2

使用 Grails 中的可搜索插件(在底层使用 Compass/Lucene),我们尝试在两个不同的 Web 应用程序之间共享搜索索引。一个应用程序仅以只读方式访问数据。另一个应用程序允许修改数据并负责在任何更改时更新索引或根据需要进行完整的重新索引。

为了存储索引,我们使用 JDBC 存储(两个应用程序都指向同一个数据库)http://www.compass-project.org/docs/latest/reference/html/core-connection.html

不幸的是,一旦我们在一个应用程序中重建整个索引,另一个应用程序似乎缓存了无效数据,如果执行搜索,则会引发异常:

| Error 2012-05-30 09:22:07,560 [http-bio-8080-exec-8] ERROR errors.GrailsExceptionResolver  - IndexOutOfBoundsException occurred when processing request: [POST] /search
Index: 45, Size: 13. Stacktrace follows:
Message: Index: 45, Size: 13
   Line | Method
->> 547 | RangeCheck  in java.util.ArrayList
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   322 | get         in     ''
|   265 | fieldInfo . in org.apache.lucene.index.FieldInfos
|   254 | fieldName   in     ''
|    86 | read . . .  in org.apache.lucene.index.TermBuffer
|   127 | next        in org.apache.lucene.index.SegmentTermEnum
|   158 | scanTo . .  in     ''
|   271 | get         in org.apache.lucene.index.TermInfosReader
|   332 | terms . . . in     ''
|   717 | terms       in org.apache.lucene.index.SegmentReader
|    93 | generate .  in org.apache.lucene.search.PrefixGenerator
|    58 | getDocIdSet in org.apache.lucene.search.PrefixFilter
|   116 | <init> . .  in org.apache.lucene.search.ConstantScoreQuery$ConstantScorer
|    81 | scorer      in org.apache.lucene.search.ConstantScoreQuery$ConstantWeight
|   230 | scorer . .  in org.apache.lucene.search.BooleanQuery$BooleanWeight
|   131 | search      in org.apache.lucene.search.IndexSearcher
|   112 | search . .  in     ''
|   204 | search      in org.apache.lucene.search.MultiSearcher
|   113 | getMoreDocs in org.apache.lucene.search.Hits
|    90 | <init>      in     ''
|    61 | search . .  in org.apache.lucene.search.Searcher
|   146 | findByQuery in org.compass.core.lucene.engine.transaction.support.AbstractTransactionProcessor
|   259 | doFind . .  in org.compass.core.lucene.engine.transaction.readcommitted.ReadCommittedTransactionProcessor
|   246 | find        in org.compass.core.lucene.engine.transaction.support.AbstractConcurrentTransactionProcessor
|   352 | find . . .  in org.compass.core.lucene.engine.LuceneSearchEngine
|   188 | hits        in org.compass.core.lucene.engine.LuceneSearchEngineQuery
|   199 | hits . . .  in org.compass.core.impl.DefaultCompassQuery
|   104 | doInCompass in grails.plugin.searchable.internal.compass.search.DefaultSearchMethod$SearchCompassCallback
|   133 | execute . . in org.compass.core.CompassTemplate
|    57 | doInCompass in grails.plugin.searchable.internal.compass.support.AbstractSearchableMethod
|    66 | invoke . .  in grails.plugin.searchable.internal.compass.search.DefaultSearchMethod
|    37 | search      in grails.plugin.searchable.SearchableService

我们可以将索引从一个应用程序重建到另一个应用程序这一事实进行沟通,以便可以执行一些清理工作。

  • 有人对 Grails 和 Searchable 插件有类似的问题吗?
  • 是否可以丢弃 Compass/Lucene 缓存的数据?
  • 一般可以禁用缓存吗?
4

1 回答 1

1

在搜索之前清除所有缓存似乎可以解决问题......

searchableService.compass.compass.searchEngineFactory.indexManager.clearCache()
于 2012-06-13T12:40:58.647 回答