Hi,

  i've got problems while using wildcard and fuzzy searches.

While indexing a bunch of documents it could happen that a field of all
documents will be left empty (empty String).

I don't know wether this field will be included into the index at all.

But this leads to a problem while searching. If i create some Queries
(actually this does the QueryParser for me) on that field and run a
search with these queries, i would expect no results.

However, WildcardQuery and FuzziQuery sometimes generate a
NullPointerException in WildcardTermEnum.termCompare(...).

It seems to me that this does not happen if i add an additional unused
field to all documents but it may be that this works for me due to other
reasons. To explain what i mean, i've attached some lines of test code.

btw: I'm using lucene nightly-build 20020814.

Am i missing something or is this a bug?

Another question: An WildcardQuery that is constructed of only
non-wildcards gives me an StringIndexOutOfBoundsException while
searching. Shouldn't this be handled in a smarter way?

Thanks in advance,

  Bjoern

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

public class Tester {

        public void testMe (boolean additionalField) throws Exception {
                RAMDirectory indexStore = new RAMDirectory();
                IndexWriter writer = new IndexWriter(indexStore, new SimpleAnalyzer(), 
true);
                Document doc = new Document();
                doc.add(Field.Text("bar0", "foo"));
                doc.add(Field.Text("bar1", ""));

                // magical unused extra field
                if (additionalField)
                        doc.add(Field.Text("bar2", "foo"));

                writer.addDocument(doc);
                writer.optimize();
                writer.close();

                IndexSearcher searcher = new IndexSearcher(indexStore);

                Query[] queries = new Query[3];
                queries[0] = new WildcardQuery(new Term("bar0", "f?o"));        // 
works as expected
                queries[1] = new TermQuery(new Term("bar1", "foo"));            // 
this one too
                queries[2] = new WildcardQuery(new Term("bar1", "f?o"));        // 
strange

                Hits result;

                for (int q = 0; q < queries.length; q++) {
                        System.out.println ("Query " + q + " (" + 
queries[q].getClass().getName() + ")");
                        System.out.println ("\ttoString (\"bar0\") = " + 
queries[q].toString ("bar0"));
                        System.out.println ("\ttoString (\"bar1\") = " + 
queries[q].toString ("bar1"));

                        result = searcher.search(queries[q]);

                        if (result.length() == 0) {
                                System.out.println ("\tno results");
                        }
                        for (int i = 0; i < result.length(); i++) {
                                Document d = result.doc(i);
                                System.out.println ("\tresult: " + d.get ("bar0") + " 
- " + d.get ("bar1"));
                        }
                }
        }

        public static void main(String[] _argv) {
                Tester t = new Tester();
                try {
                        System.out.println ("## With additional unused extra field it 
works");
                        t.testMe(true);
                }
                catch (Throwable th) {
                        System.err.println ("OOPS: " + th.getMessage());
                        th.printStackTrace();
                }
                try {
                        System.out.println ("\n## Without additional unused extra 
field it won't work");
                        t.testMe(false);
                }
                catch (Throwable th) {
                        System.err.println ("OOPS: " + th.getMessage());
                        th.printStackTrace();
                }
        }
}

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

Reply via email to