Solr 4.0: New 'fl' Parameter Functionalities – First Look
In connection with the work of slowly upcoming release of Apache Solr version 4.0 I thought that it is time to shed some light on the functionalities that you will get into your hands with the release of Apache Solr 4.0. The first change we will look at is a simple, but albeit useful functionality called pseudo fields, together with additional features related to the fl parameter.
The Apache Solr 4.0 has changed slightly how fl parameter can be used. In 4.0 this parameters can be added to the query multiple times and Solr will take all the values into consideration. Sometimes it will be useful, at least in my case.
Custom field names
In Solr 4.0 you will be able to rename fields that are returned in the results. Imagine that, depending on the query we would like rename fields like price_en, price_pl or price_fr to price. In Solr 4.0, we can do this by placing the following query:
This will cause the field price_pl to be returned as price.
All fields with a common name start
If we want Solr to return the all fields whose name starts with the word price (useful for dynamic fields) all we will need to do is add the following parameter to the query:
Returning function values
The last functionality, which we will look at today, is the ability add the result of the function, as a field in the documents returned by Solr. Thus, in Solr 4.0 will have the option to add such values as sum of prices, or calculated distance between two points. Quite useful. To use this functionality You will have to add the appropriate function call to the fl parameter for example:
The above will result in Solr returning all the fields for the document (value *) and a field named stock, which will be the sum of two fields: stockShop and stockMain.
A few words at the end
In addition to the new features mentioned above, there is one more thing that is connected to the parameter fl – the DocTransformer. However I decided to leave it for a separate blog post.
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)