1. Responsive Facets
with Apache Solr
Dallas, TX
February 12, 2013
Discussion document – Strictly Confidential & Proprietary
2. Agenda …
What we will cover tonight
• Concept of Facets
• The Problem with RDBMS
• Solr to the Rescue
• Solr by example
• Architecture basics
• Putting data in
• Getting data out
Responsive Facets with Apache Solr
February 12, 2013 2
3. Concept of facets…
Sometimes the facets only have groups with values
Responsive Facets with Apache Solr
February 12, 2013 3
4. Concept of facets…
Sometimes, they also include a count for the value
Responsive Facets with Apache Solr
February 12, 2013 4
5. The Problem with RDBMS…
Easy enough, just attributes of the product…
Responsive Facets with Apache Solr
February 12, 2013 5
6. The Problem with RDBMS…
Easy enough, just attributes of the product… Or is it!
Responsive Facets with Apache Solr
February 12, 2013 6
7. The Problem with RDBMS…
Easy enough, just attributes of the product… Or is it!
Responsive Facets with Apache Solr
February 12, 2013 7
8. The Problem with RDBMS…
Easy enough, just attributes of the product… Or is it!
Responsive Facets with Apache Solr
February 12, 2013 8
9. The Problem with RDBMS…
Easy enough, just attributes of the product… Or is it!
Responsive Facets with Apache Solr
February 12, 2013 9
10. Solr to the rescue…
We need a better way to organize our data for fast queries
Solr is a standalone search server built on the Lucene Search Library. It offers all the
capabilities of the Lucene library and extends the capabilities. Solr interactions are handled
through a REST-like API, allowing you to input and retrieve data in a variety of formats.
Solr can run within most servlet containers including Tomcat and Jetty.
• Full-Text Search Capabilities
• Standards Based Open Interfaces – XML, JSON and HTTP
• Linearly scalable, auto index replication, auto failover and recovery
• Near Real-time indexing
• SolrJ library capable of binary over HTTP communication
• Faceted Search and Filtering
Responsive Facets with Apache Solr
February 12, 2013 10
11. Solr to the rescue…
Products are inserted into Solr as a Document
• Fields and Dynamic Fields
• Unique Key on a specific field
• Fields are typed
– String is a literal
– Text is a tokenized string
• CopyField allows you to populate multiple fields off a single field insert
Responsive Facets with Apache Solr
February 12, 2013 11
12. Solr by example…
Solr utilizes a REST-like interface with XML, JSON and binary capabilities
Let’s look at a few examples…
Responsive Facets with Apache Solr
February 12, 2013 12
13. Architecture basics…
Running Solr
• Embedded
– Makes your application more bloated
– More resource intensive
• Standalone
– Run on it’s own server
– Network traffic hit
– Replication is an option
• SolrCloud
– High availability
– Sharded with replication
– http://bit.ly/TdAJBw
Responsive Facets with Apache Solr
February 12, 2013 13
15. Architecture basics…
Communicating withSolr
SolrJ
• Java binary communication
• Library that abstracts connection, query formation and response processing
Inject Server
<bean id="solrServer" class="org.apache.solr.client.solrj.impl.LBHttpSolrServer">
<constructor-argvalue="${solr.url.primary}"/>
</bean>
Inject Search Service
<bean id="blSearchService" class="com.vology.core.service.search.VolSearchServiceImpl">
<constructor-argname="solrServer" ref="${solr.source.primary}" />
</bean>
Utilize SolrJ Library
• ServerContext
• SolrQuery
• SolrDocument
• QueryResponse
Responsive Facets with Apache Solr
February 12, 2013 15
16. Putting data in…
How do we get the data into Solr?
Transform fields
• Populate transient fields
• Determine terminating object
Query product data from DB
• Utilize Hibernate to retrieve relevant products
Populate SolrJSolrDocument
• Java Reflection to get fields we want
• SolrField data from Field
Add SolrDocument
• Group into a List<SolrDocument>
• Add full set or incremental
• Commit
Responsive Facets with Apache Solr
February 12, 2013 16
17. Getting data out
How do we get the data out of Solr?
Build SolrQuery
• Query searchable fields from Field table
• Creates ‘&’ delimited list for qf from Field table
• We utilize a boost value (^100.0)
Add Search Facets
• Uses search facet and search facet range tables
• Creates ‘&’ delimited list of facet.field and facet.range
Query on ServerContext
• server.query(SolrQuery)
• QueryResponse returned
Populate ProductSearchResult
• Set facets
• Set results
• Passed back to SearchController
Responsive Facets with Apache Solr
February 12, 2013 17
18. Contact ...
Tell me what you thought!
blemons@credera.com
@brentlemons
slideshare.net/brentlemons
linkedin.com/in/brentlemons
github.com/brentlemons
Do you think this presentation should be at OSCon?
• Tweet @oscon to let them know!
Responsive Facets with Apache Solr
February 12, 2013 18