First, your solrconfig.xml should have the something similar to the
following:
<searchComponent name="termsComp"
class="org.apache.solr.handler.component.TermsComponent"/>
<requestHandler name="/autoSuggest"
class="org.apache.solr.handler.component.SearchHandler">
<arr name="components">
<str>termsComp</str>
</arr>
</requestHandler>
This will give you a request handler called "/autoSuggest" that you
will use for suggestions.
Then you need to write some rails code to access this. I am not very
familiar with ruby, but I believe you might want to try http://wiki.apache.org/solr/solr-ruby
. Make sure you set your query type to "/autoSuggest". If that won't
work for you, then just use the standard http libraries to access the
autoSuggest url directly and get json output.
With any of these methods make sure you set the following parameters:
terms=true
terms.fl=source_field
terms.lower=input_term
terms.prefix=input_term
terms.lower.incl=false
For direct access to the json output you will want these as well:
indent=true
wt=json
The terms.fl parameter specifys the field(s) you want to use as the
source for suggestions. Make sure this field has very little
processing done on it, maybe lowercasing and tokenization only.
Here is an example url that should give you some output once things
are working:
http://localhost:8983/solr/autoSuggest?terms=true&terms.fl=spell&terms.lower=t&terms.prefix=t&terms.lower.incl=false&indent=true&wt=json
The next thing is to parse the json output and do whatever you want
with the results. In my example, I just printed out each suggestion
on a single line of the response because this is what the jQuery
autocomplete plugin wanted. The easiest way to parse the json output
is to use the json ruby library, http://json.rubyforge.org/.
After you have your rails controller working you can hook it into your
FE with some javascript like I did in the example on my blog. Hope
this helps.
Thanks,
Matt Weber
eSr Technologies
http://www.esr-technologies.com
On May 7, 2009, at 7:37 AM, manisha_5 wrote:
Thanks a lot for the information. But I am still a bit confused
about the use
of TermsComponents. Like where are we exactly going to put these
codes in
Solr.For example I changed schema.xml to add autocomplete feauture.I
read
your blog too, its very helpful.But still a little confused. :-((
Can you explain it a bit?
Matt Weber-2 wrote:
You will probably want to use the new TermsComponent in Solr 1.4.
See
http://wiki.apache.org/solr/TermsComponent
. I just recently wrote a blog post about using autocompletion with
TermsComponent, a servlet, and jQuery. You can probably follow these
instructions, but instead of writing a servlet you can write a rails
handler parsing the json output directly.
http://www.mattweber.org/2009/05/02/solr-autosuggest-with-termscomponent-and-jquery/
.
Thanks,
Matt Weber
On May 4, 2009, at 9:39 AM, manisha_5 wrote:
Hi,
I am new to solr. I am using solr server to index the data and make
search
in a Ruby on rails project.I want to add autocompletion feature. I
tried
with the xml patch in the schema.xml file of solr, but dont know how
to test
if the feature is working.also havent been able to integrate the
same in the
Rails project that is using Solr.Can anyone please provide some help
in this
regards??
the patch of codes in Schema.xml is :
<fieldType name="autocomplete" class="solr.TextField">
<analyzer type="index">
<tokenizer class="solr.NGramTokenizerFactory"
minGramSize="3"
maxGramSize="15" />
<filter class="solr.LowerCaseFilterFactory" />
<filter class="solr.PatternReplaceFilterFactory"
pattern="([^a-z0-9])" replacement="" replace="all" />
<filter class="solr.EdgeNGramFilterFactory"
maxGramSize="100"
minGramSize="1" />
</analyzer>
<analyzer type="query">
<tokenizer class="solr.WhitespaceTokenizerFactory"/>
<filter class="solr.LowerCaseFilterFactory" />
<filter class="solr.PatternReplaceFilterFactory"
pattern="([^a-z0-9])" replacement="" replace="all" />
<filter class="solr.PatternReplaceFilterFactory"
pattern="^(.{20})(.*)?" replacement="$1" replace="all" />
</analyzer>
</fieldType>
--
View this message in context:
http://www.nabble.com/Solr-autocompletion-in-rails-tp23372020p23372020.html
Sent from the Solr - User mailing list archive at Nabble.com.
--
View this message in context:
http://www.nabble.com/Solr-autocompletion-in-rails-tp23372020p23428267.html
Sent from the Solr - User mailing list archive at Nabble.com.