Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introduction to Apache Solr

Introduction to Apache Solr

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

Rebecca Grenier

May 22, 2013
Tweet

Other Decks in Programming

Transcript

  1. Apache Solr How to use Apache Solr in your web

    Application – and why you might want to!
  2. Who am I? Rebecca Grenier Software Developer 13 years experience

    in Web and Software Development www.rebeccagrenier.com @beckythebest * Please Ask Questions
  3. 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
  4. 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
  5. What is a Document to Solr? •  The thing indexed

    in Solr that users are searching for •  For EatingWell, our documents are recipes.
  6. 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
  7. 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)
  8. 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)
  9. 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. <field name="title" type="text" indexed="true" stored="true" multiValued="false"/>
  10. Define Field Types in Schema.xml <fieldType name="text_term" class="solr.TextField" positionIncrementGap="100"> <analyzer>

    <charFilter class="solr.MappingCharFilterFactory" mapping="mapping-FoldToASCII.txt"/> <tokenizer class="solr.KeywordTokenizerFactory"/> <filter class="solr.LowerCaseFilterFactory"/> <filter class="solr.TrimFilterFactory"/> </analyzer> </fieldType>
  11. 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
  12. 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)
  13. 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!
  14. 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]