Reputation: 51
I've started using Sphinx and I tried to install the sphinx. Everything is working properly but i want to search for partial keyword. And I want to know how to display the results in webpage.
Ex.
I search 'ate'
The result should be : 'ate', 'update', 'late', 'hate', etc.
My sphinx.con :
source src1
{
type = mysql
sql_host = localhost
sql_user = username
sql_pass = *******
sql_db = db_name
sql_port = 3306 # optional, default is 3306
sql_query = \
SELECT id, msgtext, created \
FROM agi_sms
sql_attr_string = msgtext
sql_attr_timestamp = created
sql_query_info = SELECT * FROM agi_sms WHERE id=$id
}
index test1
{
source = src1
path = C:/Sphinx/data/test1
docinfo = extern
charset_type = sbcs
enable_star = 1
morphology = stem_en
min_infix_len = 2
infix_fields = msgtext
dict = keywords
}
indexer
{
mem_limit = 32M
}
searchd
{
listen = 9312
listen = 9306:mysql41
log = C:/Sphinx/log/searchd.log
query_log = C:/Sphinx/log/query.log
read_timeout = 5
max_children = 30
pid_file = C:/Sphinx/log/searchd.pid
max_matches = 1000
seamless_rotate = 1
preopen_indexes = 1
unlink_old = 1
workers = threads # for RT to work
binlog_path = C:/Sphinx/data
}
This is my php file:
$cl = new SphinxClient ();
$q = $_POST['search'];
$sql = "";
$mode = SPH_MATCH_EXTENDED2;
$host = "localhost";
$port = 9312;
$index = "*";
$groupby = "";
$filter = "created";
$filtervals = array();
$distinct = "";
$sortby = "";
$sortexpr = "";
$limit = 20;
$ranker = SPH_RANK_PROXIMITY_BM25;
$select = "";
////////////
// do query
////////////
$cl = new SphinxClient();
$cl->SetServer( "localhost", 9312 );
$cl->SetMatchMode( SPH_MATCH_ANY );
$cl->SetFilter( 'created', array( 3 ) );
$res = $cl->Query ( $q, $index );
////////////////
// print me out
////////////////
if ( $res===false )
{
print "Query failed: " . $cl->GetLastError() . ".\n";
} else
{
if ( $cl->GetLastWarning() )
print "WARNING: " . $cl->GetLastWarning() . "\n\n";
print "<li>Query '$q' retrieved $res[total] of $res[total_found] matches in $res[time] sec.\n</li>";
print "<li>Query stats:\n";
if ( is_array($res["words"]) )
foreach ( $res["words"] as $word => $info )
print " '$word' found $info[hits] times in $info[docs] documents\n</li>";
print "\n";
}
The results:
Query 'good' retrieved 0 of 0 matches in 0.007 sec.
Query stats: 'good' found 7534 times in 7534 documents
But if I try to search 'goo', it searched nothing.
Query 'goo' retrieved 0 of 0 matches in 0.000 sec.
Query stats: 'goo' found 0 times in 0 documents
I want to get the results with everything has a word/letter of 'goo'.
like this :
Array(1 element) {
0 Object {
id = 1,
message = Good Morning
}
2 Object {
id = 2,
message = Good Day!
}
}
Upvotes: 0
Views: 626
Reputation: 692
$cl->SetFilter( 'created', array( 3 ) ); are you sure you have records with created=3? Also for wildcard searching you should do 'goo*' ( mark the * ) or set expand_keywords = 1.
Upvotes: 1