Slide 1

Slide 1 text

Apache Solr How to use Apache Solr in your web Application – and why you might want to!

Slide 2

Slide 2 text

Who am I? Rebecca Grenier Software Developer 13 years experience in Web and Software Development www.rebeccagrenier.com @beckythebest * Please Ask Questions

Slide 3

Slide 3 text

Why do we need a fancy search engine?

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

Actual Searches •  cicken •  chicken carden blue •  portabella mushroons •  parmesean cheese •  rosotto •  bean and spinish soup •  geek salad •  sherperds pie •  mooshoo •  lasagnia •  sauted sweet potatos •  italion salad

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

What is Apache Solr? •  A Server that provides Search Services via API •  handle misspelled entry •  phrase handling (cake vs. crab cake) •  also synonyms, facets, hit highlighting, pagination •  Highly Customizable, Fast, and Scalable •  Most Popular Enterprise Search Engine

Slide 11

Slide 11 text

What is a Document to Solr? •  The thing indexed in Solr that users are searching for •  For EatingWell, our documents are recipes.

Slide 12

Slide 12 text

The Inverted Index Term Doc # a 1,3,4,5,6,7,8 becoming 8 beginner’s 6 buy 9 buying 4,5,6 car 4 child 3 cooking 1 decorating 2 first 9 fun 1 guide 1,6 home 2,5,7,8 how 3,9

Slide 13

Slide 13 text

Getting Solr Running is Easy 1  download the archive 2  extract 3.  /solr/example $ java -jar start.jar (for more detailed instructions go to http://rebeccagrenier.com/solr)

Slide 14

Slide 14 text

Admin Interface Live Demonstration http://127.0.0.1:8983/solr/

Slide 15

Slide 15 text

Getting your Documents into Solr Create an XML, json, or csv file with your documents Post file to your update handler, the default url is http://127.0.0.1:8983/solr/update $ curl http://localhost:8983/solr/update -H "Content-Type: text/xml" --data-binary @data.xml (Instructions for indexing directly from MySQL:http://rebeccagrenier.com/solr)

Slide 16

Slide 16 text

Configuring Solr

Slide 17

Slide 17 text

Define Fields in Schema.xml •  Where you describe the fields in your document •  The only fields you need to define are fields you would like to search by or fields you would like to return to display along with the results.

Slide 18

Slide 18 text

Define Field Types in Schema.xml

Slide 19

Slide 19 text

Configure Search Behavior in SolrConfig.xml •  Does not need any changes for Solr to work •  add Query Components (such as spell check) to your query, and configure them •  Set parameter defaults, parameters you don’t want to have to pass in with your query string every time •  Here is where we are working on better recipe search results

Slide 20

Slide 20 text

Modify SolrConfig.xml to Get Better Recipe Search Results

Slide 21

Slide 21 text

So how do I use these Solr results in an application?

Slide 22

Slide 22 text

class SearchResults extends Backbone.Model url: "http://solr.localhost.com/solr/recipes/select? wt=json&fl=*,score" sync: (method, model, options) -> # override sync to use jsonp options.data = new Object() options.data.q = @get "search_phrase" if (search_phrase == "cake") || (search_phrase == "cakes") options.data.bq = "type_of_dish:Desserts*^30" Backbone.sync 'read', @, options parse: (data) -> results = new ew.RecipeResults(data.response.docs)

Slide 23

Slide 23 text

Conclusion •  Search in applications is a big deal •  Highly customizable to get the search results you want •  Provide users with the advanced features they expect •  Easy to get up and running •  The price is right – Free!

Slide 24

Slide 24 text

Resources •  Basic set up instructions: http://rebeccagrenier.com/solr •  Solr in Action http://www.manning.com/grainger •  Apache Solr website: http://lucene.apache.org/solr/ •  Solr Wiki http://wiki.apache.org/solr •  Got Feedback? [email protected]

Slide 25

Slide 25 text

Questions?