1. 程式人生 > >sphinx 字符串過濾

sphinx 字符串過濾

from ray 支持 解決 配置 屬性 string 過濾 matches

sphinx 不支持字符串作為屬性過濾。要使用字符串進行過濾可以使用下面的兩者方法進行解決:
屬性查詢

需要在sphinx配置文件中定義文本字段,當查詢索引時,參考其字段。sphinx配置如下:

SELECT id, user_type \
FROM users
sql_field_string = user_type


在PHP語言中,這麽使用:

$matches = $this->sphinxClient->Query([email protected]_type "^admin$"‘);

全文搜索列

推薦使用這種方法。sphinx配置如下:

SELECT id, CRC32(user_type) AS user_type \
FROM users
sql_attr_int = user_type

PHP語言中,這麽使用:

$this->sphinxClient->SetFilter(‘user_type‘, array(crc32(‘admin‘));

sphinx 字符串過濾