responsive facets with apache solr
DESCRIPTION
This is a presentation I presented to JavaMUG on February 12, 2013. I have submitted a proposal on the topic to OSCon for 2013.TRANSCRIPT
Discussion document – Strictly Confidential & Proprietary
Responsive Facets with Apache SolrDallas, TXFebruary 12, 2013
Responsive Facets with Apache Solr
2February 12, 2013
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
3February 12, 2013
Concept of facets…
Sometimes the facets only have groups with values
Responsive Facets with Apache Solr
4February 12, 2013
Concept of facets…
Sometimes, they also include a count for the value
Responsive Facets with Apache Solr
5February 12, 2013
The Problem with RDBMS…
Easy enough, just attributes of the product…
Responsive Facets with Apache Solr
6February 12, 2013
The Problem with RDBMS…
Easy enough, just attributes of the product… Or is it!
Responsive Facets with Apache Solr
7February 12, 2013
The Problem with RDBMS…
Easy enough, just attributes of the product… Or is it!
Responsive Facets with Apache Solr
8February 12, 2013
The Problem with RDBMS…
Easy enough, just attributes of the product… Or is it!
Responsive Facets with Apache Solr
9February 12, 2013
The Problem with RDBMS…
Easy enough, just attributes of the product… Or is it!
Responsive Facets with Apache Solr
10February 12, 2013
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
11February 12, 2013
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
12February 12, 2013
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
13February 12, 2013
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
Architecture basics…
Responsive Facets with Apache Solr
14February 12, 2013
Architecture basics…
Our environment
Responsive Facets with Apache Solr
15February 12, 2013
Architecture basics…
Communicating with Solr
SolrJ
• Java binary communication
• Library that abstracts connection, query formation and response processing
<bean id="solrServer" class="org.apache.solr.client.solrj.impl.LBHttpSolrServer"> <constructor-arg value="${solr.url.primary}"/> </bean>
Inject Server
Inject Search Service <bean id="blSearchService" class="com.vology.core.service.search.VolSearchServiceImpl"> <constructor-arg name="solrServer" ref="${solr.source.primary}" /> </bean>
Utilize SolrJ Library
• ServerContext
• SolrDocument
• SolrQuery
• QueryResponse
Responsive Facets with Apache Solr
16February 12, 2013
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 SolrJ SolrDocument• 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
17February 12, 2013
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
18February 12, 2013
Contact ...
Tell me what you thought!
@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!