title: How to config SOLR server for spell check functionality
body: <p>I want to implement spellcheck functionality offered by Solr using MySql database, but I don't understand how.<br>
  Here the basic flow of what I want to do.</p>
  
  <p>I have a simple inputText (in JSF) and if I type the word <strong>shwo</strong> the response to OutputLabel should be <strong>show</strong>.</p>
  
  <p>First of all I'm using the following tools and frameworks:   </p>
  
  <p>JBoss application server 6.1.<br>
  Eclipse<br>
  JPA<br>
  JSF(Primefaces)</p>
  
  <p><strong>Steps I've done until now:</strong></p>
  
  <p><strong>Step 1:</strong>
     Download Solr server from: <a href="http://lucene.apache.org/solr/downloads.html" rel="nofollow noreferrer">http://lucene.apache.org/solr/downloads.html</a>
     Extract content.</p>
  
  <p><strong>Step 2:</strong>
     Add to Envoierment variable(where you have the solr server):</p>
  
  <pre><code>solr.solr.home=D:\JBOSS\solr-4.4.0\solr-4.4.0\example\solr
  </code></pre>
  
  <p><strong>Step 3:</strong></p>
  
  <p>Open solr war and to solr.war\WEB-INF\web.xml add env-entry - (the easy way)</p>
  
  <pre><code>&lt;env-entry&gt;
      &lt;env-entry-name&gt;solr/home&lt;/env-entry-name&gt;
      &lt;env-entry-value&gt;D:\JBOSS\solr-4.4.0\solr-4.4.0\example\solr&lt;/env-entry-value&gt;
      &lt;env-entry-type&gt;java.lang.String&lt;/env-entry-type&gt;
  &lt;/env-entry&gt;
  </code></pre>
  
  <p>OR import project change and bulid war.</p>
  
  <p><strong>Step 4:</strong>
  Browser: <code>localhost:8080/solr/</code>
  And the solr console appears.
  Until now all works well.</p>
  
  <p>I have found some usefull code (my opinion) that returns:</p>
  
  <blockquote>
    <p>[collection1] webapp=/solr path=/spell
    params={spellcheck=on&amp;q=whatever&amp;wt=javabin&amp;qt=/spell&amp;version=2&amp;spellcheck.build=true}
    hits=0 status=0 QTime=16</p>
  </blockquote>
  
  <p>Here is the code that gives the result from above:</p>
  
  <pre><code>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()) {
      for (Suggestion suggestion : spellCheckResponse.getSuggestions()) {
        System.out.println("original token: " + suggestion.getToken() + " - alternatives: " + suggestion.getAlternatives());
      }
    }
  } catch (Exception e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
  }
  </code></pre>
  
  <p>Also I added in data-config.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" ?&gt;
  &lt;dataConfig&gt;
    &lt;dataSource type="JdbcDataSource" name="altadict"
      driver="com.mysql.jdbc.Driver" 
      url="jdbc:mysql://localhost:3306/myproject"
      user="root"
      password=""
    /&gt;
  
    &lt;document name="myproject"&gt;
      &lt;entity name="myproject" query="SELECT * FROM words"&gt;
        &lt;field column="Id" name="Id" /&gt;
        &lt;field column="Cuvint" name="Cuvint" /&gt;
        &lt;field column="TradDiac" name="TradDiac" /&gt;
        &lt;field column="Explicatie" name="Explicatie" /&gt;
        &lt;field column="TipCuvint" name="TipCuvint" /&gt;
        &lt;field column="ItalicParant" name="ItalicParant" /&gt;
      &lt;/entity&gt;
    &lt;/document&gt;
  &lt;/dataConfig&gt;
  </code></pre>
  
  <p>schema.xml</p>
  
  <pre><code>&lt;field name="Id" type="tlong" indexed="true" stored="true" required="true"/&gt;
  &lt;field name="Cuvint" type="string" indexed="true" stored="true" required="true"/&gt;
  &lt;field name="TradDiac" type="string" indexed="true" stored="true" required="true"/&gt;
  &lt;field name="Explicatie" type="string" indexed="true" stored="true"/&gt;
  &lt;field name="TipCuvint" type="string" indexed="true" stored="true" required="true"/&gt;
  &lt;field name="ItalicParant" type="string" indexed="true" stored="true"/&gt;
  </code></pre>
  
  <p>solrconfig.xml</p>
  
  <pre><code>&lt;!-- altadict Request Handler --&gt;
  
  &lt;requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler"&gt;
    &lt;lst name="defaults"&gt;
      &lt;str name="config"&gt;data-config.xml&lt;/str&gt;
    &lt;/lst&gt;
  &lt;/requestHandler&gt;
  
  &lt;requestHandler name="/spell" class="solr.SearchHandler" startup="lazy"&gt;
    &lt;lst name="defaults"&gt;
      &lt;str name="df"&gt;Cuvint&lt;/str&gt; 
      &lt;str name="spellcheck.dictionary"&gt;default&lt;/str&gt; 
      &lt;str name="spellcheck"&gt;on&lt;/str&gt;
      &lt;str name="spellcheck.extendedResults"&gt;true&lt;/str&gt; 
      &lt;str name="spellcheck.count"&gt;10&lt;/str&gt;
      &lt;str name="spellcheck.maxResultsForSuggest"&gt;5&lt;/str&gt; 
      &lt;str name="spellcheck.collate"&gt;true&lt;/str&gt;
      &lt;str name="spellcheck.collateExtendedResults"&gt;true&lt;/str&gt; 
      &lt;str name="spellcheck.maxCollationTries"&gt;10&lt;/str&gt;
      &lt;str name="spellcheck.maxCollations"&gt;5&lt;/str&gt; 
    &lt;/lst&gt;
    &lt;arr name="last-components"&gt;
      &lt;str&gt;spellcheck&lt;/str&gt;
    &lt;/arr&gt;
  &lt;/requestHandler&gt;
  
  &lt;searchComponent name="spellcheck" class="solr.SpellCheckComponent"&gt;
    &lt;str name="queryAnalyzerFieldType"&gt;string&lt;/str&gt; &lt;!-- Replace with Field Type of your schema --&gt;
    &lt;lst name="spellchecker"&gt;
      &lt;str name="name"&gt;default&lt;/str&gt;
      &lt;str name="field"&gt;examplew&lt;/str&gt; &lt;!-- Replace with field name as per your scheme --&gt;
      &lt;str name="spellcheckIndexDir"&gt;./spellchecker&lt;/str&gt;
      &lt;str name="buildOnOptimize"&gt;true&lt;/str&gt;
      &lt;str name="buildOnCommit"&gt;true&lt;/str&gt;
    &lt;/lst&gt;
  
    &lt;!-- a spellchecker that uses a different distance measure --&gt;
    &lt;lst name="spellchecker"&gt;
      &lt;str name="name"&gt;jarowinkler&lt;/str&gt; 
      &lt;str name="field"&gt;spell&lt;/str&gt;
      &lt;str name="distanceMeasure"&gt;org.apache.lucene.search.spell.JaroWinklerDistance&lt;/str&gt;
      &lt;str name="spellcheckIndexDir"&gt;./spellchecker2&lt;/str&gt;
    &lt;/lst&gt;
  &lt;/searchComponent&gt;
  </code></pre>
  
  <p>and libs</p>
  
  <p>
   
   </p>
  
  <p><strong>Questions:</strong></p>
  
  <p>1.How do I make the database connection whit my DB and search the content to see if there are any words that could match?<br>
  2.How do I make the configuration.(solr-config.xml,shema.xml...etc)?<br>
  3.How do I send a string from my view(xhtml) so that the solr server knows what he looks for?<br>
  4.How do I get the correct word from Cuvine database column, for example <strong>wodr</strong> I want solr to return <strong>word</strong>.</p>
  
  <p>I read all the information about solr but it's still unclear:</p>
  
  <p>Links:Main Page:<br>
  <a href="http://lucene.apache.org/solr/" rel="nofollow noreferrer">http://lucene.apache.org/solr/</a></p>
  
  <p>Main Page tutorial:
  <a href="http://lucene.apache.org/solr/4_4_0/tutorial.html" rel="nofollow noreferrer">http://lucene.apache.org/solr/4_4_0/tutorial.html</a></p>
  
  <p>Solr Wiki:<br>
  <a href="http://wiki.apache.org/solr/Solrj" rel="nofollow noreferrer">http://wiki.apache.org/solr/Solrj</a>   --- official solrj documentation<br>
  <a href="http://wiki.apache.org/solr/SpellCheckComponent" rel="nofollow noreferrer">http://wiki.apache.org/solr/SpellCheckComponent</a>    </p>
  
  <p>Solr config:
  <a href="http://wiki.apache.org/solr/SolrConfigXml" rel="nofollow noreferrer">http://wiki.apache.org/solr/SolrConfigXml</a>
  <a href="http://www.installationpage.com/solr/solr-configuration-tutorial-schema-solrconfig-xml/" rel="nofollow noreferrer">http://www.installationpage.com/solr/solr-configuration-tutorial-schema-solrconfig-xml/</a>
  <a href="http://wiki.apache.org/solr/SchemaXml" rel="nofollow noreferrer">http://wiki.apache.org/solr/SchemaXml</a></p>
  
  <p>StackOverflow proof:
  <a href="https://stackoverflow.com/questions/9498022/solr-did-you-mean-spell-check-component">Solr Did you mean (Spell check component)</a></p>
  
  <p>Solr Database Integration:<br>
  <a href="http://www.slideshare.net/th0masr/integrating-the-solr-search-engine" rel="nofollow noreferrer">http://www.slideshare.net/th0masr/integrating-the-solr-search-engine</a><br>
  <a href="http://www.cabotsolutions.com/2009/05/using-solr-lucene-for-full-text-search-with-mysql-db/" rel="nofollow noreferrer">http://www.cabotsolutions.com/2009/05/using-solr-lucene-for-full-text-search-with-mysql-db/</a>      </p>
  
  <p>Solr Spell Check:<br>
  <a href="http://docs.lucidworks.com/display/solr/Spell+Checking" rel="nofollow noreferrer">http://docs.lucidworks.com/display/solr/Spell+Checking</a><br>
  <a href="http://searchhub.org/2010/08/31/getting-started-spell-checking-with-apache-lucene-and-solr/" rel="nofollow noreferrer">http://searchhub.org/2010/08/31/getting-started-spell-checking-with-apache-lucene-and-solr/</a><br>
  <a href="http://techiesinsight.blogspot.ro/2012/06/using-solr-spellchecker-from-java.html" rel="nofollow noreferrer">http://techiesinsight.blogspot.ro/2012/06/using-solr-spellchecker-from-java.html</a><br>
  <a href="http://blog.websolr.com/post/2748574298/spellcheck-with-solr-spellcheckcomponent" rel="nofollow noreferrer">http://blog.websolr.com/post/2748574298/spellcheck-with-solr-spellcheckcomponent</a><br>
  <a href="https://stackoverflow.com/questions/6466626/how-to-use-spellingresult-class-in-solrj">How to use SpellingResult class in SolrJ</a></p>
  
  <p>I really need your help.Regards.</p>