📜 ⬆️ ⬇️

Search on Drupal 7 using Apache Solr Part 4 - faceted filters


In previous articles, I mainly addressed issues related to full-text search. This time let's talk about facet filters for searching on Drupal using Apache Solr. For those who have not read previous materials, I recommend reading them for a better understanding of the topic. Carefully, under the cut a lot of pictures.


What is the facet and what is it for. A facet is a filter for a specific field. This filter works as a clarifying.

Consider a small example. You have the essence of the car and it is characterized by color and manufacturer. Initially, you can select multiple colors in the filter.


')
But choosing a manufacturer, you filter the sample and now only those colors are available that correspond to the selected manufacturer.



If you click on Renault again, the filter will return to its original state.

Such functionality is commonly used to search various information databases and directories.

So let's figure out how to set up the facets for searching on Drupal, through Apache Solr. In the previous lessons we have already installed the necessary modules and configured the Apache Solr server.

Now we need to perform a few more actions to customize the site:

1. First you need to install the module facetapi and Search facets (included in facetapi).

2. Now we will create a new content of the Auto Auto type and add fields for the color and the manufacturer’s company.



3. We also need to change the index settings so that it indexes the auto nodes. To do this in the settings of the index, go to the workflow tab and configure the bundle filter.



4. Then go to the Fields tab and include the color and brand fields in the index.



So, we set up an index for searching by auto nodes. We now turn directly to the facets. If you have already enabled the necessary modules and cleaned the cache (this is the most important thing in Drupal), then in the index settings you should have a new Facets tab. In this tab, you can enable facet filters for fields that are added to the index. For each facet, you can specify settings, but about them a little later. For now, just turn on the facets and index our nodes with the type auto.

Now you need to configure the output. An ordinary block is created for each facet filter and you can output it as you wish, for example, through regions or panels. There is one nuance to the facets - in order for them to be drawn, the view through which the Apache Solr request is made must already work. Simply put - on the page you should first place the view with the results, and lower in level (respectively later in drawing) the blocks of the facets. After I placed the facet blocks in the region, I got this page



Now let's talk about the settings of the facets. In the screenshot you can see the settings form.



Consider the most important of them:


For clarity, I recorded a video with an example of the work of the facet filters

Source: https://habr.com/ru/post/180083/


All Articles