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