SolrJ TermsComponent Support

I was working on implementing an auto-complete search box today using Solr 1.4 and the new TermsComponent. TermsComponent is a simple plugin that provides access to Lucene’s term dictionary and is very fast. Being fast and the fact it can hook into a search index makes it perfect for an auto-completion server.

Unfortunately, SolrJ does not support this new functionality yet. Well not officially because you could always parse the raw response object yourself. That is exactly what I was doing until I figured I might as well just add the support to SolrJ. I did, and it was extremely easy.

I added support for TermsComponent parameters and implemented a new TermsComponent response type. The TermsComponent response is parsed into a list of Type objects. The Type object has two methods, getTerm() and getFrequency(). getTerm() returns the suggested term, and getFrequency() returns the frequency of the term appearing in the index.

I have submitted my patch upstream for inclusion into a future version of SolrJ.

Here is the link to the JIRA bug report:
https://issues.apache.org/jira/browse/SOLR-1139

Here is the patch:
https://issues.apache.org/jira/secure/attachment/12407047/SOLR-1139.patch

  1. Great!!! but how can it works in current example Solr 1.3.

    • TermsComponent is not in Solr 1.3. You need to apply this patch to the latest trunk version of Solr 1.4 for this functionality.

  2. It would be really useful if TermsComponent was also available through SolrNet.

    Looks like a mini project for me…

    • Yes, version 0.2.0 supports creating your own results page. Just create a s4w_search.php based on the one included with the plugin. Unfortunately, there are some hardcoded values inside the plugin itself, however, the next version provides a fix for this.

  3. hi Matt,
    I tired to apply your patch SOLR-1139.patch on the solr 1.4 but I got some errors during the operation.
    here what the error generated by the patch command looks like:
    patch -p0 -i SOLR-1139.patch

    can’t find file to patch at input line 5
    Perhaps you used the wrong -p or –strip option?
    The text leading up to this was:
    ————————–
    |Index: CHANGES.txt
    |===================================================================
    |— CHANGES.txt (revision 889975)
    |+++ CHANGES.txt (working copy)
    ————————–
    File to patch:
    Skip this patch? [y] y
    Skipping patch.
    5 out of 5 hunks ignored

    when I use the command patch -p0 -i SOLR-1139.patch

    I get this error:

    patching file CHANGES.txt
    Hunk #1 FAILED at 58.
    1 out of 1 hunk FAILED — saving rejects to file CHANGES.txt.rej
    patching file src/test/org/apache/solr/client/solrj/SolrQueryTest.java
    Hunk #1 FAILED at 143.
    1 out of 1 hunk FAILED — saving rejects to file src/test/org/apache/solr/client/solrj/SolrQueryTest.java.rej
    patching file src/test/org/apache/solr/client/solrj/response/TermsResponseTest.java
    patching file src/solrj/org/apache/solr/client/solrj/SolrQuery.java
    Hunk #1 FAILED at 22.
    Hunk #2 FAILED at 55.
    2 out of 2 hunks FAILED — saving rejects to file src/solrj/org/apache/solr/client/solrj/SolrQuery.java.rej
    patching file src/solrj/org/apache/solr/client/solrj/response/QueryResponse.java
    Hunk #1 FAILED at 46.
    Hunk #2 FAILED at 60.
    Hunk #3 FAILED at 122.
    Hunk #4 FAILED at 133.
    Hunk #5 FAILED at 288.
    5 out of 5 hunks FAILED — saving rejects to file src/solrj/org/apache/solr/client/solrj/response/QueryResponse.java.rej
    patching file src/solrj/org/apache/solr/client/solrj/response/TermsResponse.java

    can you help me please solve this problem?
    PS: I’m using ubuntu 9.10

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>