How to search with "or" clauses in Sphinx?
I have the following index with sphinx :
source src1
{
type = mysql
sql_host = localhost
sql_user = ...
sql_pass = ...
sql_db = ....
sql_port = 3306 # optional, default is 3306
sql_sock = /var/run/mysqld/mysqld.sock
sql_query = \
SELECT anuncio_id,data_criacao,titulo,descricao,categoria1_titulo,categoria1_id,categoria2_titulo,categoria2_id,categoria3_titulo,categoria3_id,categoria4_titulo,categoria4_id FROM ccsprool_indice
sql_field_string = titulo
sql_field_string = descricao
sql_field_string = categoria1_titulo
sql_field_string = categoria2_titulo
sql_field_string = categoria3_titulo
sql_field_string = categoria4_titulo
sql_attr_uint = categoria1_id
sql_attr_uint = categoria2_id
sql_attr_uint = categoria3_id
sql_attr_uint = categoria4_id
开发者_高级运维 sql_attr_timestamp = data_criacao
sql_query_info = SELECT * FROM ccsprool_indice WHERE anuncio_id=$id
}
index produtos_sprool
{
source = src1
path = /usr/local/sphinx/var/data/produtos_sprool
docinfo = extern
mlock = 0
morphology = none
charset_type = utf-8
html_strip = 1
min_word_len = 3
min_prefix_len = 0
min_infix_len = 3
wordforms = /usr/local/sphinx/data/wordforms.txt
}
I need to check if an item is in categoria1_id, or categoria2_id, categoria3_id, or categoria4_id
can I do that with Sphinx ?
If I understood the task correctly this should help:
$cl->SetSelect('*, categoria1_id=N or categoria2_id=N or categoria3_id=N or categoria4_id=N as fil'); $cl->SetFilter('fil', array(1));
This will return all documents that have one of categoria1_id/categoria2_id/categoria3_id/categoria4_id set to N.
精彩评论