java - How to config SOLR server for spell check functionality -


i want implement spellcheck functionality offered solr using mysql database, don't understand how.
here basic flow of want do.

i have simple inputtext (in jsf) , if type word shwo response outputlabel should show.

first of i'm using following tools , frameworks:

jboss application server 6.1.
eclipse
jpa
jsf(primefaces)

steps i've done until now:

step 1: download solr server from: http://lucene.apache.org/solr/downloads.html extract content.

step 2: add envoierment variable(where have solr server):

solr.solr.home=d:\jboss\solr-4.4.0\solr-4.4.0\example\solr 

step 3:

open solr war , solr.war\web-inf\web.xml add env-entry - (the easy way)

<env-entry>     <env-entry-name>solr/home</env-entry-name>     <env-entry-value>d:\jboss\solr-4.4.0\solr-4.4.0\example\solr</env-entry-value>     <env-entry-type>java.lang.string</env-entry-type> </env-entry> 

or import project change , bulid war.

step 4: browser: localhost:8080/solr/ , solr console appears. until works well.

i have found usefull code (my opinion) returns:

[collection1] webapp=/solr path=/spell params={spellcheck=on&q=whatever&wt=javabin&qt=/spell&version=2&spellcheck.build=true} hits=0 status=0 qtime=16

here code gives result above:

solrserver solr; try {   solr = new commonshttpsolrserver("http://localhost:8080/solr");   modifiablesolrparams params = new modifiablesolrparams();   params.set("qt", "/spell");   params.set("q", "whatever");   params.set("spellcheck", "on");   params.set("spellcheck.build", "true");    queryresponse response = solr.query(params);   spellcheckresponse spellcheckresponse = response.getspellcheckresponse();   if (!spellcheckresponse.iscorrectlyspelled()) {     (suggestion suggestion : spellcheckresponse.getsuggestions()) {       system.out.println("original token: " + suggestion.gettoken() + " - alternatives: " + suggestion.getalternatives());     }   } } catch (exception e) {   // todo auto-generated catch block   e.printstacktrace(); } 

also added in data-config.xml

<?xml version="1.0" encoding="utf-8" ?> <dataconfig>   <datasource type="jdbcdatasource" name="altadict"     driver="com.mysql.jdbc.driver"      url="jdbc:mysql://localhost:3306/myproject"     user="root"     password=""   />    <document name="myproject">     <entity name="myproject" query="select * words">       <field column="id" name="id" />       <field column="cuvint" name="cuvint" />       <field column="traddiac" name="traddiac" />       <field column="explicatie" name="explicatie" />       <field column="tipcuvint" name="tipcuvint" />       <field column="italicparant" name="italicparant" />     </entity>   </document> </dataconfig> 

schema.xml

<field name="id" type="tlong" indexed="true" stored="true" required="true"/> <field name="cuvint" type="string" indexed="true" stored="true" required="true"/> <field name="traddiac" type="string" indexed="true" stored="true" required="true"/> <field name="explicatie" type="string" indexed="true" stored="true"/> <field name="tipcuvint" type="string" indexed="true" stored="true" required="true"/> <field name="italicparant" type="string" indexed="true" stored="true"/> 

solrconfig.xml

<!-- altadict request handler -->  <requesthandler name="/dataimport" class="org.apache.solr.handler.dataimport.dataimporthandler">   <lst name="defaults">     <str name="config">data-config.xml</str>   </lst> </requesthandler>  <requesthandler name="/spell" class="solr.searchhandler" startup="lazy">   <lst name="defaults">     <str name="df">cuvint</str>      <str name="spellcheck.dictionary">default</str>      <str name="spellcheck">on</str>     <str name="spellcheck.extendedresults">true</str>      <str name="spellcheck.count">10</str>     <str name="spellcheck.maxresultsforsuggest">5</str>      <str name="spellcheck.collate">true</str>     <str name="spellcheck.collateextendedresults">true</str>      <str name="spellcheck.maxcollationtries">10</str>     <str name="spellcheck.maxcollations">5</str>    </lst>   <arr name="last-components">     <str>spellcheck</str>   </arr> </requesthandler>  <searchcomponent name="spellcheck" class="solr.spellcheckcomponent">   <str name="queryanalyzerfieldtype">string</str> <!-- replace field type of schema -->   <lst name="spellchecker">     <str name="name">default</str>     <str name="field">examplew</str> <!-- replace field name per scheme -->     <str name="spellcheckindexdir">./spellchecker</str>     <str name="buildonoptimize">true</str>     <str name="buildoncommit">true</str>   </lst>    <!-- spellchecker uses different distance measure -->   <lst name="spellchecker">     <str name="name">jarowinkler</str>      <str name="field">spell</str>     <str name="distancemeasure">org.apache.lucene.search.spell.jarowinklerdistance</str>     <str name="spellcheckindexdir">./spellchecker2</str>   </lst> </searchcomponent> 

and libs

questions:

1.how make database connection whit db , search content see if there words match?
2.how make configuration.(solr-config.xml,shema.xml...etc)?
3.how send string view(xhtml) solr server knows looks for?
4.how correct word cuvine database column, example wodr want solr return word.

i read information solr it's still unclear:

links:main page:
http://lucene.apache.org/solr/

main page tutorial: http://lucene.apache.org/solr/4_4_0/tutorial.html

solr wiki:
http://wiki.apache.org/solr/solrj --- official solrj documentation
http://wiki.apache.org/solr/spellcheckcomponent

solr config: http://wiki.apache.org/solr/solrconfigxml http://www.installationpage.com/solr/solr-configuration-tutorial-schema-solrconfig-xml/ http://wiki.apache.org/solr/schemaxml

stackoverflow proof: solr did mean (spell check component)

solr database integration:
http://www.slideshare.net/th0masr/integrating-the-solr-search-engine
http://www.cabotsolutions.com/2009/05/using-solr-lucene-for-full-text-search-with-mysql-db/

solr spell check:
http://docs.lucidworks.com/display/solr/spell+checking
http://searchhub.org/2010/08/31/getting-started-spell-checking-with-apache-lucene-and-solr/
http://techiesinsight.blogspot.ro/2012/06/using-solr-spellchecker-from-java.html
http://blog.websolr.com/post/2748574298/spellcheck-with-solr-spellcheckcomponent
how use spellingresult class in solrj

i need help.regards.

1.how make database connection db , search content see if there words match?

you need index data mysql solr.
can either done build app read records mysql , feeding data solr.
or answered use data import handler (dih) enable make connection mysql , load data , index solr. also, enable incremental updates

2.how make configuration.(solr-config.xml,shema.xml...etc)?

the field spell checker should marked text analysis.
field marked string there no tokenization.
schema.xml

<field name="cuvint" type="text" indexed="true" stored="true" required="true"/> 

also, solrconfig.xml, replace field want consider spell suggestion

<str name="field">examplew</str> <!-- replace field name per scheme --> 

check example.

3.how send string view(xhtml) solr server knows looks for?

usually, implement feature search , spell suggestion combined in solr request.
when don't results solr, check if spell check suggestion available , display did mean suggestion also, instead of waiting spell suggestion, provide type ahead suggestion user prevents round trip server.

4.how correct word cuvine database column, example wodr want solr return word.

check example configure spell check , should provide suggestion.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -