有没有办法查询 Sphinx 中特定字段不为空的记录?
我正在使用 Sphinx 0.9.9 的 SPH_MATCH_EXTENDED2 匹配模式,我想编写一个搜索查询来查找在特定字段中包含任何内容的所有记录。我尝试了以下操作,但没有成功:
@MyField *
@MyField !""
我认为我可以在索引中添加一个字段,专门检查此字段并对其进行查询,但我希望拥有比这更大的灵活性 - 这将是非常好的能够通过查询语法来做到这一点。
有什么想法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
很简单,只需将常量添加到 sphinx 配置中的 sql_query 中:
然后您可以在扩展查询模式下使用简单的查询:
并且它可以工作
Easly, just add constant into your sql_query in sphinx config:
then you can use simply query for in extended query mode:
and it works
您可以在不更新/更改数据库的情况下完成此操作 - 只需修改构建索引/源的 sql_query 即可。例如
,然后运行上一个海报的评论,只需在 sphinx 查询中使用否定即可。
或者,您可以创建一个可以过滤的动态 sphinx 属性。例如
,然后确保为每个搜索过滤
title_is_not_blank=1
。或者,根据您的应用程序,如果您从不需要空白内容,只需使用 sql_query
WHERE
子句消除 then 即可。例如You can do it without updating/changing the db -- just by modifying the sql_query your index/source is built off of. e.g.
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.
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.使用2个独立的索引;一个包含所有数据,一个仅包含您关心的单元格中包含数据的行,然后您可以指定在查询时使用哪个索引。
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.