Reputation: 1334
I have found in the code base I am working on that when creating lucene Document the same Field'd name is used many times for different values (terms).
doc.add(new Field("sameName", value1, store, index));
doc.add(new Field("sameName", value2, store, index));
...
doc.add(new Field("sameName", value3, store, index));
Is it correct? What is it useful for?
Then this Field's name is used during searching:
QueryParser parser = new QueryParser(Version.LUCENE_40, "sameName", new StandardAnalyzer(
Version.LUCENE_40));
It seems that during searching only field "sameName" is used although there are number of other Fields in the Document. Strange for me. Does it make sense?
Upvotes: 2
Views: 376
Reputation: 2250
A field can be indexed with multiple values. For example you could have a "content field which has all the words in the document but also metadata such as author or tags.
Regarding your search issue, depending on the field you initialize the QueryParse with (in this case "sameName") this would be the only searched field. You could of course add multiple fields to your QueryParser.
Upvotes: 2