带空格的 Solr 通配符查询 [英] Solr wildcard query with whitespace

查看:44
本文介绍了带空格的 Solr 通配符查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类似于以下内容的通配符查询:

I have a wildcard query that looks something like:

q=location:los a*

我希望它与los angeles"和los altos"相匹配.查询如下:

I'd like it to match "los angeles" and "los altos". A query like:

q=los*

工作得很好,但是一旦我添加了空格,我就没有结果.如何在通配符查询中使用空格?

Works just fine, but as soon as I add whitespace I get no results. How I can use whitespace in my wildcard queries?

推荐答案

我最近自己也遇到了这个问题,看来您需要做的就是在查询中避开空格.Solr 会将您的原始查询解释为如下所示:

I've recently come across this problem myself, and it seems that all you need to do is escape the space in your query. Your original query would be interpreted by Solr as something like this:

location:los id:a*

(假设id"是您的默认搜索字段)

(assuming "id" is your default search field)

但是,如果您将查询写为:

However, if you were to write your query as:

location:los\ a*

然后它最终会被解析为:

Then it would end up being parsed as:

location:los a*

以上应该会产生您想要的结果(假设您的数据已正确编入索引).

And the above should yield the results that you desire (assuming your data is properly indexed).

提示:弄清楚这一切很简单.只需在提交查询时使用的 url 末尾添加 &debugQuery=on 即可查看 Solr 如何解析它.

Tip: Figuring all this out is simple. Just add &debugQuery=on to the end of the url you use when submitting your query to see how it was parsed by Solr.

这篇关于带空格的 Solr 通配符查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