首页域名资讯 正文

sphinx 字符串过滤

2024-12-03 3 0条评论

sphinx 不支持字符串作为属性过滤。要使用字符串进行过滤可以使用下面的两者方法进行解决:

属性查询

需要在sphinx配置文件中定义文本字段,当查询索引时,参考其字段。sphinx配置如下:

1 2 3 SELECT id , user _type \          FROM users sql_field_string = user_type

在PHP语言中,这么使用:

1 $ matches = $ this -> sphinxClient -> Query ( ‘@user_type “^admin$”‘ ) ;

全文搜索列

推荐使用这种方法。sphinx配置如下:

1 2 3 SELECT id , CRC32 ( user_type ) AS user _type \          FROM users sql_attr_int      = user_type

PHP语言中,这么使用:

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

文章转载来自:trustauth.cn

文章版权及转载声明

本文作者:亿网 网址:https://edns.com/ask/post/150664.html 发布于 2024-12-03
文章转载或复制请以超链接形式并注明出处。