sphinx 字符串过滤

默北 Sphinx1 12,5064字数 420阅读1分24秒阅读模式

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/
weinxin
我的微信
微信公众号
扫一扫关注运维生存时间公众号,获取最新技术文章~
默北
  • 本文由 发表于 25/04/2015 01:00:28
  • 转载请务必保留本文链接:https://www.ttlsa.com/sphinx/sphinx-filter-string/
评论  1  访客  1
    • www.sichuan520.ml
      www.sichuan520.ml 9

      sphinx想用但不会用,真纠结!!

    评论已关闭!