Solr-匹配所有提供的用户令牌



Enviornment=>solr-solr-8.9.0;11.0.12";2021-07-20 LTS

以下.csv文件在solr 中建立索引

books_id,cat,name,price,inStock,author,series_t,sequence_i,genre_s
0553573403,book,Game Thrones Clash,7.99,true,George R.R. Martin,"A Song of Ice and Fire",1,fantasy
0553573404,book,Gam Thrones,7.99,true,George Martin,"A Song of Ice and Fire",1,fantasy
0553573405,book,Throne Game,7.99,true,George,"A Song of Ice and Fire",1,fantasy
0553573406,book,Game Thrones Swords,7.99,true,George,"A Song of Ice and Fire",1,fantasy

我想模糊搜索一本名字写着《权力的游戏》的书。

字段类型:text_general是为多值为false的字段"name"配置的text_general"正在使用"solr"。StandardTokenizerFactory"作为"托管架构"中的令牌化器类。

输出应仅包含以下书籍ID:

0553573404 : (name - Gam Thrones) 
0553573405 : (name - Throne Game)

我预计以下图书ID不匹配:

0553573403 (name - Game Thrones Clash) ==> 'Clash' is extra tokens, so it should not come in output. 
0553573406 (name - Game Thrones Swords) ==> 'Swords' is extra tokens, so they should not come in output. 

只有在输入查询中指定的令牌是模糊匹配的。

我知道我可以在solr查询中使用运算符"AND"。我试过玩一个模糊匹配(输入:"Game Thrones"("Game"one_answers"Thrones(权力("的查询,但它给出了其他结果("Game Whones Clash"(book_id:0553573403(和"Game Rhones Swords"(book_id:0553573406((。

为此,执行以下查询

curl -G http://localhost:8983/solr/testCore2/select --data-urlencode "q=(name:'Game~') AND (name:'Thrones~')"

但是上面的查询在结果中给出了所有的图书id。(0553573403055357340405535734050553573406(

如何在solr查询中查找独立结果?

从我的角度来看,它不会像您预期的那样工作。

您可以尝试使用两个单独的字段。

第一个字段是非标记字段,您可以使用字符串字段类型,也可以使用文本字段类型和KeywordTokenizerFactoryLowerCaseFilterFactory

第二个字段应该是标记化的字段,根据您的要求,您可以在这里使用StandardTokenizerFactory或任何其他类似WhitespaceTokenizerFactory的字段。

当你想要模糊搜索或精确匹配时,你必须在非标记字段上搜索。

您也可以尝试使用邻近搜索。

Proximity Searches:邻近搜索的语法是在搜索阶段的末尾添加波浪号符号~和一个数值。它匹配彼此之间特定距离(所需术语移动次数(内的术语。例如:

curl -G http://localhost:8983/solr/testCore2/select --data-urlencode "q="Game Thrones"~1"

最新更新