Thanks for the reply Erik.
Sorry about the lateness of this reply; I was out of the office last week and it took me a bit to create a stand alone test case today.


I should prefix my statements by saying that I've discovered the problem I'm having is with 1.3, and it appears fixed in 1.4.
I also undestand that it is kind of illogical to "explain" a query that for a document that isn't returned by the query but nonetheless
I'm looking for confirmation that this is a bug and what can be done to fix it in 1.3
In doing so I hope to understand the main differences between explain() and search().


The test case is attached in the file LuceneTest.java

Notice that if you search for "currently classifies" in the content field and "9" in the id field, you will get 0 hits, but the explanation returns a value greater than 0.

Thanks in advance guys,

Minh



Erik Hatcher wrote:

Could you create a simple piece of code (using a RAMDirectory) that demonstrates this issue?

    Erik

On Sep 8, 2004, at 12:35 AM, Minh Kama Yie wrote:

Hi all,

Sorry I should clarify my last point.

The search() would return no hits, but the explain() using the apparently invalid docId returns a value greater than 0.

For what it's worth it's performing a PhraseQuery.

Thanks in advance,

Minh

Minh Kama Yie wrote:

Hi all,


I was wondering if anyone could tell me what the expected behaviour is for calling an explain() without calling a search() first on a particular query. Would it effectively do a search and then I can examine the Explanation in order to check whether it matches?


I'm currently looking at some existing code to this effect:

Explanation  exp = searcher.explain(myQuery, docId)
// Where docId was _not_ returned by a search on myQuery

if (exp.getValue() > 0.0f)
{
   // Assuming document for docId matched query.
}

Is the assumption wrong?

I ask because the result of this code is inconsistent with

Hits h = searcher.search(myQuery);  // there are not hits returned.

Thanks in advance,

Minh




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



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



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


import org.apache.lucene.store.Directory;
import org.apache.lucene.store.RAMDirectory;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.search.Hits;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.Explanation;
import org.apache.lucene.queryParser.QueryParser;

/**
 * User: minh
 * Date: 13/09/2004
 * Time: 09:43:43
 */
public class LuceneTest
{
    public static final StandardAnalyzer ANALYZER = new StandardAnalyzer();
    public static final String DOC0 = "currently classifies";
    public static final String DOC1 = "currently does something else";
    public static final String DOC2 = "classifies this as something else";
    public static final String DOC3 = "does not do anytihng at all";
    public static final String DOC4 = "what does this do?";
    public static final String DOC5 = "classifies this as something else";
    public static final String DOC6 = "classifies this as something else";
    public static final String DOC7 = "classifies this as something else";
    public static final String DOC8 = "currently classifies this as something else";
    public static final String DOC9 = "classifies this as something else";
    public static final String DOC10 = "currently classifies this as something else";
    
    public static final String[] DOCS_ARR = new String[] {DOC0, DOC1, DOC2, 
                                                          DOC3, DOC4, DOC5, 
                                                          DOC6, DOC7, DOC8, 
                                                          DOC9, DOC10};
    
    public static final String CONTENT_FIELD = "test-content-field";
    public static final String ID_FIELD = "test-id-field";
    
    public static void main(String[] args)
    {
        try
        {
            // Create the RAMDirectory
            Directory d = new RAMDirectory();
        
            // Create the writer.
            IndexWriter writer = new IndexWriter(d, ANALYZER, true);
        
            // Index the CONTENT_FIELD field.
            for (int i = 0; i < DOCS_ARR.length; i++)
            {
                // Create a document to index.
                Document doc = new Document();        
                doc.add(Field.Text(CONTENT_FIELD, DOCS_ARR[i]));
                doc.add(Field.Text(ID_FIELD, (new Integer(i)).toString()));
                writer.addDocument(doc);
            }
            writer.optimize(); 
            writer.close();
       
            // Create the searcher.
            IndexSearcher searcher = new IndexSearcher(d);
        
            // Create the query parser.
            int idToLookFor = 9;
            QueryParser parser = new QueryParser(CONTENT_FIELD, new 
StandardAnalyzer());
            parser.setOperator(QueryParser.DEFAULT_OPERATOR_OR);
            String searchString = "+(" + CONTENT_FIELD + ":\"currently classifies\") " 
+
                    "+(" + ID_FIELD + ":" + idToLookFor + ")";
            Query q = parser.parse(searchString);
            // Now do the searches.
            // Search for +("currently classifies").
            Hits hits = searcher.search(q);
        
            System.out.println("Hits for '" + searchString + "': " + hits.length());
        
            Explanation exp = searcher.explain(q, idToLookFor);
            System.out.println("Explain Value for '" + searchString + "': " + 
exp.getValue());
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }
}

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

Reply via email to