Rafal Kuc is a team leader and software developer. Right now he is a software architect and Solr and Lucene specialist. Mainly focused on Java, but open on every tool and programming language that will make the achievement of his goal easier and faster. Rafal is also one of the founders of solr.pl site where he tries to share his knowledge and help people with their problems. Rafał is a DZone MVB and is not an employee of DZone and has posted 75 posts at DZone. You can read more from them at their website. View Full User Profile

Solr 4.0: New 'fl' Parameter Functionalities – First Look

  • submit to reddit

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.

Lets begin

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.

Source: solr.pl/en/2011/11/22/solr-4-0-new-fl-parameter-functionalities-first-look

Published at DZone with permission of Rafał Kuć, author and DZone MVB.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)