为什么返回0会导致文档存在,TopTabId = 1027,ContentPlainRemaded = 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 3.0.3
TopTabID是字符串类型:
ldoc.Add(new Field("TopTabId", doc.TopTabId.ToString(), Field.Store.YES, Field.Index.ANALYZED));
我尝试了NumericRangeQuery
,但仍然返回0结果。
我认为问题不在于TopTabId,因为这不起作用(返回0结果):{+ContentPlainRemaded:Word* +ContentPlainRemaded:Word*}
答案 0 :(得分:1)
我怀疑" 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));