I'm building a search engine that searches multiple document fields by default. Given a query string like "Bruce Lee", I would expect the results list to first show the documents containing both "Bruce" and "Lee", and then the documents which only contain one of those names. Most of the time, this is indeed what happens, but I've noticed that in certain circumstances, Lucene doesn't rank the results in the expected order. Specifically, it happens when I enter a query containing multiple words, searching multiple fields, AND try to put the results of that through a filter.

Code example is below. Is this a bug, or am I doing something wrong?

Thanks in advance. I can provide more information, if needed.

-MB

------------------------

String[] fields = new String[] {"title", "description", "body"};
IndexSearcher index = new IndexSearcher(INDEX_DIR);
Analyzer analyzer = new StandardAnalyzer();
String queryStr = "Bruce Lee";


            // OK
            System.out.println("\n\n - test run 0:");
            Query q0 = QueryParser.parse(queryStr, "title", analyzer);
            printResults(index.search(q0));

// OK
System.out.println("\n\n - test run 1:");
Query q1 = MultiFieldQueryParser.parse(queryStr, fields, analyzer);
printResults(index.search(q1));


// WRONG!
System.out.println("\n\n - test run 2:");
Query q2 = MultiFieldQueryParser.parse(queryStr, fields, analyzer);
Filter filt0 = new QueryFilter(new TermQuery(new Term("category", "movies")));
Query q2f = new FilteredQuery(q2, filt0);
printResults(index.search(q2f));


// OK
System.out.println("\n\n - test run 3:");
Query q3 = QueryParser.parse(queryStr, "description", analyzer);
Query q3f = new FilteredQuery(q3, filt0);
printResults(index.search(q3f));


            // WRONG!
            System.out.println("\n\n - test run 4:");
            printResults(index.search(q1, filt0));


--------------------------


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to