开发者

Is there a way to query Sphinx for records that have a particular field that is not empty?

I'm using the SPH_MATCH_EXTENDED2 match mode with Sphinx 0.9.9 and I want to write a search query that finds all records that have anything in a particular field. I have tried the following with no success开发者_如何学运维:

@MyField *
@MyField !""

I figure that I can add a field to my index that specifically checks for this and query against that, but I'd prefer to have more flexibility than that--it would be really nice to be able to do this through the query syntax.

Any thoughts?


Easly, just add constant into your sql_query in sphinx config:

sql_query = SELECT `id`, `title`, 1 as `all` FROM table 

then you can use simply query for in extended query mode:

@all "1"

and it works


You can do it without updating/changing the db -- just by modifying the sql_query your index/source is built off of. e.g.

 sql_query = SELECT id, \
               IF(title!='',title,'this_field_is_actually_blank') \
             FROM table 

Then running off of a previous poster's comment, just use the negation in the sphinx query.

Alternatively, you could create a dynamic sphinx attribute you could filter against. e.g.

 sql_query = SELECT id, \
               title,  \
               IF(title!='',1,0) AS title_is_not_blank \
             FROM table 

 sql_attr_uint = title_is_not_blank

Then make sure you filter on title_is_not_blank=1 for every search.

Or, depending on your application, if you never need ones with blank content, just eliminate then with the sql_query WHERE clause. e.g.

 sql_query = SELECT id, \
               title  \
             FROM table 
             WHERE title!=''


Use 2 separate indexes; one with all the data, one with only rows that have data in this cell you care about, you can then specify which index to use at query-time.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