sphinx.conf中
sql_query = SELECT item_id, item_title, item_time, cat_id, region_id, region_parent, region1, region2, region3, metro_id, group_id, doc_words, FROM articles;
sql_attr_uint = cat_id
sql_attr_uint = region_id
sql_attr_uint = region_parent
sql_attr_uint = region1
sql_attr_uint = region2
sql_attr_uint = region3
sql_attr_uint = metro_id
sql_attr_uint = group_id
sql_attr_timestamp = item_time
sql_query_info = SELECT * FROM articles WHERE item_id=$id
php sphinx客户端
$cl->SetMatchMode( SPH_SORT_EXTENDED );
// User choses either full text search for title or doc_words column
if ($user_column_selected == "titles")
{
$user_selected_table = "@item_title";
}
elseif ($user_column_selected == "@doc_words")
{
$user_selected_table = "@doc_words";
}
// User chose to filter by metro_id
$metro_array = explode(",", $selected_market_type);
$cl->SetFilter('metro_id', $metro_array);
// User chose to filter by category
$cat_array = explode(",", $selected_category);
$cl->SetFilter('cat_id', $cat_array);
// User chose to filter by a range of region_id
if ($user_region_range == "1")
{
$cl->SetFilterRange('region_id', 100, 152, TRUE);
}
else
{
/**** USER SELECTED A SPECIFIC REGION ****/
$region_array = explode(",", $selected_region);
$cl->SetFilter('region_id', $region_array);
}
// User chose to sort by time rather than relevance
if ($user_relevance == "1")
{
// by item time
$cl->SetSortMode(SPH_SORT_ATTR_DESC, 'item_time');
}
// User chose to filter by time range
if ($user_date_filter == "1")
{
$cl->SetFilterRange('item_time',$unix_date_from, $unix_date_to,$exclude=false);
}
// User choses to group results by group_id
if ($user_group == "1")
{
$cl->SetGroupBy ( 'group_id', SPH_GROUPBY_ATTR, '@group desc' );
}
$sphinx_result = $cl->Query($user_selected_table." ".$user_text_query, my_sphinx_index );
根据我在上面创建的内容,用户可以对item_title或doc_words执行全文搜索,可以通过一个或多个sql_attr_uint列缩小结果,这些列可以按item_time排序并按group_id分组。
我现在可以通过上面所示的任何sql_attr_uint区域列设置setFilter,但我需要的是那些区域列的布尔值。
我希望这样做而不会丢失任何上述功能,同时为列region_id,region_parent,region1,region2,region3添加某种“setFilter OR”。
我在文档中读过了带有mysql CONCAT示例的setSelect和setFilter,但在将它应用于这种配置时对我没有任何意义。处理它的最佳方法是什么?
答案 0 :(得分:0)
个人可能会制作一个新的地区MVA
sql_query = ... cat_id, CONCAT_WS(',', region_id, region_parent, region1, region2, region3) AS regions, ...
sql_attr_multi = uint regions from field
然后很容易找到任何列中具有特定ID的文档: - )