Developing your own facets can be tricky when working with Apache Solr. The role of Facets is to focus a search on specified criteria and within defined parameters. The Facet module does the work of narrowing and advancing searches. The Facet module develops the parameters that relate to the data in the contents which are listed.
There are times where more detailed and incremental options are required. You might be looking into the option of developing your own facets to suit your needs using the API. There is not much information on how to do this available.
Let’s discuss developing your own facet. The index document needs to contain the field that relates with the facet. Within the custom field, some code needs to be written. If you are not sure about the terminologies or confused about how to code it, it may be best to consult a Java programmer. I will only be discussing the procedure and not the actual code.
There needs to be a function which defines all the parameters needed and links to the facet’s API. An array can be used to store the search info and the returns. The facets should relate with the content type within the index. The search info that needs array slots are:
name: Make this link with the product’s node nid in the index for Solr.
label: This is the product’s name that the user specifically wants.
description: This is the product produced by the manufacturer that the user wants.
field: This links with the product’s node nid.
dependency plugins: Link this with the role array. This serves fields depending on whether the user is a guest or a registered user.
default widget: links
allowed operators: Give AND & OR operators that need to be true for the criteria.
The array needs to be sorted. The active arrays are given priority and they are counted out. They are then displayed in ascending order. Ensure that all fields within the facet need to be filled for the search to be conducted. This can be controlled with the usual If/Else statements and a return with a message. A minimum facet count would also not be allowed. A return array is placed in the code to return it from the function. The results of the search need to be translated so that the user can interpret the data. This is created within a different class. Here is how to setup the interface:
Run a function which links to the nid and arrays the values. The database can then output a request to the user asking for values which are greater than or equal to each unit placed in the value array.
If the code is done right, you should be able to enable the block and the facet should be ready.
The Facet API bonus module and the Dependency plugin
The Facet API bonus module contains features such as added scalability, additional filters and dependency plugins. A Dependency plug is working if a field shows up and depends on another field being activated. Let me give an example:
On a car manufacturer website, some cars have sunroofs and some don’t. Each car with a sunroof allows the user to choose the color of the sunroof. The choice of the sunroof color is dependent on the type of car chosen. If the user chooses a car that does not have a sunroof, then the sunroof color option will not show up. This is the work of the Dependency plugin.
So, first we enable the bonus module. Go to the facet page. There will be drop down arrows for each facet under the heading “operations” on the right. Click the drop down arrow on the right and select “configure dependencies” for the one you would like to tweak. The next page will contain more information to help you gain the desired result.
James Dean is a avid hiker, that lives & breathes the outdoor life, capturing with his childhood passion of photography. Following his interest in business, he writes columns for Drupal developers in Orange County . Follow him on Google