Solr:删除的记录重新出现在索引

时间:2016-10-06 11:45:50

标签: solr lucene spring-data-solr

  • 我创建了一个使用Solr的CRUD应用程序,用于搜索记录,弹簧solr数据用于与Solr交互。
  • 当应用程序启动时,我将数据添加到solr索引。 启动后,我通过Spring SolrCrudRepository
  • 从索引中删除记录
  • 以下是存储库的代码

     public interface SolrRentRepository extends SolrCrudRepository<SolrRent, String> {
    
          SolrRent findById(String id, Sort sort);    
          List<SolrRent> findAll(Sort sort);
    }
    
  • 以下是用于删除solr文档的delete函数

    public void unindexRent(Rent rent) {
       if (rent == null || rent.getId() == null) {
          LOGGER.error("Invalid Rent object to unindex : " + String.valueOf(rent));
          throw new RentsException("Invalid Rent object to unindex : " + String.valueOf(rent));
      }
      rentRepository.delete(rent.getId());
      LOGGER.info("Unindexed rent : " + rent);
    }
    
  • 搜索索引时删除后,将显示已删除的记录。

  • 如果我使用该应用程序插入记录并在此之后立即将其删除,则该记录不会再出现在索引中。

  • 以下是我试图删除的solr文档。

    public class SolrRent {
    
      @Field
      private String id;    
      @Field
      private String city;    
      @Field
      private String province;    
      @Field
      private String country;    
      @Field
      private String type;    
      @Field(value = "airCondition")
      private boolean hasAirCondition;    
      @Field(value = "garden")
      private boolean hasGarden;    
      @Field(value = "pool")
      private boolean hasPool;    
      @Field
      private boolean closeToBeach;    
      @Field
      private double dailyPrice;    
      @Field
      private int roomsNumber;    
      @Field
      private Date lastModified;
    
      // getters & setters
    }
    
  • Solr schema.xml

    <?xml version="1.0" encoding="UTF-8" ?>
    <schema name="rents" version="1.5">
        <types>
            <fieldType name="string" class="solr.TextField" sortMissingLast="true">
                <analyzer>
                    <tokenizer class="solr.KeywordTokenizerFactory"/>
                    <filter class="solr.LowerCaseFilterFactory"/>
                </analyzer>
            </fieldType>
            <fieldType name="boolean" class="solr.BoolField" />
            <fieldType name="double" class="solr.TrieDoubleField" sortMissingLast="true"/>
            <fieldType name="int" class="solr.TrieIntField" sortMissingLast="true"/>
            <fieldType name="date" class="solr.TrieDateField" precisionStep="0" positionIncrementGap="0"/>
        </types>
    
        <fields>
            <field name="id" type="string" indexed="true" stored="true" required="true"/>
            <field name="city" type="string" indexed="true" stored="true" required="true"/>
            <field name="province" type="string" indexed="true" stored="true" required="true"/>
            <field name="country" type="string" indexed="true" stored="true" required="true"/>
            <field name="type" type="string" indexed="true" stored="true" required="true"/>
            <field name="signatureField" type="string" stored="true" indexed="true" multiValued="false" />
    
            <field name="airCondition" type="boolean" indexed="true" required="true"/>
            <field name="garden" type="boolean" indexed="true" required="true"/>
            <field name="pool" type="boolean" indexed="true" required="true"/>
            <field name="closeToBeach" type="boolean" indexed="true" required="true"/>
    
            <field name="dailyPrice" type="double" indexed="true" stored="true" required="true"/>
    
            <field name="roomsNumber" type="int" indexed="true" stored="true" required="true"/>
    
            <field name="lastModified" type="date" indexed="true" stored="true" required="true"/>
    
    
            <defaultSearchField>type</defaultSearchField>
        </fields>
    
        <uniqueKey>id</uniqueKey>
    </schema>
    
    • solrconfig.xml中

    LUCENE_48     数据                             本地人          

<updateRequestProcessorChain name="deDupChain">
    <processor class="solr.processor.SignatureUpdateProcessorFactory">
        <bool name="enabled">true</bool>
        <str name="signatureField">signatureField</str>
        <bool name="overwriteDupes">true</bool>
        <str name="fields">id</str>
        <str name="signatureClass">solr.processor.Lookup3Signature</str>
    </processor>
    <processor class="solr.LogUpdateProcessorFactory" />
    <processor class="solr.RunUpdateProcessorFactory" />
</updateRequestProcessorChain>

<query>
    <maxBooleanClauses>1024</maxBooleanClauses>
    <filterCache class="solr.FastLRUCache" size="512" initialSize="512" autowarmCount="0" />
    <queryResultCache class="solr.LRUCache" size="512" initialSize="512" autowarmCount="0" />
    <documentCache class="solr.LRUCache" size="512" initialSize="512" autowarmCount="0" />
    <enableLazyFieldLoading>true</enableLazyFieldLoading>
    <queryResultWindowSize>20</queryResultWindowSize>
    <queryResultMaxDocsCached>200</queryResultMaxDocsCached>
    <useColdSearcher>false</useColdSearcher>
    <maxWarmingSearchers>2</maxWarmingSearchers>
</query>
<requestDispatcher handleSelect="false">
    <requestParsers enableRemoteStreaming="true" multipartUploadLimitInKB="2048000" formdataUploadLimitInKB="2048" />
    <httpCaching never304="true" />
</requestDispatcher>
<requestHandler name="/select" class="solr.SearchHandler" default="true">
    <lst name="defaults">
        <str name="sort">title asc</str>
        <str name="echoParams">explicit</str>
        <int name="rows">10</int>
        <str name="q">*:*</str>
        <bool name="facet">false</bool>
    </lst>
</requestHandler>

<requestHandler name="/update" class="solr.UpdateRequestHandler" >
    <lst name="defaults">
        <str name="update.chain">deDupChain</str>
    </lst>
</requestHandler>

<requestHandler name="/analysis/field" startup="lazy" class="solr.FieldAnalysisRequestHandler" />
<requestHandler name="/analysis/document" class="solr.DocumentAnalysisRequestHandler" startup="lazy" />
<requestHandler name="/admin/" class="solr.admin.AdminHandlers" />
<requestHandler name="/admin/ping" class="solr.PingRequestHandler">
    <lst name="invariants">
        <str name="q">*:*</str>
    </lst>
    <lst name="defaults">
        <str name="echoParams">all</str>
    </lst>
</requestHandler>
<admin>
    <defaultQuery>*:*</defaultQuery>
</admin>

  • pastebin link代表schema.xmlsolrconfig.xml个文件
  • Solr版本: 4.10.4

修改

  • 插入/删除记录后未发出手动提交。
  • 下面是我通过正在运行的应用程序插入记录,搜索并立即删除它时获得的solr日志。
  

196228 [qtp1856056345-12] INFO   org.apache.solr.update.processor.LogUpdateProcessor - [collection1]   webapp = / solr path = / update params = {wt = javabin&amp; version = 2}   {delete = [31b31c84-9e91-45cc-9b41-f22facbf8157]} 0 1 196235   [qtp1856056345-12] INFO org.apache.solr.update.UpdateHandler - start   提交{,优化=假,openSearcher =真,waitSearcher =真,expungeDeletes =假,softCommit =假,prepareCommit = FALSE}   197794 [qtp1856056345-12] INFO org.apache.solr.core.SolrCore -   SolrDeletionPolicy.onCommit:提交:num = 2     承诺{DIR = NRTCachingDirectory(MMapDirectory@/home/tharindu/Documents/apps/solr-4.10.4/example/solr/collection1/data/index   lockFactory=NativeFSLockFactory@/home/tharindu/Documents/apps/solr-4.10.4/example/solr/collection1/data/index;   maxCacheMB = 48.0 maxMergeSizeMB = 4.0),segFN = segments_d,generation = 13}     承诺{DIR = NRTCachingDirectory(MMapDirectory@/home/tharindu/Documents/apps/solr-4.10.4/example/solr/collection1/data/index   lockFactory=NativeFSLockFactory@/home/tharindu/Documents/apps/solr-4.10.4/example/solr/collection1/data/index;   maxCacheMB = 48.0 maxMergeSizeMB = 4.0),segFN = segments_e,generation = 14}   197795 [qtp1856056345-12] INFO org.apache.solr.core.SolrCore -   最新提交生成= 14 197796 [qtp1856056345-12]信息   org.apache.solr.search.SolrIndexSearcher - 开幕   Searcher @ 5fcf2379 [collection1]主要197797 [qtp1856056345-12] INFO   org.apache.solr.update.UpdateHandler - end_commit_flush 197797   [searcherExecutor-6-thread-1] INFO org.apache.solr.core.SolrCore -   [collection1]注册新搜索者搜索者@ 5fcf2379 [collection1]   main {StandardDirectoryReader(segments_1:31:nrt _a(4.10.4):C10)} 197800   [qtp1856056345-12]信息   org.apache.solr.update.processor.LogUpdateProcessor - [collection1]   webapp = / solr path = / update   params = {waitSearcher = true&amp; commit = true&amp; softCommit = false&amp; wt = javabin&amp; version = 2} {commit =} 0 1565 203103 [qtp1856056345-12] INFO   org.apache.solr.core.SolrCore - UnInverted多值字段   {字段=类型,MEMSIZE = 4476,tindexSize = 48,时间= 0,相位1 = 0,nTerms = 5,bigTerms = 1,termInstances = 7,使用= 0}   203104 [qtp1856056345-12] INFO org.apache.solr.core.SolrCore -   [collection1] webapp = / solr path = / select   PARAMS = {Q =城市:巴杜拉的+和+国家(的斯里兰卡 + 斯里兰卡的)+和+省:乌瓦&安培; facet.limit = 10安培; facet.field =类型&安培;排序=城市+ ASC&安培; facet.mincount = 1&安培;小面=真安培;重量= javabin&安培;版本= 2}   hits = 0 status = 0 QTime = 18

  • 当我尝试搜索并删除我在启动时添加的记录时,下面是solr日志。
  

