英文:
How to match exact Search in Solr with space
问题
如何在两个单词之间有空格时搜索单词的一部分。我的查询如下:
/select?q=*:*&fq=pageType:program&fl=programLocation&rows=100&fq=programLocation:"Mohali"
我得到的结果如下:
"response":{"numFound":3,"start":0,"docs":[
{
"programLocation":["Mohali"]},
{
"programLocation":["Mohali"]},
{
"programLocation":["Mohali and Hyderabad"]}]
我想要仅检索 "Mohali",但现在我得到了 "Mohali" 和 "Mohali and Hyderabad"。如何构建查询以仅获取 Mohali?
英文:
How to search a part of the word when space is present between two words. My query this like below
/select?q=*:*&fq=pageType:program&fl=programLocation&rows=100&fq=programLocation:"Mohali"
The result I am getting is as below
"response":{"numFound":3,"start":0,"docs":[
{
"programLocation":["Mohali"]},
{
"programLocation":["Mohali"]},
{
"programLocation":["Mohali and Hyderabad"]}]
I want to retrieve only "Mohali", but now I am getting both "Mohali" and "Mohali and Hyderabad". How to form a query to only fetch Mohali?
答案1
得分: 1
你需要将string
作为fieldtype
应用于你的字段programLocation
。
将字符串作为fieldtype
应用并重新索引数据。
<field name="programLocation" type="string" indexed="true" stored="true" required="true" multiValued="false" />
String
将单词/句子存储为精确字符串,不执行任何标记化操作。
它在存储精确匹配时非常有用,例如用于分面、排序。
与string
类型相反的是text
类型。
Text
对数据进行标记化处理,执行诸如转小写等处理。在需要匹配句子的一部分时很有用。
如果您想要实现小写搜索,那么请为您的字段使用以下fieldtype
。
<fieldType name="forExactMatch" class="solr.TextField" sortMissingLast="true" omitNorms="true">
<analyzer>
<!-- KeywordTokenizer不会实际进行标记化,因此整个
输入字符串将保留为单个标记
-->
<tokenizer class="solr.KeywordTokenizerFactory"/>
<!-- LowerCase TokenFilter按预期执行操作,可用于
在排序时进行大小写不敏感的匹配
-->
<filter class="solr.LowerCaseFilterFactory" />
</analyzer>
</fieldType>
如果存在空格,您还可以在小写过滤工厂之后使用以下过滤器。
<!-- TrimFilter删除任何前导或尾随空格 -->
<filter class="solr.TrimFilterFactory" />
然后,您的字段定义将如下所示。
<field name="programLocation" type="forExactMatch" indexed="true" stored="true"/>
英文:
You need to use the string
as fieldtype
for your field programLocation
.
Apply the String as fieldtype
and reindex the data.
<field name="programLocation" type="string" indexed="true" stored="true" required="true" multiValued="false" />
String
stores the word/sentence as an exact string without performing any tokenization on it.
Its useful in cases for storing exact matches, e.g, for faceting, sorting.
Opposite of string
type is text
.
Text
does the tokenization of data, performs processing such as lower-casing etc. It is helpful in case when we want to match part of a sentence.
If you want achieve the lowercase search then use the below fieldtype for you field.
<fieldType name="forExactMatch" class="solr.TextField" sortMissingLast="true" omitNorms="true">
<analyzer>
<!-- KeywordTokenizer does no actual tokenizing, so the entire
input string is preserved as a single token
-->
<tokenizer class="solr.KeywordTokenizerFactory"/>
<!-- The LowerCase TokenFilter does what you expect, which can be
when you want your sorting to be case insensitive
-->
<filter class="solr.LowerCaseFilterFactory" />
</analyzer>
</fieldType>
If you have spaces the you can also use the below filter after the lowercase filter factory.
<!-- The TrimFilter removes any leading or trailing whitespace -->
<filter class="solr.TrimFilterFactory" />
Then your field defination will look like below
<field name="programLocation" type="forExactMatch" indexed="true" stored="true"/>
答案2
得分: 0
用于在Java中进行与Lucene搜索的精确匹配
`?q="Your search"~0`
您可以更改整数值以定义单词之间的最大距离
`?q="Your search"~2`
示例:"这是一个精确匹配的很棒的示例"
- `?q="awesome exemple"~0` 将匹配
- `?q="awesome exact match"~0` 不会匹配
- `?q="awesome exact match"~2` 将匹配
英文:
For an exact match with lucene search in java
?q="Your search"~0
Your can play with the integer to define the max distance between words
?q="Your search"~2
Exemple : "This is an awesome exemple of exact match"
?q="awesome exemple"~0
will match?q="awesome exact match"~0
won't match?q="awesome exact match"~2
will match
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论