Can I share a value across multiple fields in Lucene?
I'm wondering if it's possible to 开发者_如何学JAVAadd a value to multiple fields at once in Lucene, so that I don't have to replicate the value across multiple fields and waste space unnecessarily.
For example, suppose I have a record representing a book and I have several sources for the book's summary, perhaps Wikipedia, Amazon, Library of Congress. Let's suppose I have a specific field in the index to store each of these, e.g. "summary.wikipedia", etc.
At the same time I want to have a general field name called just "summary" that I can set to one of the specific summaries, so that queries on the index can just search the "summary" field and not have to specify which summary they are wanting to search.
What I want to be able to do is specify multiple field identifiers when adding a field so that the value can be shared across those fields, without replicating the data and wasting space.
E.g.:
document.AddField( new string[] { "summary.wikipedia", "summary" }, "Summary of the book...", ... );
Any chance this is possible? Or do I simply have to add the field twice, with the same data but a different field name?
There is no way to do this in Lucene. As you stated in your comment, you can always make the general summary field an indexed but not stored field. Then you can add another field called "summary_source" that tells you which field the summary came from.
精彩评论