执行类别搜索 Sphinx php

Execute category search Sphinx php

一天中的好时光!

有这样的配置Sphinx

    source txtcontent :  ru_config
{ 
  sql_query = SELECT `id` as `txt_id`, 1 as index_id, `type_id`,`content_type_id`, `title`, `annonce`, `content` FROM `TxtContent` WHERE `status` = 1 AND `content_type_id` != 14
  sql_attr_uint   = index_id
  sql_attr_uint   = type_id
}

整个 table 都被编入索引,并存储在一个大型搜索索引中。 当要找到里面的东西时,一切正常

但是今天的任务是搜索类别 字段中描述的类别并且具有 type_id 类型的 int php 如何使用 SphinxAPI 执行这样的搜索? 标准搜索看起来像这样。

$sphinxClient = new SphinxClient();
$sphinxClient->SetServer("127.0.0.1", 3312 );
$sphinxClient->SetLimits( 0, 700,700 );
$sphinxClient->SetSortMode(SPH_SORT_RELEVANCE);
$sphinxClient->SetArrayResult( true );
$result = $sphinxClient->Query( $this->query, 'txtcontent provider item');

我尝试添加

$sphinxClient->SetFilter('type_id','1');

只搜索 type_id = 1 的位置,但没有帮助。

实际上我怎样才能搜索特定类别?不考虑在 php 中找到所有内容以放弃结果多余的选项(否则,搜索将是 saturada 现有限制)如何通过 API 做到 "properly" 而不放置每个主题在单独的搜索索引中?

setFilter 采用 数组 值。并且它们需要是 numerictype_id 是一个数字属性)

$sphinxClient->SetFilter('type_id',array(1));

sphinxapi class 实际上使用断言来检测像这样的无效数据,我猜你已经禁用了(否则会看到它们!)。