lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From syedfa <>
Subject Searching over multiple fields using XML document
Date Sun, 02 Nov 2008 23:53:21 GMT

Dear fellow Java/Lucene developers:

I am trying to search an xml document over multiple fields.  The index I
created using the SAX method.  I am trying to search shakespeare's "Hamlet"
over the <speaker> and <lines> tags for words that the user is looking for. 
I am thinking of using the MultiFieldQueryParser however, I also read that a
better alternative would be to combine the various fields together.  In the
book, "Lucene in Action", the author writes:

"A synthetic 'contents' field in our test environment uses this scheme to
put author and subjects together:

doc.add(Field.UnStored("contents", author + " " + subjects));

We used a space (" ") between author and subjects to separate words for the

I am not sure I fully understand what the author is referring to here.  In
my situation I have the following:

public void endElement(String uri, String localName, String qName) throws
		try {
				Field reference = new Field(qName, elementBuffer.toString(),
Field.Store.YES, Field.Index.NO, Field.TermVector.NO);
			else if(qName.equals("SPEAKER")){
				Field speaker = new Field(qName, elementBuffer.toString(),
Field.Store.YES, Field.Index.TOKENIZED, Field.TermVector.YES);
			else if(qName.equals("LINES")){
				Field lines = new Field(qName, elementBuffer.toString(),
Field.Store.YES, Field.Index.TOKENIZED, Field.TermVector.YES);
		} catch (CorruptIndexException e) {
		} catch (IOException e) {


How would I combine the fields together into one synthetic field here so
that in my searcher code, I would search over one field, yet retrieve the
results from the several fields that the keyword is found and show that to
the user?

All I want to do, is allow a user to search an xml document over multiple
fields and return the results with the keywords they are searching for,
highlighted in the results list, just as google does when searching for
websites.   At this point, I am able to do a simple/fuzzy/wildcard search
over one field in the xml document, but would like to extend this
functionality over multiple fields.  Any ideas?

Thanks in advance to all who reply.
View this message in context:
Sent from the Lucene - Java Users mailing list archive at

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

View raw message