Implementing Autocomplete with Solr and j Query Magic

  • Slides: 25
Download presentation
Implementing Autocomplete with Solr and j. Query Magic Made Easy by Paul Oakes

Implementing Autocomplete with Solr and j. Query Magic Made Easy by Paul Oakes

Objectives • Find – Solr/Lucene project – j. Query autocomplete • Configure – schema.

Objectives • Find – Solr/Lucene project – j. Query autocomplete • Configure – schema. xml, solrconfig. xml – j. Query autocomplete plugin – Search API workaround for j. Query • Run – Solr searching – j. Query autocomplete

What is Autocomplete in Solr? Solr-1316: Autosuggest https: //issues. apache. org/jira/browse/SOLR-1316 Based on spellcheck

What is Autocomplete in Solr? Solr-1316: Autosuggest https: //issues. apache. org/jira/browse/SOLR-1316 Based on spellcheck http: //wiki. apache. org/solr/Spell. Check. Component Ternary Search Trie http: //www. javaworld. com/javaworld/jw-02 -2001/jw-0216 -ternary. html A Ternary Search Trie is a data structure for storing strings that is ideal for practical use in sorting and searching data. Let's get started!

Find • SOLR-1316 Patches https: //issues. apache. org/jira/browse/SOLR-1316 • Solr/Lucene from Apache http: //svn.

Find • SOLR-1316 Patches https: //issues. apache. org/jira/browse/SOLR-1316 • Solr/Lucene from Apache http: //svn. apache. org/repos/asf/lucene/dev/trunk/ – Trunk has Autosuggest already built in

Find • j. Query http: //jqueryui. com/demos/autocomplete/#remote http: //ajax. googleapis. com/ajax/libs/jquery/1. 4. 2/jquery. js

Find • j. Query http: //jqueryui. com/demos/autocomplete/#remote http: //ajax. googleapis. com/ajax/libs/jquery/1. 4. 2/jquery. js http: //ajax. googleapis. com/ajax/libs/jqueryui/1. 8. 3/ – jquery-ui. js – themes/base/jquery-ui. css http: //dev. jquery. com/view/trunk/plugins/autocomplete/jquery. autocomplete. css

What to Autocomplete? “Who's your data? ”

What to Autocomplete? “Who's your data? ”

What to autocomplete? • What is searchable in the index? • What data is

What to autocomplete? • What is searchable in the index? • What data is useful to autocomplete? • Lets look at the document data

Data, Documents and Fields <doc> <field name="id">SOLR 026</field> <field name="categories">Computers</field> <field name="categories">Solr</field> <field name="categories">Search</field>

Data, Documents and Fields <doc> <field name="id">SOLR 026</field> <field name="categories">Computers</field> <field name="categories">Solr</field> <field name="categories">Search</field> <field name="authors">ASF</field> <field name="description"></field> <field name="average_rating">5. 0</field> <field name="sales_rank">100</field> <field name="title">Solr Enterprise Search</field> </doc>

Configure • schema. xml • solrconfig. xml • URL parameters

Configure • schema. xml • solrconfig. xml • URL parameters

Configure schema. xml • http: //wiki. apache. org/solr/Schema. Xml • Lives in $SOLR_HOME/conf •

Configure schema. xml • http: //wiki. apache. org/solr/Schema. Xml • Lives in $SOLR_HOME/conf • Field Types Defines datatypes, tokenizers and filters. • Fields Defines the fields that are stored in the search index. • Copy Fields Instruction to copy value of one defined field in to another. Autocomplete uses copy. Field(s. )

Configure schema. xml <fields> <field name="authors" type="textgen" indexed="true" stored="true" multi. Valued="true"/> <field name="title" type="textgen"

Configure schema. xml <fields> <field name="authors" type="textgen" indexed="true" stored="true" multi. Valued="true"/> <field name="title" type="textgen" indexed="true" stored="true"/> <field name="categories" type="textgen" indexed="true" stored="true" multi. Valued="true"/> <field name="autocomplete-field" type="string" indexed="true" stored="true" multi. Valued="true"/> </fields>

Configure schema. xml <copy. Field source="authors" dest="autocomplete-field"/> <copy. Field source="title" dest="autocomplete-field"/> <copy. Field source="categories"

Configure schema. xml <copy. Field source="authors" dest="autocomplete-field"/> <copy. Field source="title" dest="autocomplete-field"/> <copy. Field source="categories" dest="autocomplete-field"/>

