Abram
Abram

Reputation: 41884

Changing SOLR schema.xml has no effect using 'sunspot_rails' gem

I am attempting to search partial words in my rails app using SOLR. This requires a change to the schema.xml file. As suggested by others, I have updated my "app_root/solr/conf/schema.xml" file to remove

<fieldType name="text" class="solr.TextField" omitNorms="false">
  <analyzer>
    <tokenizer class="solr.StandardTokenizerFactory"/>
    <filter class="solr.StandardFilterFactory"/>
    <filter class="solr.LowerCaseFilterFactory"/>
  </analyzer>
</fieldType>

and add ...

<fieldType name="text" class="solr.TextField" omitNorms="false">
    <analyzer type="index">
        <tokenizer class="solr.StandardTokenizerFactory"/>
        <filter class="solr.StandardFilterFactory"/>
        <filter class="solr.LowerCaseFilterFactory"/>
        <filter class="solr.NGramFilterFactory" minGramSize="1" maxGramSize="15" />
    </analyzer>
    <analyzer type="query">
        <tokenizer class="solr.StandardTokenizerFactory"/>
        <filter class="solr.StandardFilterFactory"/>
        <filter class="solr.LowerCaseFilterFactory"/>
    </analyzer>
</fieldType>

After making these changes I run the rake command rake sunspot:reindex and get 100% complete re-index result. Then I start my server... However, I am still receiving a response back only for full words, and not word partials.

Just in case it matters, here is the relevant code from my Style model:

  searchable do
    text :full_name 
    #full_name is just one of Style's attribute columns
  end

and the code doing the fetch...

if params[:sSearch].present?
  @search = Style.search do 
    fulltext params[:sSearch]
  end
  styles = @search.results
end

Any help would be greatly appreciated.

For references see:

https://github.com/sunspot/sunspot/blob/master/README.md

http://wiki.apache.org/solr/AnalyzersTokenizersTokenFilters#solr.EdgeNGramFilterFactory

Upvotes: 2

Views: 1129

Answers (4)

pthamm
pthamm

Reputation: 1841

I was running into a similar issue and the solution is to restart your solr instance and run the reindex with bundle exec rake not just rake:

$ bundle exec rake sunspot:solr:stop 
$ bundle exec rake sunspot:solr:start 
$ bundle exec rake sunspot:reindex

Upvotes: 3

DavidMann10k
DavidMann10k

Reputation: 563

Unless something has changed in a version since sunspot_solr-2.1.1 the problem is that Solr isn't reading the schema.xml that is copied into the [rails_root]/solr directory. It's reading the schema.xml located with the gem files (roughly here: /gems/sunspot_solr-2.1.1/solr/solr/conf/schema.xml).

I was able to verify this by making a change to that file, restarting the server, and checking the schema in the solr admin interface.

It works this same way on my mac and on a virtual box I use (Ubuntu 14.04 LTS - Trusty Tahr).

The (band-aid) solution is to edit and use the file there. Back it up first, though.

Upvotes: 2

Ravi
Ravi

Reputation: 873

Which version of Solr are you running? I ran into a similar issue while using Solr 4, it shows that the schema is updated once the Solr Server is restarted, but the indexes doesn't change as per the Schema. After spending a lot of time restarting and re-indexing, I created a new core (a new collection) with the updated configuration, and that worked for me.

So, try creating a complete new core, and see if that helps. Good luck!

Upvotes: 1

Alexandre Rafalovitch
Alexandre Rafalovitch

Reputation: 9789

If you are using Solr 4, your best bet to troubleshoot this is to go into Analyze window in the admin interface and run some test strings against your index and query interface. You can either select any of the fields with the 'text' type or the type itself in the dropdown.

On your specific setting, you seem to be saying that for every word you want to match it for any starting subset of it from 1 leading character (really?) to 15. So if somebody searches for 'a', you will get all words starting from 'a'. Is that what you want?

Try this all out before you are trying to troubleshoot the sunspot part.

Upvotes: 0

Related Questions