CREATE OR REPLACE VIEW `catalog` AS SELECT p.`id` , p.`id_company` , p.`id_category` , p.`name` , p.`keyword` , p.`short_desc` , com.`name` AS company_name, cat.`name` AS category_name FROM `products` p JOIN `categories` cat ON p.id_category = cat.id JOIN `companies` com ON p.id_company = com.id WHERE 1
# source catalog { # # : mysql, pgsql, mssql, xmlpipe, xmlpipe2, odbc type = mysql # sql_host = localhost sql_user = root sql_pass = sql_db = products sql_port = 3306 # , 3306 # -, # UTF-8, sql_query_pre = SET NAMES utf8 # , # ID sql_query = \ SELECT * \ FROM catalog # , , sql_attr_uint = id_company sql_attr_uint = id_category # document info query, ONLY for CLI search (ie. testing and debugging) # optional, default is empty # must contain $id macro and must fetch the document by that id sql_query_info = SELECT * FROM products WHERE id=$id }
# index catalog { # source = catalog # , path = C:\Sphinx/data/catalog # morphology = stem_ru # min_word_len = 1 # charset_type = utf-8 }
# () searchd { # "" listen = 9312 # log = C:\Sphinx/log/searchd.log # query_log = C:\Sphinx/log/query.log # PID file, searchd process ID file name # mandatory pid_file = C:\Sphinx/log/searchd.pid }
C:\Users\Iskander> C:\Sphinx\bin\indexer --all --config C:\Sphinx\sphinx.conf.in Sphinx 1.10-beta (r2420) Copyright (c) 2001-2010, Andrew Aksyonoff Copyright (c) 2008-2010, Sphinx Technologies Inc (http://sphinxsearch.com) using config file 'C:\Sphinx\sphinx.conf.in'... indexing index 'catalog'... collected 572 docs, 0.1 MB sorted 0.0 Mhits, 100.0% done total 572 docs, 115192 bytes total 0.380 sec, 303124 bytes/sec, 1505.19 docs/sec total 2 reads, 0.000 sec, 31.6 kb/call avg, 0.0 msec/call avg total 9 writes, 0.001 sec, 14.6 kb/call avg, 0.1 msec/call avg
C:\Users\Iskander> C:\Sphinx\bin\search --config C:\Sphinx\sphinx.conf.in computer Sphinx 1.10-beta (r2420) Copyright (c) 2001-2010, Andrew Aksyonoff Copyright (c) 2008-2010, Sphinx Technologies Inc (http://sphinxsearch.com) using config file 'C:\Sphinx\sphinx.conf.in'... index 'catalog': query 'computer': returned 1 matches of 1 total in 0.000 sec displaying matches: 1. document=1, weight=2812, id_company=2, id_category=1263 id=1 id_company=2 id_category=1263 words: 1. 'computer': 1 documents, 2 hits
<?php // api include('C:\Sphinx\api\sphinxapi.php'); // - $cl = new SphinxClient(); $cl->SetServer( "localhost", 9312 ); // $cl->SetMatchMode( SPH_MATCH_ANY ); // 1 $result = $cl->Query("computer"); // // if ( $result === false ) { echo "Query failed: " . $cl->GetLastError() . ".\n"; // } else { if ( $cl->GetLastWarning() ) { echo "WARNING: " . $cl->GetLastWarning() . " // "; } if ( ! empty($result["matches"]) ) { // - foreach ( $result["matches"] as $product => $info ) { echo $product . "<br />"; // id } } } exit;
Source: https://habr.com/ru/post/104690/
All Articles