0
votes

I'm using sunspot solr in the Ruby-on-Rails application with Postgres as a database. When I update a field in the table and search for results with solr it can find old index data. For example, I changed the field from “Test 1” to “Test 2” and solr can find a document with “Test 1” query, but displays it as “Test 2”, also it can find “Test 2”. As I understand solr while updating document should perform delete and add operations and should skip all deleted documents but in my case deleted documents still display during requests.

Below is code snippet:

class Position < ActiveRecord::Base
........

searchable ignore_attribute_changes_of: [ :sha1hash ] do

    text :title

    text :description

    text :account_location do
      account.address.entire_address if account.address
    end

    text :account_name do
      account.name
    end

   string :title

............
end

def search_index()

..............
Position.search(include: [{ account: :address }]) do |query|
        query.without(:private, true)
        query.with(:unconfirmed_account, false)
        query.with(:account_name, params[:name]) if params[:name].present?
        query.with(:title, params[:title]) if params[:title].present?


    ..............
        query.paginate per_page: per_page, page: [params[:page].to_i, 1].max

      end

end

For example, if I changed a title field from "Test 1" to "Test 2" I can still find document with "Test 1" title.

Thanks very much for your help and advice

1
Please share your code snippet. - Pirate X
Do you see a delete issued if you delete a document? Does the documents in Solr have different ids? If you retrieve the document from Solr when searching for "Test 1" - does it actually contain "Test 1"? (it's possible it's being retrieved for just the hit for Test, depending on the query operator). - MatsLindh
I don't delete document, I update it. I think documents have the same id from database. When I retrieve documents from Solr it actually contain "Test 2". - Alex Medvedev

1 Answers

0
votes

I found the issue. It was configuration for case-insensitive search for string field in schema.xml file:

    <fieldType name="string" class="solr.TextField" omitNorms="true">
      <analyzer type="query">
        <tokenizer class="solr.StandardTokenizerFactory"/>
        <filter class="solr.LowerCaseFilterFactory"/>
      </analyzer>
    </fieldType>

The question is still open: how to get case-insensitive search and avoid such issues with update document :)