简体   繁体   English

太阳黑子solr显示已删除的文档

[英]sunspot solr displays deleted documents

I'm using sunspot solr in the Ruby-on-Rails application with Postgres as a database. 我在Ruby-on-Rails应用程序中使用sunspot solr,并将Postgres作为数据库。 When I update a field in the table and search for results with solr it can find old index data. 当我更新表中的字段并使用solr搜索结果时,它可以找到旧的索引数据。 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”. 例如,我将字段从“测试1”更改为“测试2”,solr可以使用“测试1”查询来查找文档,但将其显示为“测试2”,也可以找到“测试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. 据我了解,solr在更新文档时应执行删除和添加操作,并应跳过所有已删除的文档,但是在我的情况下,在请求期间仍显示已删除的文档。

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. 例如,如果我将标题字段从“测试1”更改为“测试2”,我仍然可以找到带有“测试1”标题的文档。

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: 这是对schema.xml文件中的字符串字段进行区分大小写搜索的配置:

    <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 :) 问题仍然悬而未决:如何进行不区分大小写的搜索,并避免在更新文档中出现此类问题:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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