lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 16437] - AND NOT queries not working
Date Sun, 23 Feb 2003 08:32:57 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=16437>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=16437

AND NOT queries not working

otis@apache.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID



------- Additional Comments From otis@apache.org  2003-02-23 08:32 -------
Are you certain that AND NOT queries are not working?
I am questioning this bug report because TestQueryParser unit tests include AND
NOT queries, and the tests are passing.  This only shows that the QueryParser is
working, but it is possible that the bug is elsewhere.
If this is trully a bug, please reopen the bug report and attach some code that
demonstrates the bug.

Here, try this:

import junit.framework.*;
import org.apache.lucene.index.*;
import org.apache.lucene.analysis.*;
import org.apache.lucene.analysis.standard.*;
import org.apache.lucene.store.*;
import org.apache.lucene.document.*;
import org.apache.lucene.search.*;
import org.apache.lucene.queryParser.*;

public class AndNotTest extends TestCase {
    Directory dir = new RAMDirectory();
    String testText = "This is a test. (abc) Is there a bug OR not?
\"Question\"! xyz xyz";

    public AndNotTest(String tn) {
        super(tn);
    }

    protected void setUp() throws Exception {
        IndexWriter writer = new IndexWriter(dir, new StandardAnalyzer(), true);
        Document doc = new Document();
        doc.add(Field.Text("contents", testText));
        writer.addDocument(doc);
        writer.optimize();
        writer.close();
    }

    private boolean doQuery(String queryString) throws Exception {
        Searcher searcher = new IndexSearcher(dir);
        Analyzer analyzer = new StandardAnalyzer();
        Query query = QueryParser.parse(queryString, "contents", analyzer);
        System.out.println(query.toString());
        Hits hits = searcher.search(query);
        searcher.close();
        return (hits.length() == 1);
    }

    public void testAndNot() throws Exception {
        assertFalse(doQuery("test AND NOT bug"));
    }
}


If you run this, you will see something like this:

running AndNotTest
.+contents:test -contents:bug

Time: 0.973

OK (1 test)

So it looks like this is not a bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-dev-help@jakarta.apache.org


Mime
View raw message