Configure solrconfig. xml • http: //wiki. apache. org/solr/Solr. Config. Xml • Lives in $SOLR_HOME/conf

Configure solrconfig. xml • http: //wiki. apache. org/solr/Solr. Config. Xml • Lives in $SOLR_HOME/conf • Defines – Index defaults, deletion policy – Update handlers – Caches – Event listeners, e. g. new and first searchers – Request handlers (API) – Search components – Response writers

Configure solrconfig. xml Search Component <search. Component name="spellcheck-autocomplete" class="solr. Spell. Check. Component"> <lst name="spellchecker">

Configure solrconfig. xml Search Component <search. Component name="spellcheck-autocomplete" class="solr. Spell. Check. Component"> <lst name="spellchecker"> <str name="name">suggest</str> <str name="classname"> org. apache. solr. spelling. suggest. Suggester </str> <str name="lookup. Impl"> org. apache. solr. spelling. suggest. jaspell. Jaspell. Lookup </str> <str name="field">autocomplete-field</str> <str name="source. Location">american-english</str> </lst> </search. Component>

Configure solrconfig. xml Request Handler <request. Handler name="/autocomplete" class="solr. Search. Handler"> <arr name="components"> <str>spellcheck-autocomplete</str>

Configure solrconfig. xml Request Handler <request. Handler name="/autocomplete" class="solr. Search. Handler"> <arr name="components"> <str>spellcheck-autocomplete</str> </arr> </request. Handler>

Configure • Autocomplete URL: http: //antikythera 3. local: 8983/solr/autocomplete? spellcheck=true&spellcheck. dicti onary=suggest&spellcheck. extended. Results=true&spellcheck.

Configure • Autocomplete URL: http: //antikythera 3. local: 8983/solr/autocomplete? spellcheck=true&spellcheck. dicti onary=suggest&spellcheck. extended. Results=true&spellcheck. c ount=100&spellcheck. build=true&q=s • Important parameters • spellcheck=true • spellcheck. build=true • spellcheck. dictionary=suggest

Run • • Build and run Solr Add documents Populate autocomplete search component Demonstration

Run • • Build and run Solr Add documents Populate autocomplete search component Demonstration of autocomplete

Configure • HTML • j. Query

Configure • HTML • j. Query

Configure HTML <div class="demo"> <div class="ui-widget-search ui-widget"> Search: <input id="search" class="search. Input"/> </div> <div

Configure HTML <div class="demo"> <div class="ui-widget-search ui-widget"> Search: <input id="search" class="search. Input"/> </div> <div class="ui-widget-results ui-widget"> Results: <div id="results" style="overflow: auto; " class="ui-widget-content"></div>

Configure j. Query autocomplete plugin options $( "#search" ). autocomplete({ min. Length: 1, delay:

Configure j. Query autocomplete plugin options $( "#search" ). autocomplete({ min. Length: 1, delay: 10, source: function(request, response) { – min. Length: min. typed characters – delay: millisecond keystroke delay – source: data to use, can be array, string or callback – disabled

Configure j. Query autocomplete plugin events $( "#search" ). autocomplete({ select: function( event, ui

Configure j. Query autocomplete plugin events $( "#search" ). autocomplete({ select: function( event, ui ), focus: function( event, ui ) Both events add ajax results to #results

Configure • j. Query Cross Site Scripting blocking: – Cross Site Scripting prevention in

Configure • j. Query Cross Site Scripting blocking: – Cross Site Scripting prevention in j. Query includes port! – Test going directly to Solr - will get "Canceled opening the page” – Work around: proxy API for j. Query to Solr

Run • Build and run j. Query Web App & Solr • Add documents

Run • Build and run j. Query Web App & Solr • Add documents • Demonstration of autocomplete

Review • Find – Solr/Lucene project http: //svn. apache. org/repos/asf/lucene/dev/trunk/ – j. Query autocomplete

Review • Find – Solr/Lucene project http: //svn. apache. org/repos/asf/lucene/dev/trunk/ – j. Query autocomplete http: //jqueryui. com/demos/autocomplete/#remote • Configure – schema. xml, solrconfig. xml – j. Query autocomplete plugin – Search API workaround for j. Query • Run – JQuery and Solr

Thank You Questions? Contact me: poakes@lulu. com

Thank You Questions? Contact me: poakes@lulu. com