Solr:对带空格的字符串使用通配符 [英] Solr: Using a wildcard on a string with whitespace

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

问题描述

我有与此处讨论的基本相同的问题:使用空格的Solr通配符查询 ,但这个问题没有得到回答.

I have basically the same problem as discussed here: Solr wildcard query with whitespace, but this question was not answered.

我在名为"brand"的字段的过滤器查询中使用通配符.

I'm using a wildcard in a filter query on a field called "brand."

当品牌名称中包含空格时,我遇到了麻烦.例如,当我说fq = {!tag = brand} brand:Lexing * n时,过滤品牌"Lexington"的效果很好.但是,像"Athentic Models"这样的多词品牌会引起问题.似乎必须在名称两边加上双引号.

I'm having trouble when the brand name has whitespace in it. For instance, filtering the brand "Lexington" works fine when I say fq={!tag=brand}brand:Lexing*n. A multi-word brand like "Athentic Models" causes problems, however. It seems double quotes must be included around the name.

当有"s"时,* s不执行任何操作,即品牌:"Athentic Mode *"或品牌:"Lexingt *",不匹配任何内容.没有双引号,则可以说出品牌: Authen *,没有引号,没有空格,可以匹配Authentic型号,但是品牌名称中一旦包含空格,匹配时似乎只考虑字符串到第一个空格为止.

When there are "s, *s don't do anything, ie brand:"Athentic Mode*" or brand:"Lexingt*", won't match anything. Without double quotes, it does work to say brand:Authen*, with no quotes and no space, and that will match Authentic Models. But once whitespace is included in the brand name, it seems to only consider the string up to the first space when matching.

品牌字段的类型

<fieldType name="string" class="solr.StrField" sortMissingLast="true" omitNorms="true"/>

据我了解,

不是空白标记的.但是,它使用来自空白标记化字段的copyField填充.

which is not whitespace tokenized, to my understanding. It is populated with a copyField from a whitespace tokenized field, though.

是否可以做一些事情来阻止Solr在不使用双引号的情况下对过滤器查询进行标记化?

Is there something I can do to stop Solr from tokenizing the filter query without using double quotes?

推荐答案

就像罗布(Rob)在回答中所说的那样,我发布了我自己回答他所链接的问题.

Just like Rob said in his answer, I've posted an answer on my own on the question he linked to.

您需要做的就是在查询中转义空格(如customer_name:Pop *Tart-> customer_name:Pop\ *Tart). 根据我的经验,无论您将通配符放在何处,此方法都有效,这由Solr如何声明类似以下内容来支持:

All you need to do is escape the space in your query (as in, customer_name:Pop *Tart --> customer_name:Pop\ *Tart). From my experience, this method works no matter where you place the wildcard, which is backed up by how Solr claims that something like:

customer_name:Pop\ *Tart

解析为:

customer_name:Pop *Tart

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

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