SlideShare a Scribd company logo
Solr Facets and Custom
Indices
Filtering Search Results in new
ways
Quick Intro to Solr
Solr (lucene.apache.org/solr)

Open Source Enterprise Search Platform

Powerful full-text search

Highly reliable, scalable and fault tolerant

Faceted Search

Java based, standalone server within a servlet
container (e.g. Jetty, Tomcat, Jboss, and the like)

Large community
Solr and Drupal
ApacheSolr ( drupal.org/project/solr )

Faceted Search - Faceted search is supported if you use the
facet API module.

More like this - "More like this" blocks can be added to any
node page.

Search Pages - Multiple search pages

Search Environments - Add multiple Solr Search cores

Range Queries – (Requires Facet Api Slider)

Full Entity support – Hooks for indexing custom entities

Exportable - Configs are exportable
ApacheSolr Related Modules
• FacetAPI (drupal.org/project/facetapi)
• FacetAPI Bonus (drupal.org/project/facetapi_bonus)
• Apache Solr Attachments
• Apache Solr User Indexing
• Apache Solr Term Indexing
• Apache Solr Multilingual
• Apache Solr Views
• …. and many more
What are Facets
Wikipedia: Faceted Search
Faceted search, also called faceted navigation or faceted
browsing, is a technique for accessing information
organized according to a faceted classification system,
allowing users to explore a collection of information by
applying multiple filters. A faceted classification system
classifies each information element along multiple explicit
dimensions, enabling the classifications to be accessed
and ordered in multiple ways rather than in a single, pre-
determined, taxonomic order.
What are Facets
Facets Prerequisites
Solr Set up
ApacheSolr Module installed and configured
(see Docs link from project)
FacetAPI Module installed
(optionally) FacetAPI Bonus Module Installed
Note: The FacetAPI partially supports Drupal's
internal search via the Faceted Navigation for Search
module (search_facatapi).
Enabling Facets
Admin Configuration Apache Solr Search Settings (tab)→ → →
Enabling Facets
List of available
Facets that can
be enabled with
settings options.
List is based on
supported entity
fields being
indexed.
Enabled Facets
generate blocks
to be placed on
page.
Facet Display Settings
Use Drop down.
Facet Dependencies Settings
Facet Filter Settings
Place Blocks
Admin Structure Blocks→ →
Note: Facets generally only show up when search results are
displayed. So no need to limit to search pages.
Custom Indices
WHY?
Not all fields are indexed by Solr, for example, file
attachments.
Not all field types are supported by FacetAPI display
widgets. You can “convert” them to a string or text index
which is supported by a display widget.
The Hooks
/**
* Build the Solr document object before passing it back
* to be indexed.
* Add index fields here.
*/
function hook_apachesolr_index_document_build(
ApacheSolrDocument $document, $entity, $entity_type,
$env_id)
Note: Formerly known as hook_apachesolr_update_index()
/**
* Alter the query after it's prepared and cached.
*
*/
Function hook_apachesolr_query_alter(
DrupalSolrQueryInterface $query)
Dynamic Solr Fields
Custom index fields need to be named in a way that Solr can
understand it's type. The Drupal Solr configuration uses the
following convention for dynamic fields:
<type><single/multiple>_<field name>
<type> = s for string, t for text, b for boolean, or i for integer
<single/multiple> = s for single / m for multiple values
<field name> is the name to id this field.
Note: Even though you can create boolean and numeric
indices, there are not many facet display widgets that work
well with this. String and Text types are best.
Some Examples
tm_multiple_dynamic_text_areas
This would be an index who's content will contain multiple
searchable text areas.
ss_single_string_field
This would be an index who's content will be a single string
value.
Note: text type indices will be index by words contain in
them. Strings are indexed “whole”.
Putting this together
/*Implements hook_apachesolr_index_document_build(). */
function my_module_apachesolr_index_document_build(
ApacheSolrDocument $document, $entity,
$entity_type, $env_id) {
if(in_array($entity->type, array('article','book','etd','media')))
{
if( ! empty($entity->field_attachments) ) {
foreach($entity->field_attachments AS $lang => $attachments) {
foreach ($attachments as $id => $attachment) {
$document->setField('ss_has_field_attachments', 'Yes' );
if ( isset($attachment['filename'])) {
$ext = strtoupper(pathinfo($attachment['filename'],
PATHINFO_EXTENSION));
$document->setMultiValue('sm_field_attachments_ext', $ext);
}
}
}
}
else {
$document->setField('ss_has_field_attachments', 'No' );
}
}
}
Putting this together
/**
* Implementation of hook_apachesolr_query_alter($query)
*
* Add the newly indexed fields from above to the query result.
*/
function nph_search_apachesolr_query_alter($query) {
$query->addParams(array(
'fl' => array('ss_has_field_attachments'))
);
$query->addParams(array(
'fl' => array('sm_field_attachments_ext'))
);
}
Note: The key above has a lower case L not a 1
Activating The Code
If not enabled, enable the new module with hooks.
If code added to existing module, clear cache so new hooks
registered.
Rebuild the entire Solr index by:

Go to Admin Configuration Apache Solr Search→ →

Use the “Delete the Search & Solr Index” button

Use the “Queue all content for reindexing” button

Repeatedly click the “Index queued content” button until all content sent.
(Less load on the system than Index All Queued content)
Wait for a few minutes until the Solr server has indexed
everything.
Using the new Indices
Admin Configuration Apache Solr Search Settings (tab)→ → →
Click on the Facets link
Enable the new file extension facet
Set your display settings:
Use checkbox list / “Or” this facet
Add the block to the sidebar
Voila!
Questions?

More Related Content

PDF
Numeric Range Queries in Lucene and Solr
PDF
The Many Facets of Apache Solr - Yonik Seeley
PDF
PostgreSQL: Advanced features in practice
PDF
DConf 2016 std.database (a proposed interface & implementation)
ODP
How to Become a Tree Hugger: Random Forests and Predictive Modeling for Devel...
PDF
Analysis of Fatal Utah Avalanches with Python. From Scraping, Analysis, to In...
PDF
CREATE INDEX … USING VODKA. VODKA CONNECTING INDEXES, Олег Бартунов, Александ...
KEY
Postgres rules
Numeric Range Queries in Lucene and Solr
The Many Facets of Apache Solr - Yonik Seeley
PostgreSQL: Advanced features in practice
DConf 2016 std.database (a proposed interface & implementation)
How to Become a Tree Hugger: Random Forests and Predictive Modeling for Devel...
Analysis of Fatal Utah Avalanches with Python. From Scraping, Analysis, to In...
CREATE INDEX … USING VODKA. VODKA CONNECTING INDEXES, Олег Бартунов, Александ...
Postgres rules

What's hot (20)

PDF
Swift 함수 커링 사용하기
PDF
Leveraging Symfony2 Forms
PDF
Swift에서 꼬리재귀 사용기 (Tail Recursion)
PDF
Closure, Higher-order function in Swift
PDF
Elixir formatter Internals
PDF
Everything you always wanted to know about forms* *but were afraid to ask
PPT
Python tutorial
DOCX
Airline reservation project using JAVA in NetBeans IDE
PDF
Pooya Khaloo Presentation on IWMC 2015
PPTX
Graph Database Query Languages
PDF
Creating New Streams: Presented by Dennis Gove, Bloomberg LP
KEY
Fields in Core: How to create a custom field
PDF
BabelJS - James Kyle at Modern Web UI
PPTX
Php forum2015 tomas_final
PDF
Introduction to Python
PPT
JavaScript Arrays
KEY
Python Dictionary
PPT
Xm lparsers
PDF
WP_Query, pre_get_posts, and eliminating query_posts()
DOCX
What are arrays in java script
Swift 함수 커링 사용하기
Leveraging Symfony2 Forms
Swift에서 꼬리재귀 사용기 (Tail Recursion)
Closure, Higher-order function in Swift
Elixir formatter Internals
Everything you always wanted to know about forms* *but were afraid to ask
Python tutorial
Airline reservation project using JAVA in NetBeans IDE
Pooya Khaloo Presentation on IWMC 2015
Graph Database Query Languages
Creating New Streams: Presented by Dennis Gove, Bloomberg LP
Fields in Core: How to create a custom field
BabelJS - James Kyle at Modern Web UI
Php forum2015 tomas_final
Introduction to Python
JavaScript Arrays
Python Dictionary
Xm lparsers
WP_Query, pre_get_posts, and eliminating query_posts()
What are arrays in java script
Ad

