How to implement Facet Search on data in Drupal 7

author
By Team Srijan Sep 3, 2015

If you are thinking about creating a website where you can show your big data, then with the help of facet search your website user can actually find specific data related to them. In this blog, I will help you in setting up Facet search functionality on your data in Drupal 7. 

The Faceted Search module provides a search API and a search interface for allowing users to browse content in such a way that they can rapidly get acquainted with the scope and nature of the content, and never get lost in the data. More than a search interface, this is an information navigation and discovery tool.

In order to make such functionality, you need to install some modules on your site. We will first make an  Indexing engine which will index all your data, and then we will make blocks of specific data which will allow you to filter all the related data to itself.

Modules to install for implementing Facet Search:

  1. Facet API
  2. Search API
  3. Database search
  4. Search Facets
  5. Search Views
  6. Entity API

Now that we are done with installing and enabling above modules, follow the below steps. Steps to follow:

  1. Create the content type and add fields in respective content type.

  2. Configure the search server

  3. configure the search index

  4. Add fields on in Facet API

  5. Create a complete view  of your data

Each step is explained below

Step 1. Create content type and add fields in that:

Let’s take an example that we created content type

  • Title: Company

  • Fields: Address

  • Fields: County

Now create content of above content type and add data into it.

Right now we have content with data into it, and also modules. Now we need to configure above modules as per our functionality on data.

Step 2. Configure the search server:

Go to configuration admin page (configuration/admin) in your Drupal 7 site and click on the search API in Search and metadata section. You should be now on Search configuration setting. We will create a search engine for our data. You should see page like below:

Configure the search server

Now click on Add server link. Give a name to your server I gave (MYSQL), Choose database service for your service class and click create a server. Your server should be like below.

 

Configure the search server

 

Step 3. Configure the search Index:

Now we will make our search index, which will index all data from using search server and database server. It will do indexing as the user search for data on site and give faster results. Go back to search API settings and click on Add Index link. You should be on below page now.Configure the search Index

Values for above form:

  • Index name: Business Information

  • Item type: Node

  • Server: MYSQL which you create earlier

  • Index items immediately: Checked

Click on create Index. Now we will select which field to be indexed from our data so we will select fields we want. In our case, we will select

  • content type

  • Address

  • Title

  • County

and click on save the configuration.

What is the outcome

we created our database server, Index server and added fields which need to be. As you added fields for indexing Facet API actually make Facet blocks of those fields.We will enable them later.

Now run Cron in your site which populate the Index.

Step 4. Create a view of your data which need to be Indexed and Displayed to your site user:

Install Views and enable it. Go to Structure > Views. click add a new view. Select below values for each field:

  • Show content: Business Information “This will be name of your Search server”

  • Create a page: checked

  • Path: node

  • Display format: Table

Your view information look like below:

Create a view of your data which need to be Indexed and Displayed to your site use

Click on continue & edit button. Now in the Fields section click on add fields and Filter Index node. Add Index fields you want to show to your user. Your selection will look like as below.

Create a view of your data which need to be Indexed and Displayed to your site use- 2

Complete all configuration of the specific field and click Apply Display. You are done with creating view. You are now able to see this view on your front page(/node).

Next step is to enable all blocks of your facet search. Earlier we added fields which needed to be Indexed. Actually when you add fields for indexing Facet API it creates Blocks of those fields respectively. You have to just enable them from Search settings.

Step 5. Enable Facet block from Search settings:

Go to configuration and click on Search API from search and metadata. Now just click on edit in You are able to see various configuration options like below.

Enable Facet block from Search setting

Click on Facets and enable facets you want. When you enable and save the configuration, it will create blocks of respective fields.

Step 6. Enable your Facet block from Blocks:

Now go to structures and blocks. Here you are able to see your block in Disable section just enable them in any regions of your theme.

Congratulations! Your site is ready. Visit your home page and it should look like as below. As you select options from blocks your main view shows you data as per your selection.

Note:-

Facet API have many configuration options. You should take a look to them like showing selection in Blocks in Checkbox etc. However, facet API is not able to give you Multiple Facet search functionality. So, I am now working on developing custom module of widget and behavior which will give functionality of Multiple facet selection search. Facet API have OR and AND but only AND works not OR among fields.

Read my next blog on How to Drive through certain scenarios while implementing Facet Search API.

Please free feel to ask your queries related to Facet search in the comment section below. 

Our Innovation

Our Recent Innovations

Let’s start our conversation

  • Business Inquiry
  • Career
  • Others

Business Inquiry

Career

Others