user3093010
user3093010

Reputation: 365

LUCENE.NET not searching with two AND

Why does this return 0 results a document exists with TopTabId = 1027 and ContentPlainRemaded = Word?

{+TopTabId:1027 +ContentPlainRemaded:Word*}

This query is working, but returns more records then needed:

{TopTabId:1027 +ContentPlainRemaded:Word*}

Not working code is:

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 is string type: ldoc.Add(new Field("TopTabId", doc.TopTabId.ToString(), Field.Store.YES, Field.Index.ANALYZED));

I tried NumericRangeQuery, but still return 0 results.

I think problem is not with TopTabId, because and this not working (return 0 result): {+ContentPlainRemaded:Word* +ContentPlainRemaded:Word*}

Upvotes: 0

Views: 61

Answers (1)

femtoRgon
femtoRgon

Reputation: 33341

I suspect that "TopTabId" is indexed as a numeric field. The QueryParse, in general, doesn't handle numeric fields. You have two options:

  • Change TopTabId to a non-numeric field. This is often the best choice if your field is an id number or something like that. Something that is more a string of digits, than a real number. Generally, if you aren't going to sort by it, or perform range queries, it probably doesn't need to be a numeric field.

  • Use a NumericRangeQuery to query on that field:

    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));

Upvotes: 1

Related Questions