Note:
This is a cross-entry, it is first posted on the sphinx forum , however I did not receive a response, so I post it here.
First look at an example:
Below is my table (for test only):
+ ---- + -------------------------- + ----------------- ----- +
| Id | title | body |
+ ---- + -------------------------- + ----------------- ----- +
| 1 | National first hospital | NASA |
| 2 | National second hospital | Space Administration |
| 3 | National govenment | Support the hospital |
+ ---- + -------------------------- + ----------------- ----- +
I want to search the contents from the header and body fields, so I am setting up sphinx.conf as shown below:
-------- The sphinx config file ----------
source mysql
{
type = mysql
sql_host = localhost
sql_user = root
sql_pass = 0000
sql_db = testfull
sql_port = 3306 # optional, default is 3306
sql_query_pre = SET NAMES utf8
sql_query = SELECT * FROM test
}
index mysql
{
source = mysql
path = var / data / mysql_old_test
docinfo = extern
mlock = 0
morphology = stem_en, stem_ru, soundex
min_stemming_len = 1
min_word_len = 1
charset_type = utf-8
html_strip = 0
}
indexer
{
mem_limit = 128M
}
searchd
{
listen = 9312
read_timeout = 5
max_children = 30
max_matches = 1000
seamless_rotate = 0
preopen_indexes = 0
unlink_old = 1
pid_file = var / log / searchd_mysql.pid
log = var / log / searchd_mysql.log
query_log = var / log / query_mysql.log
}
------------------
Then I reindex the db and run the searchd daemon.
In my client side, I set the attribute as:
---------- Client side configuration -------------------
sc = new SphinxClient();
HashMap<String, Integer> weiMap=new HashMap<String, Integer>();
weiMap.put("title", 100);
weiMap.put("body", 0);
sc.SetFieldWeights(weiMap);
sc.SetMatchMode(SphinxClient.SPH_MATCH_ALL);
sc.SetSortMode(SphinxClient.SPH_SORT_EXTENDED,"@weight DESC");
When I try to search the National Hospital, I get the following result:
Query 'National hospital' retrieved 3 of 3 matches in 0.0 sec.
Query stats:
'nation' found 3 times in 3 documents
'hospitals' found 3 times in 3 documents
Matches:
1. id = 3, weight = 101
2. id = 1, weight = 100
3. id = 2, weight = 100
The match number (three matches) is correct, however the order of the result is not what I wanted.
, 1 2
( " " ), , ,
, .
, ?
PS:
1), , sortModel :
sc.SetSortMode(SphinxClient.SPH_SORT_EXTENDED,"@weight ASC");
, .
2) - , "National Hosp..l",
.