Hi,

I am trying to distinguish between a document that matches the query because the query *appears* in one of the fields, and a document that matches the query because the query equals the complete field. I do want to use an Analyzer for case- and punctuation normalization. For example:

The query "bloemendaal" matches the complete field "Bloemendaal" in a document in my result list. The query "adele" only partly matches the field "Adele Bloemendaal" in another document.

What is the best way to do this?

I currently solve it by first searching in a normal way, and than using the QueryParser on both the query and the relevant field in the documents in my result list. Finally, I simply compare the parsed query and the parsed field.

        QueryParser parser = new QueryParser(field,new StandardAnalyzer());
        Query query = parser.parse(q);
        Hits hits = is.search(query);
        ...     
        Document doc = hits.doc(i);
        Query myfield = parser.parse(doc.get("skos:prefLabel"));
if(myfield.equals(query)) System.out.println("Query exactly matches the entire field.");
        else System.out.println("The field contains the query.");

Is there a better way?

Thanks,
Laura

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org
For additional commands, e-mail: java-user-h...@lucene.apache.org

Reply via email to