有没有办法查询 Sphinx 中特定字段不为空的记录?

发布于 2024-10-02 18:57:25 字数 245 浏览 6 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

盗琴音 2024-10-09 18:57:25

很简单,只需将常量添加到 sphinx 配置中的 sql_query 中:

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

然后您可以在扩展查询模式下使用简单的查询:

@all "1"

并且它可以工作

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

半世蒼涼 2024-10-09 18:57:25

您可以在不更新/更改数据库的情况下完成此操作 - 只需修改构建索引/源的 sql_query 即可。例如

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

,然后运行上一个海报的评论,只需在 sphinx 查询中使用否定即可。

或者,您可以创建一个可以过滤的动态 sphinx 属性。例如

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

 sql_attr_uint = title_is_not_blank

,然后确保为每个搜索过滤title_is_not_blank=1

或者,根据您的应用程序,如果您从不需要空白内容,只需使用 sql_query WHERE 子句消除 then 即可。例如

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

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!=''
没有伤那来痛 2024-10-09 18:57:25

使用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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文