378758 [qtp1856056345-13] INFO org.apache.solr.core.SolrCore -   [collection1] webapp = / solr path = / select   PARAMS = {Q =城市: city66 &安培; facet.limit = 10安培; facet.field =类型&安培;排序=城市+ ASC&安培; facet.mincount = 1&安培;小面=真安培;重量= javabin&安培;版本= 2}   hits = 2 status = 0 QTime = 6 383571 [qtp1856056345-13] INFO   org.apache.solr.update.processor.LogUpdateProcessor - [collection1]   webapp = / solr path = / update params = {wt = javabin&amp; version = 2}   {delete = [zZC8U]} 0 1 383578 [qtp1856056345-13] INFO   org.apache.solr.update.UpdateHandler - 开始   提交{,优化=假,openSearcher =真,waitSearcher =真,expungeDeletes =假,softCommit =假,prepareCommit = FALSE}   383745 [qtp1856056345-13] INFO org.apache.solr.core.SolrCore -   SolrDeletionPolicy.onCommit:提交:num = 2     承诺{DIR = NRTCachingDirectory(MMapDirectory@/home/tharindu/Documents/apps/solr-4.10.4/example/solr/collection1/data/index   lockFactory=NativeFSLockFactory@/home/tharindu/Documents/apps/solr-4.10.4/example/solr/collection1/data/index;   maxCacheMB = 48.0 maxMergeSizeMB = 4.0),segFN = segments_e,generation = 14}     承诺{DIR = NRTCachingDirectory(MMapDirectory@/home/tharindu/Documents/apps/solr-4.10.4/example/solr/collection1/data/index   lockFactory=NativeFSLockFactory@/home/tharindu/Documents/apps/solr-4.10.4/example/solr/collection1/data/index;   maxCacheMB = 48.0 maxMergeSizeMB = 4.0),segFN = segments_f,generation = 15}   383745 [qtp1856056345-13] INFO org.apache.solr.core.SolrCore -   最新提交生成= 15 383747 [qtp1856056345-13]信息   org.apache.solr.core.SolrCore - SolrIndexSearcher没有改变 -   不重新开放:org.apache.solr.search.SolrIndexSearcher 383747   [qtp1856056345-13] INFO org.apache.solr.update.UpdateHandler -   end_commit_flush 383747 [qtp1856056345-13]信息   org.apache.solr.update.processor.LogUpdateProcessor - [collection1]   webapp = / solr path = / update   params = {waitSearcher = true&amp; commit = true&amp; softCommit = false&amp; wt = javabin&amp; version = 2} {commit =} 0 170 389109 [qtp1856056345-13] INFO   org.apache.solr.core.SolrCore - [collection1] webapp = / solr   路径= /选择   PARAMS = {Q =城市: city66 &安培; facet.limit = 10安培; facet.field =类型&安培;排序=城市+ ASC&安培; facet.mincount = 1&安培;小面=真安培;重量= javabin&安培;版本= 2}   hits = 2 status = 0 QTime = 5感谢任何帮助以解决此问题。

0 个答案:

没有答案