Lucene Index problems with quot;-quot; character(“-的 Lucene 索引问题特点)
问题描述
我在使用 Lucene 索引时遇到问题,该索引的索引词包含-"字符.
I'm having trouble with a Lucene Index, which has indexed words, that contain "-" Characters.
它适用于某些包含-"的单词,但不适用于所有单词,我找不到原因,为什么它不起作用.
It works for some words that contain "-" but not for all and I don't find the reason, why it's not working.
我正在搜索的字段经过分析并包含带有和不带有-"字符的单词的版本.
The field I'm searching in, is analyzed and contains version of the word with and without the "-" character.
我正在使用分析器:org.apache.lucene.analysis.standard.StandardAnalyzer
I'm using the analyzer: org.apache.lucene.analysis.standard.StandardAnalyzer
这里是一个例子:
如果我搜索gsx-*"我得到一个结果,索引字段包含铃木 GSX-R 1000 GSX-R1000 GSXR"
if I search for "gsx-*" I got a result, the indexed field contains "SUZUKI GSX-R 1000 GSX-R1000 GSXR"
但如果我搜索v-*",我没有得到任何结果.预期结果的索引字段包含:铃木 DL 1000 V-STROM DL1000V-STROMVSTROM V STROM"
but if I search for "v-*" I got no result. The indexed field of the expected result contains: "SUZUKI DL 1000 V-STROM DL1000V-STROMVSTROM V STROM"
如果我在没有*"的情况下搜索v-strom",它可以工作,但如果我只搜索v-str",例如我不会得到结果.(应该有结果,因为它是针对网上商店的实时搜索)
If I search for "v-strom" without "*" it works, but if I just search for "v-str" for example I don't get the result. (There should be a result because it's for a live search for a webshop)
那么,两个预期结果之间有什么区别?为什么它适用于gsx-"而不适用于v-"?
So, what's the difference between the 2 expected results? why does it work for "gsx-" but not for "v-" ?
推荐答案
我相信,StandardAnalyzer 会将连字符视为空格.所以它把你的查询 "gsx-*"
变成 "gsx*"
和 "v-*"
变成空,因为 at 也消除了单字母令牌.您在搜索结果中看到的字段内容是该字段的存储值,它完全独立于为该字段编制索引的术语.
StandardAnalyzer will treat the hyphen as whitespace, I believe. So it turns your query "gsx-*"
into "gsx*"
and "v-*"
into nothing because at also eliminates single-letter tokens. What you see as the field contents in the search result is the stored value of the field, which is completely independent of the terms that were indexed for that field.
所以你想要的是将v-strom"作为一个整体作为一个索引词.StandardAnalyzer
不适合这种文本.也许可以试试 WhitespaceAnalyzer
或 SimpleAnalyzer
.如果这仍然不能解决问题,您还可以选择将自己的分析器放在一起,或者只是从这两个开始并使用进一步的 TokenFilters
组合它们.theLucene 分析包 Javadoc.
So what you want is for "v-strom" as a whole to be an indexed term. StandardAnalyzer
is not suited to this kind of text. Maybe have a go with the WhitespaceAnalyzer
or SimpleAnalyzer
. If that still doesn't cut it, you also have the option of throwing together your own analyzer, or just starting off those two mentined and composing them with further TokenFilters
. A very good explanation is given in the Lucene Analysis package Javadoc.
顺便说一句,不需要在索引中输入所有变体,例如 V-strom、V-Strom 等.这个想法是让同一个分析器在索引中和解析时将所有这些变体标准化为相同的字符串查询.
BTW there's no need to enter all the variants in the index, like V-strom, V-Strom, etc. The idea is for the same analyzer to normalize all these variants to the same string both in the index and while parsing the query.
这篇关于“-"的 Lucene 索引问题特点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:“-"的 Lucene 索引问题特点
基础教程推荐
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- 降序排序:Java Map 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01