我正在使用 sphinx php api 对搜索结果进行排序。我想给标题更多的权重而不是内容,我尝试设置 setFieldWeights
$sp->setFieldWeights(array('title'=>10,'full_story'=>1));
但它根本不起作用。无论我如何改变重量,结果都保持不变。
以“test”作为搜索词的 print_r 和setFieldWeights(array('title'=>10,'full_story'=>1));
Array ( [error] => [warning] => [status] => 0 [fields] => Array ( [0] => title [1] => full_story [2] => category ) [attrs] => Array ( [date] => 2 ) [matches] => Array ( [0] => Array ( [id] => 1933 [weight] => 10 [attrs] => Array ( [date] => 2012 ) ) [1] => Array ( [id] => 2824 [weight] => 10 [attrs] => Array ( [date] => 2012 ) ) [2] => Array ( [id] => 2860 [weight] => 10 [attrs] => Array ( [date] => 2012 ) ) [3] => Array ( [id] => 2865 [weight] => 10 [attrs] => Array ( [date] => 2012 ) ) [4] => Array ( [id] => 5720 [weight] => 10 [attrs] => Array ( [date] => 2013 ) ) [5] => Array ( [id] => 6963 [weight] => 10 [attrs] => Array ( [date] => 2012 ) ) [6] => Array ( [id] => 8190 [weight] => 10 [attrs] => Array ( [date] => 2012 ) ) [7] => Array ( [id] => 8591 [weight] => 10 [attrs] => Array ( [date] => 2012 ) ) [8] => Array ( [id] => 10114 [weight] => 10 [attrs] => Array ( [date] => 2013 ) ) [9] => Array ( [id] => 10157 [weight] => 10 [attrs] => Array ( [date] => 2012 ) ) [10] => Array ( [id] => 11162 [weight] => 10 [attrs] => Array ( [date] => 2012 ) ) [11] => Array ( [id] => 11659 [weight] => 10 [attrs] => Array ( [date] => 2012 ) ) [12] => Array ( [id] => 13219 [weight] => 10 [attrs] => Array ( [date] => 2012 ) ) [13] => Array ( [id] => 13220 [weight] => 10 [attrs] => Array ( [date] => 2012 ) ) [14] => Array ( [id] => 13565 [weight] => 10 [attrs] => Array ( [date] => 2012 ) ) [15] => Array ( [id] => 13576 [weight] => 10 [attrs] => Array ( [date] => 2012 ) ) [16] => Array ( [id] => 14801 [weight] => 10 [attrs] => Array ( [date] => 2012 ) ) [17] => Array ( [id] => 14857 [weight] => 10 [attrs] => Array ( [date] => 2012 ) ) [18] => Array ( [id] => 17311 [weight] => 10 [attrs] => Array ( [date] => 2012 ) ) [19] => Array ( [id] => 17511 [weight] => 10 [attrs] => Array ( [date] => 2012 ) ) [20] => Array ( [id] => 18131 [weight] => 10 [attrs] => Array ( [date] => 2012 ) ) [21] => Array ( [id] => 19171 [weight] => 10 [attrs] => Array ( [date] => 2012 ) ) [22] => Array ( [id] => 21134 [weight] => 10 [attrs] => Array ( [date] => 2012 ) ) [23] => Array ( [id] => 23007 [weight] => 10 [attrs] => Array ( [date] => 2013 ) ) [24] => Array ( [id] => 23230 [weight] => 10 [attrs] => Array ( [date] => 2013 ) ) [25] => Array ( [id] => 23460 [weight] => 10 [attrs] => Array ( [date] => 2013 ) ) [26] => Array ( [id] => 23473 [weight] => 10 [attrs] => Array ( [date] => 2013 ) ) [27] => Array ( [id] => 25609 [weight] => 10 [attrs] => Array ( [date] => 2013 ) ) [28] => Array ( [id] => 28093 [weight] => 10 [attrs] => Array ( [date] => 2013 ) ) [29] => Array ( [id] => 28175 [weight] => 10 [attrs] => Array ( [date] => 2013 ) ) [30] => Array ( [id] => 30364 [weight] => 10 [attrs] => Array ( [date] => 2013 ) ) [31] => Array ( [id] => 30506 [weight] => 10 [attrs] => Array ( [date] => 2013 ) ) [32] => Array ( [id] => 31439 [weight] => 10 [attrs] => Array ( [date] => 2013 ) ) [33] => Array ( [id] => 31668 [weight] => 10 [attrs] => Array ( [date] => 2013 ) ) [34] => Array ( [id] => 32017 [weight] => 10 [attrs] => Array ( [date] => 2013 ) ) [35] => Array ( [id] => 1432 [weight] => 1 [attrs] => Array ( [date] => 2012 ) ) [36] => Array ( [id] => 5362 [weight] => 1 [attrs] => Array ( [date] => 2013 ) ) [37] => Array ( [id] => 9175 [weight] => 1 [attrs] => Array ( [date] => 2012 ) ) [38] => Array ( [id] => 13817 [weight] => 1 [attrs] => Array ( [date] => 2012 ) ) [39] => Array ( [id] => 14132 [weight] => 1 [attrs] => Array ( [date] => 2012 ) ) [40] => Array ( [id] => 14658 [weight] => 1 [attrs] => Array ( [date] => 2013 ) ) [41] => Array ( [id] => 15792 [weight] => 1 [attrs] => Array ( [date] => 2013 ) ) [42] => Array ( [id] => 16615 [weight] => 1 [attrs] => Array ( [date] => 2012 ) ) [43] => Array ( [id] => 18177 [weight] => 1 [attrs] => Array ( [date] => 2012 ) ) [44] => Array ( [id] => 18581 [weight] => 1 [attrs] => Array ( [date] => 2012 ) ) [45] => Array ( [id] => 18618 [weight] => 1 [attrs] => Array ( [date] => 2012 ) ) [46] => Array ( [id] => 18665 [weight] => 1 [attrs] => Array ( [date] => 2012 ) ) [47] => Array ( [id] => 18718 [weight] => 1 [attrs] => Array ( [date] => 2012 ) ) [48] => Array ( [id] => 19096 [weight] => 1 [attrs] => Array ( [date] => 2012 ) ) [49] => Array ( [id] => 19128 [weight] => 1 [attrs] => Array ( [date] => 2012 ) ) [50] => Array ( [id] => 19464 [weight] => 1 [attrs] => Array ( [date] => 2012 ) ) [51] => Array ( [id] => 20014 [weight] => 1 [attrs] => Array ( [date] => 2012 ) ) [52] => Array ( [id] => 20144 [weight] => 1 [attrs] => Array ( [date] => 2013 ) ) [53] => Array ( [id] => 20306 [weight] => 1 [attrs] => Array ( [date] => 2012 ) ) [54] => Array ( [id] => 22604 [weight] => 1 [attrs] => Array ( [date] => 2013 ) ) [55] => Array ( [id] => 23870 [weight] => 1 [attrs] => Array ( [date] => 2013 ) ) [56] => Array ( [id] => 23994 [weight] => 1 [attrs] => Array ( [date] => 2013 ) ) [57] => Array ( [id] => 24507 [weight] => 1 [attrs] => Array ( [date] => 2013 ) ) [58] => Array ( [id] => 24617 [weight] => 1 [attrs] => Array ( [date] => 2013 ) ) [59] => Array ( [id] => 25043 [weight] => 1 [attrs] => Array ( [date] => 2013 ) ) [60] => Array ( [id] => 25350 [weight] => 1 [attrs] => Array ( [date] => 2013 ) ) [61] => Array ( [id] => 26063 [weight] => 1 [attrs] => Array ( [date] => 2013 ) ) [62] => Array ( [id] => 26614 [weight] => 1 [attrs] => Array ( [date] => 2013 ) ) [63] => Array ( [id] => 26819 [weight] => 1 [attrs] => Array ( [date] => 2013 ) ) [64] => Array ( [id] => 28292 [weight] => 1 [attrs] => Array ( [date] => 2013 ) ) [65] => Array ( [id] => 29155 [weight] => 1 [attrs] => Array ( [date] => 2013 ) ) [66] => Array ( [id] => 30854 [weight] => 1 [attrs] => Array ( [date] => 2013 ) ) [67] => Array ( [id] => 31566 [weight] => 1 [attrs] => Array ( [date] => 2013 ) ) [68] => Array ( [id] => 31704 [weight] => 1 [attrs] => Array ( [date] => 2013 ) ) [69] => Array ( [id] => 32092 [weight] => 1 [attrs] => Array ( [date] => 2013 ) ) ) [total] => 70 [total_found] => 70 [time] => 0,017 [words] => Array ( [*test*] => Array ( [docs] => 70 [hits] => 70 ) ) )
以“test”作为搜索词的 print_r 和setFieldWeights(array('title'=>10000,'full_story'=>1));
Array ( [error] => [warning] => [status] => 0 [fields] => Array ( [0] => title [1] => full_story [2] => category [3] => date ) [attrs] => Array ( ) [matches] => Array ( [0] => Array ( [id] => 1933 [weight] => 10000 [attrs] => Array ( ) ) [1] => Array ( [id] => 2824 [weight] => 10000 [attrs] => Array ( ) ) [2] => Array ( [id] => 2860 [weight] => 10000 [attrs] => Array ( ) ) [3] => Array ( [id] => 2865 [weight] => 10000 [attrs] => Array ( ) ) [4] => Array ( [id] => 5720 [weight] => 10000 [attrs] => Array ( ) ) [5] => Array ( [id] => 6963 [weight] => 10000 [attrs] => Array ( ) ) [6] => Array ( [id] => 8190 [weight] => 10000 [attrs] => Array ( ) ) [7] => Array ( [id] => 8591 [weight] => 10000 [attrs] => Array ( ) ) [8] => Array ( [id] => 10114 [weight] => 10000 [attrs] => Array ( ) ) [9] => Array ( [id] => 10157 [weight] => 10000 [attrs] => Array ( ) ) [10] => Array ( [id] => 11162 [weight] => 10000 [attrs] => Array ( ) ) [11] => Array ( [id] => 11659 [weight] => 10000 [attrs] => Array ( ) ) [12] => Array ( [id] => 13219 [weight] => 10000 [attrs] => Array ( ) ) [13] => Array ( [id] => 13220 [weight] => 10000 [attrs] => Array ( ) ) [14] => Array ( [id] => 13565 [weight] => 10000 [attrs] => Array ( ) ) [15] => Array ( [id] => 13576 [weight] => 10000 [attrs] => Array ( ) ) [16] => Array ( [id] => 14801 [weight] => 10000 [attrs] => Array ( ) ) [17] => Array ( [id] => 14857 [weight] => 10000 [attrs] => Array ( ) ) [18] => Array ( [id] => 17311 [weight] => 10000 [attrs] => Array ( ) ) [19] => Array ( [id] => 17511 [weight] => 10000 [attrs] => Array ( ) ) [20] => Array ( [id] => 18131 [weight] => 10000 [attrs] => Array ( ) ) [21] => Array ( [id] => 19171 [weight] => 10000 [attrs] => Array ( ) ) [22] => Array ( [id] => 21134 [weight] => 10000 [attrs] => Array ( ) ) [23] => Array ( [id] => 23007 [weight] => 10000 [attrs] => Array ( ) ) [24] => Array ( [id] => 23230 [weight] => 10000 [attrs] => Array ( ) ) [25] => Array ( [id] => 23460 [weight] => 10000 [attrs] => Array ( ) ) [26] => Array ( [id] => 23473 [weight] => 10000 [attrs] => Array ( ) ) [27] => Array ( [id] => 25609 [weight] => 10000 [attrs] => Array ( ) ) [28] => Array ( [id] => 28093 [weight] => 10000 [attrs] => Array ( ) ) [29] => Array ( [id] => 28175 [weight] => 10000 [attrs] => Array ( ) ) [30] => Array ( [id] => 30364 [weight] => 10000 [attrs] => Array ( ) ) [31] => Array ( [id] => 30506 [weight] => 10000 [attrs] => Array ( ) ) [32] => Array ( [id] => 31439 [weight] => 10000 [attrs] => Array ( ) ) [33] => Array ( [id] => 31668 [weight] => 10000 [attrs] => Array ( ) ) [34] => Array ( [id] => 32017 [weight] => 10000 [attrs] => Array ( ) ) [35] => Array ( [id] => 1432 [weight] => 1 [attrs] => Array ( ) ) [36] => Array ( [id] => 5362 [weight] => 1 [attrs] => Array ( ) ) [37] => Array ( [id] => 9175 [weight] => 1 [attrs] => Array ( ) ) [38] => Array ( [id] => 13817 [weight] => 1 [attrs] => Array ( ) ) [39] => Array ( [id] => 14132 [weight] => 1 [attrs] => Array ( ) ) [40] => Array ( [id] => 14658 [weight] => 1 [attrs] => Array ( ) ) [41] => Array ( [id] => 15792 [weight] => 1 [attrs] => Array ( ) ) [42] => Array ( [id] => 16615 [weight] => 1 [attrs] => Array ( ) ) [43] => Array ( [id] => 18177 [weight] => 1 [attrs] => Array ( ) ) [44] => Array ( [id] => 18581 [weight] => 1 [attrs] => Array ( ) ) [45] => Array ( [id] => 18618 [weight] => 1 [attrs] => Array ( ) ) [46] => Array ( [id] => 18665 [weight] => 1 [attrs] => Array ( ) ) [47] => Array ( [id] => 18718 [weight] => 1 [attrs] => Array ( ) ) [48] => Array ( [id] => 19096 [weight] => 1 [attrs] => Array ( ) ) [49] => Array ( [id] => 19128 [weight] => 1 [attrs] => Array ( ) ) [50] => Array ( [id] => 19464 [weight] => 1 [attrs] => Array ( ) ) [51] => Array ( [id] => 20014 [weight] => 1 [attrs] => Array ( ) ) [52] => Array ( [id] => 20144 [weight] => 1 [attrs] => Array ( ) ) [53] => Array ( [id] => 20306 [weight] => 1 [attrs] => Array ( ) ) [54] => Array ( [id] => 22604 [weight] => 1 [attrs] => Array ( ) ) [55] => Array ( [id] => 23870 [weight] => 1 [attrs] => Array ( ) ) [56] => Array ( [id] => 23994 [weight] => 1 [attrs] => Array ( ) ) [57] => Array ( [id] => 24507 [weight] => 1 [attrs] => Array ( ) ) [58] => Array ( [id] => 24617 [weight] => 1 [attrs] => Array ( ) ) [59] => Array ( [id] => 25043 [weight] => 1 [attrs] => Array ( ) ) [60] => Array ( [id] => 25350 [weight] => 1 [attrs] => Array ( ) ) [61] => Array ( [id] => 26063 [weight] => 1 [attrs] => Array ( ) ) [62] => Array ( [id] => 26614 [weight] => 1 [attrs] => Array ( ) ) [63] => Array ( [id] => 26819 [weight] => 1 [attrs] => Array ( ) ) [64] => Array ( [id] => 28292 [weight] => 1 [attrs] => Array ( ) ) [65] => Array ( [id] => 29155 [weight] => 1 [attrs] => Array ( ) ) [66] => Array ( [id] => 30854 [weight] => 1 [attrs] => Array ( ) ) [67] => Array ( [id] => 31566 [weight] => 1 [attrs] => Array ( ) ) [68] => Array ( [id] => 31704 [weight] => 1 [attrs] => Array ( ) ) [69] => Array ( [id] => 32092 [weight] => 1 [attrs] => Array ( ) ) ) [total] => 70 [total_found] => 70 [time] => 0,000 [words] => Array ( [*test*] => Array ( [docs] => 70 [hits] => 70 ) ) )
print_r 带有“test”作为搜索词,没有setFieldWeights
Array ( [error] => [warning] => [status] => 0 [fields] => Array ( [0] => title [1] => full_story [2] => category [3] => date ) [attrs] => Array ( ) [matches] => Array ( [0] => Array ( [id] => 1432 [weight] => 1 [attrs] => Array ( ) ) [1] => Array ( [id] => 1933 [weight] => 1 [attrs] => Array ( ) ) [2] => Array ( [id] => 2824 [weight] => 1 [attrs] => Array ( ) ) [3] => Array ( [id] => 2860 [weight] => 1 [attrs] => Array ( ) ) [4] => Array ( [id] => 2865 [weight] => 1 [attrs] => Array ( ) ) [5] => Array ( [id] => 5362 [weight] => 1 [attrs] => Array ( ) ) [6] => Array ( [id] => 5720 [weight] => 1 [attrs] => Array ( ) ) [7] => Array ( [id] => 6963 [weight] => 1 [attrs] => Array ( ) ) [8] => Array ( [id] => 8190 [weight] => 1 [attrs] => Array ( ) ) [9] => Array ( [id] => 8591 [weight] => 1 [attrs] => Array ( ) ) [10] => Array ( [id] => 9175 [weight] => 1 [attrs] => Array ( ) ) [11] => Array ( [id] => 10114 [weight] => 1 [attrs] => Array ( ) ) [12] => Array ( [id] => 10157 [weight] => 1 [attrs] => Array ( ) ) [13] => Array ( [id] => 11162 [weight] => 1 [attrs] => Array ( ) ) [14] => Array ( [id] => 11659 [weight] => 1 [attrs] => Array ( ) ) [15] => Array ( [id] => 13219 [weight] => 1 [attrs] => Array ( ) ) [16] => Array ( [id] => 13220 [weight] => 1 [attrs] => Array ( ) ) [17] => Array ( [id] => 13565 [weight] => 1 [attrs] => Array ( ) ) [18] => Array ( [id] => 13576 [weight] => 1 [attrs] => Array ( ) ) [19] => Array ( [id] => 13817 [weight] => 1 [attrs] => Array ( ) ) [20] => Array ( [id] => 14132 [weight] => 1 [attrs] => Array ( ) ) [21] => Array ( [id] => 14658 [weight] => 1 [attrs] => Array ( ) ) [22] => Array ( [id] => 14801 [weight] => 1 [attrs] => Array ( ) ) [23] => Array ( [id] => 14857 [weight] => 1 [attrs] => Array ( ) ) [24] => Array ( [id] => 15792 [weight] => 1 [attrs] => Array ( ) ) [25] => Array ( [id] => 16615 [weight] => 1 [attrs] => Array ( ) ) [26] => Array ( [id] => 17311 [weight] => 1 [attrs] => Array ( ) ) [27] => Array ( [id] => 17511 [weight] => 1 [attrs] => Array ( ) ) [28] => Array ( [id] => 18131 [weight] => 1 [attrs] => Array ( ) ) [29] => Array ( [id] => 18177 [weight] => 1 [attrs] => Array ( ) ) [30] => Array ( [id] => 18581 [weight] => 1 [attrs] => Array ( ) ) [31] => Array ( [id] => 18618 [weight] => 1 [attrs] => Array ( ) ) [32] => Array ( [id] => 18665 [weight] => 1 [attrs] => Array ( ) ) [33] => Array ( [id] => 18718 [weight] => 1 [attrs] => Array ( ) ) [34] => Array ( [id] => 19096 [weight] => 1 [attrs] => Array ( ) ) [35] => Array ( [id] => 19128 [weight] => 1 [attrs] => Array ( ) ) [36] => Array ( [id] => 19171 [weight] => 1 [attrs] => Array ( ) ) [37] => Array ( [id] => 19464 [weight] => 1 [attrs] => Array ( ) ) [38] => Array ( [id] => 20014 [weight] => 1 [attrs] => Array ( ) ) [39] => Array ( [id] => 20144 [weight] => 1 [attrs] => Array ( ) ) [40] => Array ( [id] => 20306 [weight] => 1 [attrs] => Array ( ) ) [41] => Array ( [id] => 21134 [weight] => 1 [attrs] => Array ( ) ) [42] => Array ( [id] => 22604 [weight] => 1 [attrs] => Array ( ) ) [43] => Array ( [id] => 23007 [weight] => 1 [attrs] => Array ( ) ) [44] => Array ( [id] => 23230 [weight] => 1 [attrs] => Array ( ) ) [45] => Array ( [id] => 23460 [weight] => 1 [attrs] => Array ( ) ) [46] => Array ( [id] => 23473 [weight] => 1 [attrs] => Array ( ) ) [47] => Array ( [id] => 23870 [weight] => 1 [attrs] => Array ( ) ) [48] => Array ( [id] => 23994 [weight] => 1 [attrs] => Array ( ) ) [49] => Array ( [id] => 24507 [weight] => 1 [attrs] => Array ( ) ) [50] => Array ( [id] => 24617 [weight] => 1 [attrs] => Array ( ) ) [51] => Array ( [id] => 25043 [weight] => 1 [attrs] => Array ( ) ) [52] => Array ( [id] => 25350 [weight] => 1 [attrs] => Array ( ) ) [53] => Array ( [id] => 25609 [weight] => 1 [attrs] => Array ( ) ) [54] => Array ( [id] => 26063 [weight] => 1 [attrs] => Array ( ) ) [55] => Array ( [id] => 26614 [weight] => 1 [attrs] => Array ( ) ) [56] => Array ( [id] => 26819 [weight] => 1 [attrs] => Array ( ) ) [57] => Array ( [id] => 28093 [weight] => 1 [attrs] => Array ( ) ) [58] => Array ( [id] => 28175 [weight] => 1 [attrs] => Array ( ) ) [59] => Array ( [id] => 28292 [weight] => 1 [attrs] => Array ( ) ) [60] => Array ( [id] => 29155 [weight] => 1 [attrs] => Array ( ) ) [61] => Array ( [id] => 30364 [weight] => 1 [attrs] => Array ( ) ) [62] => Array ( [id] => 30506 [weight] => 1 [attrs] => Array ( ) ) [63] => Array ( [id] => 30854 [weight] => 1 [attrs] => Array ( ) ) [64] => Array ( [id] => 31439 [weight] => 1 [attrs] => Array ( ) ) [65] => Array ( [id] => 31566 [weight] => 1 [attrs] => Array ( ) ) [66] => Array ( [id] => 31668 [weight] => 1 [attrs] => Array ( ) ) [67] => Array ( [id] => 31704 [weight] => 1 [attrs] => Array ( ) ) [68] => Array ( [id] => 32017 [weight] => 1 [attrs] => Array ( ) ) [69] => Array ( [id] => 32092 [weight] => 1 [attrs] => Array ( ) ) ) [total] => 70 [total_found] => 70 [time] => 0,000 [words] => Array ( [*test*] => Array ( [docs] => 70 [hits] => 70 ) ) )
狮身人面像 php api
// Include the sphinx API class
require(ENGINE_DIR . "/modules/sphinxapi.php");
$sp = new SphinxClient();
$sp->setFieldWeights(array('title'=>10,'full_story'=>1));
$sp->SetMatchMode(SPH_MATCH_all);
$sp->SetArrayResult(true);
$sp->SetLimits(0,$count_result = ($config['search_number'] * 5));
$query = explode(" ",$story);
$query = implode(array_map(function($item) { return ' *' . $item . '* '; }, $query));
$results = $sp->Query($query, $config['sphinx_index']);
print_r($results);
$count_result = $results['total_found'];
$result_count = $count_result;
比我在 ids 上执行选择
$sql_request = "SELECT * from post WHERE id IN {$rIds} LIMIT $search_start,{$config['search_number']}";
狮身人面像会议
type = mysql
sql_host = localhost
sql_user = user
sql_pass = pass
sql_db = user
sql_port = 3306 # optional, default is 3306
sql_query_pre = REPLACE INTO sph_counter SELECT 1, MAX(id) FROM post
sql_query_pre = SET NAMES utf8
sql_query_pre = SET CHARACTER SET utf8
sql_query_pre = SET SESSION query_cache_type=OFF
sql_query = SELECT id, title, full_story, category, DATE FROM post WHERE approve='1' AND id <=( SELECT max_doc_id FROM sph_counter WHERE counter_id=1 )
#sql_attr_timestamp = DATE
sql_ranged_throttle = 0
指数
index online_test
{
source = online_test_posts
path = /var/lib/sphinx/online_test
docinfo = extern
charset_type = utf-8
morphology = stem_enru
min_word_len = 1
min_prefix_len = 0
min_infix_len = 1
mlock = 0
charset_table = 0..9, A..Z->a..z, _, a..z, U+410..U+42F->U+430..U+44F, U+430..U+44F
enable_star = 1
rt_mem_limit = 512M
}
我的指示是标题为“测试你的大脑”的帖子,ID 为“2865”,它应该至少是第二个。相反,我收到标题为“来来去去”的帖子,full_story
内容test
为,id post -1432
顺便说一句,如果我从命令行运行搜索,结果会更加准确。
search test
index 'online_test': query 'test ': returned 7 matches of 7 total in 0.008 sec
displaying matches:
1. document=2865, weight=1684
2. document=5362, weight=1684
3. document=8190, weight=1684
4. document=23460, weight=1684
5. document=25609, weight=1684
6. document=31704, weight=1684
7. document=32092, weight=1684