Autocomplete with Solr TermsComponent and RSolr

If you’re already familiar with the basics and just looking for some sample code, here you go!

  rsolr = RSolr.connect :url => ''
  rsolr.get 'terms', :params => { 'terms.fl' => '', 'terms.prefix' => '' }

Installing and using RSolr

Please refer to our article on RSolr for a more comprehensive look at general RSolr usage.

TermsComponent basics

TermsComponent bases its responses on the contents of a field which you specify. This can be a specific field,

If you use dynamic field naming conventions you could also copy all of your text fields into a single text field.

<?xml version="1.0" encoding="UTF-8"?>

    <fieldType name="text" class="solr.TextField">
      <!-- the rest of your definition for a typical text field goes here -->

    <!-- other field types omitted for brevity -->


    <!-- other fields omitted for brevity -->

    <field name="*_text" type="text" indexed="true" stored="false" multiValued="true" />
    <field name="allText" type="text" indexed="true" stored="false" multiValued="true" />


    Copy each of the text fields into allText for use by TermsComponent,
    SpellcheckComponent, and others.
  <copyField source="*_text" dest="allText"/>


Interacting with TermsComponent

rsolr = RSolr.connect :url => ''
rsolr.get 'terms', :params => { 'terms.fl' => '', 'terms.prefix' => '' }