Imagine your products have multiple prices, and depending on your client's location you search one of the defined fields. So you have a field for price in US dollars, in Euros, and so on. But what you would like to do is return the field you are using for displaying the price of the document as a "price" no matter what field you use. This recipe will show you how to do it.
Let's begin with the following index structure (put all the entries in the
fields
section of yourschema.xml
file):<field name="id" type="string" indexed="true" stored="true" required="true" multiValued="false" /> <field name="name" type="text" indexed="true" stored="true"/> <field name="price_usd" type="double" indexed="true" stored="true" /> <field name="price_eur" type="double" indexed="true" stored="true" /> <field name="price_pln" type="double" indexed="true" stored="true" />
We will also use the following test data:
<add> <doc> <field...