简体   繁体   中英

sunspot solr displays deleted documents

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

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 :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM