开发者

Lucene.Net IndexSearcher not working with BooleanQuery

I have the following code snippet:

        QueryParser parser = new MultiFieldQueryParser(Lucene.Net.Util.Version.LUCENE_29, new string[] { Field1, Field2, Field3 }, _analyzer);
        parser.SetDefaultOperator(QueryParser.Operator.AND);
        Query queryOrig= parser.Parse(queryString);

        var query = new BooleanQuery();
   开发者_开发问答     query.Add(queryOrig, BooleanClause.Occur.MUST);

        if (itemId.HasValue)
            query.Add(new TermQuery(new Term("Field3", NumericUtils.IntToPrefixCoded(itemId.Value))), BooleanClause.Occur.MUST);

        Hits hits;
        if (sortField != null)
        {
            var sort = new Sort(new SortField(sortField, isDescending));
            hits = Searcher.Search(query, null, sort);
        }
        else
            hits = Searcher.Search(query);

This piece of code is always returning 0 hits no matter what. If I do a direct search using the queryOrig without the boolean, it works fine. I'm quite sure the data is correct.

Thanks, Leonardo


Well.. It was a data problem! :D The lucene works just fine.

Thanks, Leo!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