You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by bu...@apache.org on 2003/02/23 09:32:57 UTC
DO NOT REPLY [Bug 16437] -
AND NOT queries not working
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