Dear all,

I tried to search using two approaches, Query and BooleanQuery. To my
surprise, the two behaves different on the same index? Or I made
something wrong?

On the same index, Query can get results whereas BooleanQuery get NOTHING. Why?

The codes are shown as follows.

Using Query,

        ......
        IndexSearcher searcher = new IndexSearcher(fsDirectory);
        Analyzer chineseAnalyzer = new ChineseAnalyzer();
        QueryParser queryParser = new QueryParser(searchField, chineseAnalyzer);
        Query query = 
queryParser.Parse(DBTools.FilterKeyFieldValue(searchKeyword));
        Hits results = searcher.Search(query);
        ......

Using BooleanQuery,

        ......
        IndexSearcher searcher = new IndexSearcher(fsDirectory);
        Term term = new Term(searchField, searchKeyword);
        TermQuery termQuery = new TermQuery(term);
        BooleanQuery booleanQuery = new BooleanQuery();
        booleanQuery.Add(termQuery, BooleanClause.Occur.MUST);
        Hits results = searcher.Search(booleanQuery);
        ......

I think the codes should be correct. But why do they get different
results on the same index?

Thanks so much for your help!
LB

Reply via email to