为什么返回0结果文档存在TopTabId=1027和ContentPlainRemad=Word?
{+TopTabId:1027 +ContentPlainRemaded:Word*}
此查询正在工作,但返回了所需的更多记录:
{TopTabId:1027 +ContentPlainRemaded:Word*}
不工作的代码是:
Query query1;
BooleanQuery querySearch = new BooleanQuery()
query1 = ((new QueryParser(VersionsToUse, "TopTabId", Analyzer)).Parse("1027"));
querySearch.Add(new BooleanClause(query1, Occur.MUST));
query1 = ((new QueryParser(VersionsToUse, "ContentPlainRemaded", Analyzer)).Parse("WORD"));
querySearch.Add(query1, Occur.MUST);
using (IndexSearcher searcher = new IndexSearcher(SearchIndexDirectory, true))
{
var docs = searcher.Search(querySearch, 100);
.................................
}
LUCENE.NET
TopTabID是字符串类型:ldoc. Add(new Field("TopTabId",doc.TopTabId.ToString(),Field.Store.YES,Field.Index.ANALYZED));
我尝试了NumericRangeQuery
,但仍然返回0个结果。
我认为问题不在于TopTabId,因为这不起作用(返回0结果):{ContentPlainRemaded-Word*ContentPlainRemaded-Word*}
我怀疑“TopTabId”被索引为数字字段。一般来说,QueryParse不处理数字字段。您有两种选择:
>
将TopTabId更改为非数字字段。如果您的字段是id号或类似的东西,这通常是最佳选择。更像是一串数字,而不是实数。通常,如果您不打算按它排序或执行范围查询,它可能不需要是数字字段。
使用NumericRangeQuery查询该字段:
BooleanQuery querySearch = new BooleanQuery()
Query query1 = NumericRangeQuery.newIntRange("TopTabId", 1027, 1027, true, true);
querySearch.Add(new BooleanClause(query1, Occur.MUST));
Query query2 = new QueryParser(VersionsToUse, "ContentPlainRemaded", Analyzer).Parse("WORD");
querySearch.Add(new BooleanClause(query2, Occur.MUST));