7

我希望我的 Lucene 查询包含类似于以下内容的内容:

公司名称:梅赛德斯卡车

它将与 companyName 字段中的字符串“mercedes trucks”进行完全匹配。
companyName 是一个未标记的字段,但任何带有空格的内容都会返回空结果。

new TermQuery(new Term("companyName", "mercedes trucks"));

如果涉及空格,则始终产生 0 个结果。否则我的程序运行良好。

4

7 回答 7

10

也许更换:

mercedes trucks 

mercedes?trucks

为我工作。

于 2010-05-31T18:40:06.380 回答
9

像这样使用 PhraseQuery:

//create the query objects
BooleanQuery query = new BooleanQuery();
PhraseQuery q2 = new PhraseQuery();
//grab the search terms from the query string
string[] str = Sitecore.Context.Request.QueryString[BRAND_TERM].Split(' ');
//build the query
foreach(string word in str)
{
  //brand is the field I'm searching in
  q2.Add(new Term("brand", word.ToLower()));
}

//finally, add it to the BooleanQuery object
query.Add(q2, BooleanClause.Occur.MUST);

//Don't forget to run the query
Hits hits = searcher.Search(query);

希望这可以帮助!

于 2010-02-16T20:13:25.553 回答
4

您在搜索时使用的分析器可能与创建索引时使用的分析器不同。

在搜索时尝试使用 KeywordAnalyzer。它将创建搜索字符串的单个标记,这可能是您正在寻找的。

于 2009-03-11T10:14:15.240 回答
0

您是否考虑过使用PhraseQuery?该字段是否必须取消标记?我相信 unkenized 是用于 ids 等,而不是用于具有多个单词作为内容的字段。

于 2009-03-10T12:47:55.817 回答
0

I'm guessing here - does exactMask add quotes around the string? You should simply use the string "mercedes truck", without manipulating it.

new TermQuery(new Term("companyName", "mercedes trucks"));
于 2009-03-09T15:57:33.467 回答
0

我发现可行的最佳方法是使用关键字分析器和以下查询“mercedes?trucks”来解析查询。

于 2010-10-26T22:38:19.293 回答
-1

Even I am facing the same issue. You have to do the following thing to get rid of from this issue. 1)When add the field value to the document remove the spaces in between. 2)Make the field value in lowercase. 3)Make the search text in lowercase. 4)Remove the white spaces in the search text. Regards ~shef

于 2009-08-05T09:42:26.963 回答