lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Laura Hollink <>
Subject Exact match on entire field
Date Wed, 06 May 2009 08:50:00 GMT

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  

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 =;
	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?


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message