Viewers also liked (20)

PDF
Facettensuche mit Lucene und Solr
PDF
The Seven Deadly Sins of Solr - By Jay Hill
PPTX
Battle of the Giants Round 2 - Apache Solr vs. Elasticsearch
PDF
Warum 'ne Datenbank, wenn wir Elasticsearch haben?
PPTX
Apache Solr vs Oracle Endeca
PDF
Grouping and Joining in Lucene/Solr
PDF
State of Solr Security 2016: Presented by Ishan Chattopadhyaya, Lucidworks
ZIP
Attachments 2012 01_12
PDF
Faceted Search and Solr
PDF
Working with deeply nested documents in Apache Solr
PDF
The Evolution of Lucene & Solr Numerics from Strings to Points: Presented by ...
PDF
Building and Running Solr-as-a-Service: Presented by Shai Erera, IBM
PDF
Working with deeply nested documents in Apache Solr
PPTX
Indexing popsi....
PPTX
National library of India. Library and information science
PPT
Indexing and hashing
PPT
Chain indexing
PPTX
Post coordinate indexing .. Library and information science
PPTX
Precis
PPT
Indexing
Facettensuche mit Lucene und Solr
The Seven Deadly Sins of Solr - By Jay Hill
Battle of the Giants Round 2 - Apache Solr vs. Elasticsearch
Warum 'ne Datenbank, wenn wir Elasticsearch haben?
Apache Solr vs Oracle Endeca
Grouping and Joining in Lucene/Solr
State of Solr Security 2016: Presented by Ishan Chattopadhyaya, Lucidworks
Attachments 2012 01_12
Faceted Search and Solr
Working with deeply nested documents in Apache Solr
The Evolution of Lucene & Solr Numerics from Strings to Points: Presented by ...
Building and Running Solr-as-a-Service: Presented by Shai Erera, IBM
Working with deeply nested documents in Apache Solr
Indexing popsi....
National library of India. Library and information science
Indexing and hashing
Chain indexing
Post coordinate indexing .. Library and information science
Precis
Indexing
Ad

Similar to Solr facets and custom indices (20)

PDF
Apace Solr Web Development.pdf
KEY
Switching search to SOLR
PDF
Basics of Solr and Solr Integration with AEM6
PPTX
Assamese search engine using SOLR by Moinuddin Ahmed ( moin )
PPT
Building Intelligent Search Applications with Apache Solr and PHP5
PPTX
Drupal 7 and SolR
PDF
Search Engine-Building with Lucene and Solr
PPTX
Search Engine Building with Lucene and Solr (So Code Camp San Diego 2014)
KEY
Intro to Apache Solr for Drupal
PPTX
20130310 solr tuorial
PPTX
Making your Drupal fly with Apache SOLR
PDF
PDF
Search Engine-Building with Lucene and Solr, Part 1 (SoCal Code Camp LA 2013)
KEY
Apache Solr - Enterprise search platform
PDF
Apache Solr crash course
PDF
Apache Solr
PDF
Apache Solr Search Mastery
PPTX
Search Engines: Best Practice
PDF
Information Retrieval - Data Science Bootcamp
PDF
Apache Solr Workshop
Apace Solr Web Development.pdf
Switching search to SOLR
Basics of Solr and Solr Integration with AEM6
Assamese search engine using SOLR by Moinuddin Ahmed ( moin )
Building Intelligent Search Applications with Apache Solr and PHP5
Drupal 7 and SolR
Search Engine-Building with Lucene and Solr
Search Engine Building with Lucene and Solr (So Code Camp San Diego 2014)
Intro to Apache Solr for Drupal
20130310 solr tuorial
Making your Drupal fly with Apache SOLR
Search Engine-Building with Lucene and Solr, Part 1 (SoCal Code Camp LA 2013)
Apache Solr - Enterprise search platform
Apache Solr crash course
Apache Solr
Apache Solr Search Mastery
Search Engines: Best Practice
Information Retrieval - Data Science Bootcamp
Apache Solr Workshop

