In one of our recent project we have needed Faceted Search Block by taxonomy vacabulary in search result page. This might have been straight forward but it was not due to some reason. It was my first time working on Faceted block and I am now discussing my findings here.

The requirement was:

We have some taxonomy vocabulary(Figure 1). We need to create 4 faceted block and place right sidebar of search result page. This requirement was not in the specification. We get this in our Feedback phase.

What was the difficulties in implementetion:

There was many content types in this project and same taxonomy terms are used in different content type as different fields.

When we wanted to create Faceted block using the Facet API then we found that Faceted block can be created using the Fields used in the Content Types. So when we create a Faceted Block using a field 'Disease Taxonomy' then it was being displayed for the content that has this field, but not for any other content type that uses the same taxonomy.

For example: The block was showing for the 'Content type 3' (it has the field 'Disease Taxonomy' using Disease vocabulary) but not for the but not for the 'Content type 1' (it has the field 'Page Taxonomy' using the Disease vocabulary) or 'Content type 2' (it has 'Disease' field also using the Disease vocabulary). Since all the 3 content type has one field using the 'Disease' vocabulary so the Faceted block should be displayed for the contents of all type. But it was not possible because the fields name were different. So we need to have a common(same machine name) field using the same vocabulary in all content type to create a faceted block for this vocabulary.

What was our solution:

As we have already more that 200 content added so changing the existing fields was not a good solution. Again in some content type, 2 or 3 vocabularies were used combindly in one field, it was requirement. So we needed to think alternative solution.

Then we have decided to create 4 new common fields using the 4 vocabularies for all content type.

1. Common Disease taxonomy

2. Common Vaccine Taxonomy

3. Common Management Taxonomy

4. Common Tooltype Taxonomy

Then we made them hidden (by CSS) from the admin interface so that the admin user does not see the fields when they add/update content.

We have internally assigned terms in those fields when the content is being added or updated depending on the taxonomy terms that is selected for the content.

More details by an example:

'Content type 1' has 'Disease' and 'Management Toolkit' vacabulary in one field named 'Page Taxonomy'. So we have added 2 new fields using the 'Disease' and 'Management Toolkit' vacabulary individually. The new 2 fields are invisible in admin interface. When any new content added in 'Content Type 1' then we internally take the term ids selected for the 'Disease' and 'Management Toolkit' taxonomy and then assign those terms for the new 2 fields.

Similarly we add(re use) newly created fileds for all content type where needed.

Content Type

Existing Taxonomy Fields

Newly added common taxonomy Fields

Basic Page

1.Disease Taxonomy

2.Vaccine Taxonomy

3.Management Toolkit Taxonomy

1. Common Disease taxonomy

2. Common Vaccine Taxonomy

3. Common Management Taxonomy

Detail Page

1. Page Taxonomy ( Disease, Management Toolkit)

1. Common Disease taxonomy

2. Common Management Taxonomy

Tools and Training

 

1. Tool Type Taxonomy

2. Detail Page Taxonomy ( vaccine, disease, management toolkit)

1. Common Tooltype

2. Common Disease taxonomy

3. Common Vaccine Taxonomy

4. Common Management Taxonomy

Vaccine Detail

 

1. Vaccine Taxonomy

2. Disease Taxonomy

1. Common Disease taxonomy

2. Common Vaccine Taxonomy

 

In this way all the content will be tagged with 4 taxonomy vocabulary terms (Disease, Vaccine, Management Toolkit, Tool Type) by 4 common fields (Common Disease taxonomy, Common Vaccine Taxonomy, Common Management Taxonomy, Common Tooltype Taxonomy)

Now we can create 4 faceted block using the new 4 new common fields.

Then we have displayed four faceted block in the search result page.

This is a conceptual discussion so I've skipped all internal code here. The reason of sharing this is, I think we should keep this scenario in mind and we should ask and be confirm about the Faceted search functionality at the earlier stage so that we can design and implement the functionaliy accordingly.

Thank you.

Add new comment