I am new to Lucene. Last night I started writing a small prototype indexer
and search to become familiar with Lucene before I try to integrate it into
my application. I believe I'm using Lucene correctly, however I can't
figure out why I'm getting the error I am. I have tried searching through
the FAQ's and the mail archive. I hate asking what is probably a stupid
question.
I'm getting the following error with the query shown:
Query : ( DATE:[20021110 - 20021118] )
java.lang.IllegalArgumentException: At least one term must be non-null
Here is the code sample I'm using and below that is the results I'm getting.
I left the two cases which worked in the output. It's the third case that
I'm concerned about.
package lucenetest;
import org.apache.lucene.document.*;
import org.apache.lucene.analysis.*;
import org.apache.lucene.index.*;
import org.apache.lucene.search.*;
import org.apache.lucene.queryParser.*;
import java.util.*;
public class LuceneTest {
private Map writerMap = new HashMap();
private Map searcherMap = new HashMap();
public LuceneTest() {}
private IndexWriter getWriter(String name)throws Exception{
if(!writerMap.containsKey(name)){
writerMap.put(name, new IndexWriter(name, new SimpleAnalyzer(),
true));
}
return (IndexWriter)writerMap.get(name);
}
private Searcher getSearcher(String name)throws Exception{
if(!searcherMap.containsKey(name)){
searcherMap.put(name, new IndexSearcher(name));
}
return (Searcher)searcherMap.get(name);
}
public void addInfo(String indexName, String id, String title, String
description, String date)throws Exception{
IndexWriter writer = getWriter(indexName);
Document doc = new Document();
doc.add(Field.UnIndexed("ID", id));
doc.add(Field.Text("TITLE", title));
doc.add(Field.Text("DESCRIPTION", description));
doc.add(Field.Text("DATE", date));
writer.addDocument(doc);
writer.optimize();
}
public Hits find(String indexName, String title, String description,
String start, String end)throws Exception{
Searcher searcher = getSearcher(indexName);
Analyzer analyzer = new SimpleAnalyzer();
String[] fields = null;
ArrayList fieldList = new ArrayList();
StringBuffer buff = new StringBuffer();
if(title!=null){
buff.append("(TITLE:");
buff.append(title);
buff.append(")");
fieldList.add("TITLE");
}
if(description!=null){
buff.append("(DESCRIPTION:");
buff.append(description);
buff.append(")");
fieldList.add("DESCRIPTION");
}
if(start!=null || end!=null){
buff.append(" ( DATE:[");
buff.append(start);
buff.append(" - ");
buff.append(end);
buff.append("] ) ");
fieldList.add("DATE");
}
Object[] objs = fieldList.toArray();
fields = new String[objs.length];
for (int i = 0; i < objs.length; i++) {
fields[i] = (String)objs[i];
}
System.out.println("Query : " + buff.toString());
Query query = MultiFieldQueryParser.parse(buff.toString(), fields,
analyzer);
return searcher.search(query);
}
public void showHits(Hits hits)throws Exception{
for (int i = 0; i < hits.length(); i++) {
System.out.println("Score = " + hits.score(i) + " : Document = " +
hits.doc(i));
}
System.out.println("==");
System.out.println("====================================");
System.out.println("==");
}
public static void main(String[] args) {
LuceneTest test = new LuceneTest();
try{
test.addInfo("myindex", "1", "This is a book about nothing", "It
really does not contains a damn thing worth mentioning. Read it yourself",
"20021105");
test.addInfo("myindex", "2", "This is a book about Something", "It
really does contains a something worth mentioning. Read it yourself",
"20021126");
test.addInfo("myindex", "3", "This is a book about Everything", "It
really does contains a everything worth mentioning. Read it yourself",
"20021113");
test.addInfo("myindex", "4", "Slim", "He's everything you'd ever want
in a developer", "20021115");
test.addInfo("myindex", "5", "Slim Jim Shady", "I'm not so sure this
is the same guy but he is a developer", "20021103");
test.addInfo("myindex", "6", "Slim Shady", "I know this is not the guy
but he too is a developer who know's everything", "20021125");
test.showHits(test.find("myindex", "This", null, null, null));
test.showHits(test.find("myindex", "This", "everything", null, null));
test.showHits(test.find("myindex", null, null, "20021110",
"20021118"));
}catch(Exception e){
e.printStackTrace(System.out);
}
System.out.println("Done");
}
}
=======RESULTS==========
Query : (TITLE:This)
Score = 0.5787209 : Document = Document<Unindexed<ID:1> Text<TITLE:This is a
book about nothing> Text<DESCRIPTION:It really does not contains a damn
thing worth mentioning. Read it yourself> Text<DATE:20021105>>
Score = 0.5787209 : Document = Document<Text<DATE:20021126>
Text<DESCRIPTION:It really does contains a something worth mentioning. Read
it yourself> Text<TITLE:This is a book about Something> Unindexed<ID:2>>
Score = 0.5787209 : Document = Document<Unindexed<ID:3> Text<TITLE:This is a
book about Everything> Text<DESCRIPTION:It really does contains a everything
worth mentioning. Read it yourself> Text<DATE:20021113>>
==
====================================
==
Query : (TITLE:This)(DESCRIPTION:everything)
Score = 0.4458295 : Document = Document<Unindexed<ID:3> Text<TITLE:This is a
book about Everything> Text<DESCRIPTION:It really does contains a everything
worth mentioning. Read it yourself> Text<DATE:20021113>>
Score = 0.12860465 : Document = Document<Unindexed<ID:1> Text<TITLE:This is
a book about nothing> Text<DESCRIPTION:It really does not contains a damn
thing worth mentioning. Read it yourself> Text<DATE:20021105>>
Score = 0.12860465 : Document = Document<Text<DATE:20021126>
Text<DESCRIPTION:It really does contains a something worth mentioning. Read
it yourself> Text<TITLE:This is a book about Something> Unindexed<ID:2>>
Score = 0.09920931 : Document = Document<Text<DATE:20021115>
Text<DESCRIPTION:He's everything you'd ever want in a developer>
Text<TITLE:Slim> Unindexed<ID:4>>
Score = 0.07593799 : Document = Document<Text<DATE:20021125>
Text<DESCRIPTION:I know this is not the guy but he too is a developer who
know's everything> Text<TITLE:Slim Shady> Unindexed<ID:6>>
==
====================================
==
Query : ( DATE:[20021110 - 20021118] )
java.lang.IllegalArgumentException: At least one term must be non-null
at org.apache.lucene.search.RangeQuery.<init>(Unknown Source)
at org.apache.lucene.queryParser.QueryParser.getRangeQuery(Unknown
Source)
at org.apache.lucene.queryParser.QueryParser.Term(Unknown Source)
at org.apache.lucene.queryParser.QueryParser.Clause(Unknown Source)
at org.apache.lucene.queryParser.QueryParser.Query(Unknown Source)
at org.apache.lucene.queryParser.QueryParser.Clause(Unknown Source)
at org.apache.lucene.queryParser.QueryParser.Query(Unknown Source)
at org.apache.lucene.queryParser.QueryParser.parse(Unknown Source)
at org.apache.lucene.queryParser.QueryParser.parse(Unknown Source)
at org.apache.lucene.queryParser.MultiFieldQueryParser.parse(Unknown
Source)
at lucenetest.LuceneTest.find(LuceneTest.java:80)
at lucenetest.LuceneTest.main(LuceneTest.java:106)
Done
Thanks,
Michael
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>