[英]Tokenize result of a NGramFilterFactory in Solr (query analyzer)
我正在使用NGramFilterFactory進行索引和查詢。
所以,如果我正在搜索“溢出”,它會創建一個這樣的查詢:
mySearchField:"ov ve ... erflow overflo verflow overflow"
但如果我拼錯“溢出”,即“owerflow”沒有匹配,因為查詢周圍的引號:
mySearchField:"ow we ... erflow owerflo werflow owerflow"
是否有可能將NGramFilteFactory的結果標記化,它將創建一個如下查詢:
mySearchField:"ow"
mySearchField:"we"
mySearchField:"erflow"
mySearchField:"owerflo"
mySearchField:"werflow"
mySearchField:"owerflow"
在這種情況下,solr也會找到結果,因為令牌“erflow”存在。
您不需要像編寫的那樣對查詢進行標記。 檢查schema.xml
是否在索引時和查詢時應用了NGramFilterFactory
。 然后,您正在使用的查詢解析器會產生差異。 使用LuceneQParser
您將獲得您正在尋找的結果,但不會使用DisMax
和eDisMax
。
我使用eDisMax
和debugQuery=on
檢查了mySearchField:owerflow
查詢:
<str name="querystring">text:owerflow</str>
<str name="parsedquery">
+((text:o text:w text:e text:r text:f text:l text:o text:w text:ow text:we text:er text:rf text:fl text:lo text:ow text:owe text:wer text:erf text:rfl text:flo text:low text:ower text:werf text:erfl text:rflo text:flow text:owerf text:werfl text:erflo text:rflow text:owerfl text:werflo text:erflow text:owerflo text:werflow text:owerflow)~36)
</str>
如果查看生成的查詢的結尾,您將看到~36
其中36是從查詢生成的n-gram數。 因為那個~36
你沒有得到任何結果,但你可以通過mm
參數改變它,這是最小匹配。
如果您將查詢更改為mySearchField:owerflow&mm=1
或低於25的值,您將獲得您正在尋找的結果。
這個答案和你的答案之間的區別在於,使用EdgeNGramFilterFactory
,像mySearchField:werflow
EdgeNGramFilterFactory
的中綴查詢mySearchField:werflow
不會返回任何結果,而是使用NGramFilterFactory
。
總之,如果你使用NGramFilterFactory
制作拼寫校正,我強烈建議有在看SpellCheckComponent
以及為此目的作出准確。
好的,我找到了解決問題的快捷方法。
fieldType具有可選屬性autoGeneratePhraseQueries(默認值= true)。 如果我將autoGeneratePhraseQueries設置為false,一切正常。
說明:
schema.xml中使用的fieldType:
<fieldType name="edgytext" class="solr.TextField" autoGeneratePhraseQueries="false">
<analyzer type="index">
<tokenizer class="solr.KeywordTokenizerFactory"/>
<filter class="solr.LowerCaseFilterFactory"/>
<filter class="solr.EdgeNGramFilterFactory" minGramSize="1" maxGramSize="25" />
</analyzer>
<analyzer type="query">
<tokenizer class="solr.WhiteSpaceTokenizerFactory"/>
<filter class="solr.LowerCaseFilterFactory"/>
<filter class="solr.EdgeNGramFilterFactory" minGramSize="1" maxGramSize="25" />
</analyzer>
</fieldType>
如果要索引單詞“surprise”,則跟蹤標記位於索引中:
s,su,sur,surp,surpr,surpri,surprise,surprise
如果您正在搜索“surpriese”(拼寫錯誤),則solr會創建以下標記(匹配的標記為粗體):
s , su , sur , surp , surpr , surpri ,surprie,surpries,surpriese
將要創建的真實查詢如下所示:
mySearchField:s,mySearchField:su,mySearchField:sup ..等等
但是如果你設置autoGeneratePhraseQueries = true,則會創建以下查詢:
mySearchField:“s su surp supr surprie surpries surpriese”
這是一個短語查詢,與索引的術語不匹配。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.