More from cgmonroe (13)

PDF
Structured SEO Data Overview and How To
PDF
Structured SEO Data: An overview and how to for Drupal
PDF
Tips on Securing Drupal Sites - DrupalCamp Atlanta (DCA)
PDF
Tips on Securing Drupal Sites
PDF
Becoming "Facet"-nated with Search API
ODP
Intro to drupal module internals asheville
ODP
Using Content Delivery Networks with Drupal
PPTX
HTML Purifier, WYSIWYG, and TinyMCE
PPTX
Using the Features API
PPTX
The Drupal Strongarm Module - Tips and Tricks.
PPT
Intro to CSS Selectors in Drupal
PPT
Drupal Workflow Concepts
PPTX
TriDUG WebFM Presentation
Structured SEO Data Overview and How To
Structured SEO Data: An overview and how to for Drupal
Tips on Securing Drupal Sites - DrupalCamp Atlanta (DCA)
Tips on Securing Drupal Sites
Becoming "Facet"-nated with Search API
Intro to drupal module internals asheville
Using Content Delivery Networks with Drupal
HTML Purifier, WYSIWYG, and TinyMCE
Using the Features API
The Drupal Strongarm Module - Tips and Tricks.
Intro to CSS Selectors in Drupal
Drupal Workflow Concepts
TriDUG WebFM Presentation

Recently uploaded (20)

PDF
Web App vs Mobile App What Should You Build First.pdf
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
project resource management chapter-09.pdf
PDF
WOOl fibre morphology and structure.pdf for textiles
PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
PDF
DP Operators-handbook-extract for the Mautical Institute
PPTX
Tartificialntelligence_presentation.pptx
PPTX
cloud_computing_Infrastucture_as_cloud_p
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Approach and Philosophy of On baking technology
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
1. Introduction to Computer Programming.pptx
PDF
A comparative study of natural language inference in Swahili using monolingua...
PDF
Encapsulation theory and applications.pdf
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
A novel scalable deep ensemble learning framework for big data classification...
PDF
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
Web App vs Mobile App What Should You Build First.pdf
Group 1 Presentation -Planning and Decision Making .pptx
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
Programs and apps: productivity, graphics, security and other tools
project resource management chapter-09.pdf
WOOl fibre morphology and structure.pdf for textiles
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
DP Operators-handbook-extract for the Mautical Institute
Tartificialntelligence_presentation.pptx
cloud_computing_Infrastucture_as_cloud_p
Encapsulation_ Review paper, used for researhc scholars
Approach and Philosophy of On baking technology
MIND Revenue Release Quarter 2 2025 Press Release
1. Introduction to Computer Programming.pptx
A comparative study of natural language inference in Swahili using monolingua...
Encapsulation theory and applications.pdf
NewMind AI Weekly Chronicles - August'25-Week II
A novel scalable deep ensemble learning framework for big data classification...
From MVP to Full-Scale Product A Startup’s Software Journey.pdf

