0

我尝试使用短语查询搜索多个单词和特殊字符,例如“工程与建筑”,并将其添加到布尔查询中,但没有得到任何结果。我索引查询的方式是

doc.Add(new Field("Industry","Engineering & Construction", Field.Store.YES, Field.Index.ANALYZED,Field.TermVector.WITH_POSITIONS_OFFSETS));

对于搜索:

var booleanQuery = new BooleanQuery();
PhraseQuery phrasequery = new PhraseQuery();
phrasequery.Add(new Term("Industry","Engineering & Construction"));
booleanQuery.Add(phraseQuery, BooleanClause.Occur.MUST);

booleanQuery 包含 {+Industry:"Engineering & Construction"} 即使它没有得到想要的结果。

4

2 回答 2

1

这个

phrasequery.Add(new Term("Industry","Engineering & Construction"));

生成单个术语 ,Engineering & Construction但索引将依次包含两个术语engineering和(分析器将删除 )。像这样手动构建短语查询需要您了解标记,并分别添加每个术语,例如:construction&

phrasequery.Add(new Term("Industry","engineering"));
phrasequery.Add(new Term("Industry","construction"));

当然,更简单的方法是使用查询解析器;

Query phraseQuery = queryparser.parse("Industry:Engineering & Construction");
booleanquery.add(phraseQuery);
于 2013-07-12T15:55:19.180 回答
1

对于索引:

doc.Add(new Field("Industry","Engineering & Construction", Field.Store.YES, Field.Index.NOT_ANALYZED));

对于搜索:

TermQuery query = new TermQuery(new Term("Industry", "Engineering & Construction"));
booleanQuery.Add(query, BooleanClause.Occur.MUST);

这对我的标准很有帮助。它使用特殊字符搜索确切的短语。

于 2013-07-13T07:46:22.123 回答