sphinx 不支持字符串作为属性过滤。要使用字符串进行过滤可以使用下面的两者方法进行解决:
属性查询
需要在sphinx配置文件中定义文本字段,当查询索引时,参考其字段。sphinx配置如下:文章源自运维生存时间-https://www.ttlsa.com/sphinx/sphinx-filter-string/
SELECT id, user_type \ FROM users sql_field_string = user_type
在PHP语言中,这么使用:文章源自运维生存时间-https://www.ttlsa.com/sphinx/sphinx-filter-string/
$matches = $this->sphinxClient->Query('@user_type "^admin$"');
全文搜索列
推荐使用这种方法。sphinx配置如下:文章源自运维生存时间-https://www.ttlsa.com/sphinx/sphinx-filter-string/
SELECT id, CRC32(user_type) AS user_type \ FROM users sql_attr_int = user_type
PHP语言中,这么使用:文章源自运维生存时间-https://www.ttlsa.com/sphinx/sphinx-filter-string/
$this->sphinxClient->SetFilter('user_type', array(crc32('admin'));文章源自运维生存时间-https://www.ttlsa.com/sphinx/sphinx-filter-string/文章源自运维生存时间-https://www.ttlsa.com/sphinx/sphinx-filter-string/

我的微信
微信公众号
扫一扫关注运维生存时间公众号,获取最新技术文章~
1F
sphinx想用但不会用,真纠结!!