Solr facets and custom indices

  • 1. Solr Facets and Custom Indices Filtering Search Results in new ways
  • 2. Quick Intro to Solr Solr (lucene.apache.org/solr)  Open Source Enterprise Search Platform  Powerful full-text search  Highly reliable, scalable and fault tolerant  Faceted Search  Java based, standalone server within a servlet container (e.g. Jetty, Tomcat, Jboss, and the like)  Large community
  • 3. Solr and Drupal ApacheSolr ( drupal.org/project/solr )  Faceted Search - Faceted search is supported if you use the facet API module.  More like this - "More like this" blocks can be added to any node page.  Search Pages - Multiple search pages  Search Environments - Add multiple Solr Search cores  Range Queries – (Requires Facet Api Slider)  Full Entity support – Hooks for indexing custom entities  Exportable - Configs are exportable
  • 4. ApacheSolr Related Modules • FacetAPI (drupal.org/project/facetapi) • FacetAPI Bonus (drupal.org/project/facetapi_bonus) • Apache Solr Attachments • Apache Solr User Indexing • Apache Solr Term Indexing • Apache Solr Multilingual • Apache Solr Views • …. and many more
  • 5. What are Facets Wikipedia: Faceted Search Faceted search, also called faceted navigation or faceted browsing, is a technique for accessing information organized according to a faceted classification system, allowing users to explore a collection of information by applying multiple filters. A faceted classification system classifies each information element along multiple explicit dimensions, enabling the classifications to be accessed and ordered in multiple ways rather than in a single, pre- determined, taxonomic order.
  • 7. Facets Prerequisites Solr Set up ApacheSolr Module installed and configured (see Docs link from project) FacetAPI Module installed (optionally) FacetAPI Bonus Module Installed Note: The FacetAPI partially supports Drupal's internal search via the Faceted Navigation for Search module (search_facatapi).
  • 8. Enabling Facets Admin Configuration Apache Solr Search Settings (tab)→ → →
  • 9. Enabling Facets List of available Facets that can be enabled with settings options. List is based on supported entity fields being indexed. Enabled Facets generate blocks to be placed on page.
  • 13. Place Blocks Admin Structure Blocks→ → Note: Facets generally only show up when search results are displayed. So no need to limit to search pages.
  • 14. Custom Indices WHY? Not all fields are indexed by Solr, for example, file attachments. Not all field types are supported by FacetAPI display widgets. You can “convert” them to a string or text index which is supported by a display widget.
  • 15. The Hooks /** * Build the Solr document object before passing it back * to be indexed. * Add index fields here. */ function hook_apachesolr_index_document_build( ApacheSolrDocument $document, $entity, $entity_type, $env_id) Note: Formerly known as hook_apachesolr_update_index() /** * Alter the query after it's prepared and cached. * */ Function hook_apachesolr_query_alter( DrupalSolrQueryInterface $query)
  • 16. Dynamic Solr Fields Custom index fields need to be named in a way that Solr can understand it's type. The Drupal Solr configuration uses the following convention for dynamic fields: <type><single/multiple>_<field name> <type> = s for string, t for text, b for boolean, or i for integer <single/multiple> = s for single / m for multiple values <field name> is the name to id this field. Note: Even though you can create boolean and numeric indices, there are not many facet display widgets that work well with this. String and Text types are best.
  • 17. Some Examples tm_multiple_dynamic_text_areas This would be an index who's content will contain multiple searchable text areas. ss_single_string_field This would be an index who's content will be a single string value. Note: text type indices will be index by words contain in them. Strings are indexed “whole”.
  • 18. Putting this together /*Implements hook_apachesolr_index_document_build(). */ function my_module_apachesolr_index_document_build( ApacheSolrDocument $document, $entity, $entity_type, $env_id) { if(in_array($entity->type, array('article','book','etd','media'))) { if( ! empty($entity->field_attachments) ) { foreach($entity->field_attachments AS $lang => $attachments) { foreach ($attachments as $id => $attachment) { $document->setField('ss_has_field_attachments', 'Yes' ); if ( isset($attachment['filename'])) { $ext = strtoupper(pathinfo($attachment['filename'], PATHINFO_EXTENSION)); $document->setMultiValue('sm_field_attachments_ext', $ext); } } } } else { $document->setField('ss_has_field_attachments', 'No' ); } } }
  • 19. Putting this together /** * Implementation of hook_apachesolr_query_alter($query) * * Add the newly indexed fields from above to the query result. */ function nph_search_apachesolr_query_alter($query) { $query->addParams(array( 'fl' => array('ss_has_field_attachments')) ); $query->addParams(array( 'fl' => array('sm_field_attachments_ext')) ); } Note: The key above has a lower case L not a 1
  • 20. Activating The Code If not enabled, enable the new module with hooks. If code added to existing module, clear cache so new hooks registered. Rebuild the entire Solr index by:  Go to Admin Configuration Apache Solr Search→ →  Use the “Delete the Search & Solr Index” button  Use the “Queue all content for reindexing” button  Repeatedly click the “Index queued content” button until all content sent. (Less load on the system than Index All Queued content) Wait for a few minutes until the Solr server has indexed everything.
  • 21. Using the new Indices Admin Configuration Apache Solr Search Settings (tab)→ → → Click on the Facets link Enable the new file extension facet Set your display settings: Use checkbox list / “Or” this facet Add the block to the sidebar