Apache Solr – Facets Configuration

                 In the previous post, we have seen, how to configure Apache data import handler to import the data from the database to Solr and performed some basic search related queries on that. In this post, we are going to see how to configure the facets and how we can filter the results based on the facets. Before going to configure facets, we will seeApache Solr answers for a couple of questions.

What is a facet?

A facet is a specific property extracted from the data. This might be a flat list that allows only one choice or it might be a hierarchical list. The combination of all facets and values is often called as facet taxonomy.

What is the importance of facets or guided navigation?

The answer to this will be explained with an example. Here, when I am searching for products in an e-commerce store, as an end user,

  • I want shoes

  • I want “Puma” shoes

  • I want 9 inches of shoes

  • I want white shoes

                 To get the search results with the above-specified criteria, without grouping or facets, finding 9 inches, white, puma shoes from thousands of shoes across the product catalog is very difficult. To make search enjoyable to the user, we need to provide facets to the user. From the facets, the user can find the group to filter the results and finds the shoes what he wants. So, proving the right facets to the user ultimately improves the user experience and increase the sales.

             With Solr, we can configure date facets, range facets(for Price),  normal field facets(like String, Text, etc). Now, in this example, we will configure Solr to provide facets on “Retailer name” and the “Sale Amount”. We can enable the facets by providing the configuration to the request handler or during query time, we can send query parameters.

The request handler configuration is given below.



 <!-- default values for query parameters -->
 
 explicit
 
 
 on
 retailerName
 1
 after
 salePrice
 0
 400
 100
 


              Now, while querying the Solr, send “facet=true” query parameter. This tells Solr to send the facets as part of response. For example http:// < host > :<port>/solr/sampleCatalog/select?q=*%3A*&wt=xml&indent=true&facet=true

The search response for facets is given below.






10
9
9
9
9
9
8
8
8
8
8
8
7






8
40
46
11

100.0
0.0
400.0
5




                 As per the facets configuration, the response has facets on retailer name and sale price. Now, we will filter the search results for retailer “Red Start Diecast” by applying the filter query (fq=retailerName:”Red Start Diecast”) parameter. The mentioned retailer has 7 results associated. For  example http:// < host > : <port>/solr/sampleCatalog/select?q=*%3A*&wt=xml&indent=true&facet=true&fq=retailerName:%22Red%20Start%20Diecast%22

The search response is given below.




0
82

true
true
*:*
xml
retailerName:"Red Start Diecast"


...




7






1
5
1

100.0
0.0
400.0
0





Now, we will find search results between 100 to 200 price range. With this price range, we should get 40 results. For example

http:// < host > :<port>/solr/sampleCatalog/select?q=*%3A*&wt=xml&indent=true&facet=true&fq=salePrice:[100%20TO%20199]

The search response is given below.




0
4

true
true
*:*
xml
salePrice:[100 TO 199]



...
...
...
...
...
...
...
...
...
...





5
4
4
4
4
4
4
4
2
2
2
1






40

100.0
0.0
400.0
0





Advertisement

Siva Janapati is an Architect with experience in building Cloud Native Microservices architectures, Reactive Systems, Large scale distributed systems, and Serverless Systems. Siva has hands-on in architecture, design, and implementation of scalable systems using Cloud, Java, Go lang, Apache Kafka, Apache Solr, Spring, Spring Boot, Lightbend reactive tech stack, APIGEE edge & on-premise and other open-source, proprietary technologies. Expertise working with and building RESTful, GraphQL APIs. He has successfully delivered multiple applications in retail, telco, and financial services domains. He manages the GitHub(https://github.com/2013techsmarts) where he put the source code of his work related to his blog posts.

Tagged with: ,
Posted in Apache Solr, Facetes Configuration, guided navigation

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Dzone.com
DZone

DZone MVB

Java Code Geeks
Java Code Geeks
OpenSourceForYou
%d bloggers like this: