2014-02-22 63 views
2

我在Grails 2.2.3應用程序中使用Searchable Plugin 0.6.4,但遇到了一個奇怪的錯誤。錯誤說:GrailsContextLoader Error initializing the application: No entities listed to be indexed, have you defined your entities correctly?Grails可搜索插件 - 沒有被列入索引的實體

我只有一個類列出索引。下面是這個類(簡化了一下):

class Incident { 

    String howReceived 
    Date timeOfCall 
    Date timeOfArrival 

    User reportingOfficer 

    static searchable = [ except: ['version', 'dateCreated', 'lastUpdated'] ] 

    static embedded = [ 'witnesses' ] 
    static hasMany = [ witnesses: Witness ] 

    static mapping = { 
     datasource 'police' 
     table 'incidents' 
    } 
} 

這就是我所擁有的一個簡單的映射。下面我還包括了我打開的堆棧跟蹤和調試語句。

編輯:看來,由於某種原因,sessionFactory豆未在DefaultHibernateEntitiesLocator類找到任何類的元數據。所以...

Map allClassMetaData = sessionFactory.getAllClassMetadata(); 
assert allClassMetaData == null 

不確定爲什麼或者如果這些信息有幫助。

調試

searchable.SearchableGrailsPlugin Not found: Searchable 
searchable.SearchableGrailsPlugin Trying to load config from 'SearchableConfiguration.class' 
searchable.SearchableGrailsPlugin Not found: SearchableConfiguration 
searchable.SearchableGrailsPlugin Defining Compass and Compass::GPS beans 
searchable.SearchableGrailsPlugin Done defining Compass and Compass::GPS beans 
spring.DefaultSearchableCompassFactoryBean Building SearchableCompassFactoryBean with grailsApplication [[email protected]ea05] and compassClassMappingXmlBuilder [grails.plugin.searchable.internal[email protected]e0ef6fa] 
spring.SearchableCompassFactoryBean Building new Compass 
config.EnvironmentSearchableCompassConfigurator Setting Compass connection to [/Users/grantmcconnaughey/.grails/projects/campus-police/searchable-index/development] 
config.DefaultGrailsDomainClassMappingSearchableCompassConfigurator Mapping class [com.company.police.Incident] with strategy [searchable class property] 
config.DefaultGrailsDomainClassMappingSearchableCompassConfigurator No mapping strategy found for class [com.company.police.Employee]: assuming this class is not searchable 
mapping.SearchableGrailsDomainClassCompassMappingUtils Mapping [Incident.howReceived] 
mapping.SearchableGrailsDomainClassCompassMappingUtils Mapping [Incident.id] 
mapping.SearchableGrailsDomainClassCompassMappingUtils Mapping [Incident.timeOfArrival] 
mapping.SearchableGrailsDomainClassCompassMappingUtils Mapping [Incident.timeOfCall] 
mapping.DefaultSearchableCompassClassMappingXmlBuilder Building Compass mapping XML for [com.company.police.Incident] from description [CompassClassMapping: mappedClass=[class com.company.police.Incident], mappedClassSuperClass=[null], alias=[Incident], spellCheck=[null], subIndex=[null], root=[true], poly=[false], extend=[null], propertyMappings=[[CompassClassPropertyMapping: type=[property], propertyName=[domestic], attributes=[{}], CompassClassPropertyMapping: type=[property], propertyName=[hateCrime], attributes=[{}], CompassClassPropertyMapping: type=[property], propertyName=[howReceived], attributes=[{}], CompassClassPropertyMapping: type=[id], propertyName=[id], attributes=[{}], CompassClassPropertyMapping: type=[property], propertyName=[occurredFrom], attributes=[{}], CompassClassPropertyMapping: type=[property], propertyName=[occurredTo], attributes=[{}], CompassClassPropertyMapping: type=[property], propertyName=[officerAssaulted], attributes=[{}], CompassClassPropertyMapping: type=[property], propertyName=[officerKilled], attributes=[{}], CompassClassPropertyMapping: type=[property], propertyName=[readyForSignature], attributes=[{}], CompassClassPropertyMapping: type=[property], propertyName=[reportNumber], attributes=[{}], CompassClassPropertyMapping: type=[property], propertyName=[timeOfArrival], attributes=[{}], CompassClassPropertyMapping: type=[property], propertyName=[timeOfCall], attributes=[{}]]]] 
mapping.DefaultSearchableCompassClassMappingXmlBuilder Mapping Searchable Property 'com.company.police.Incident.howReceived' with property attributes [name:howReceived] and meta-data [howReceived:[:]] 
mapping.DefaultSearchableCompassClassMappingXmlBuilder Mapping Searchable Property 'com.company.police.Incident.timeOfArrival' with property attributes [name:timeOfArrival] and meta-data [timeOfArrival:[:]] 
mapping.DefaultSearchableCompassClassMappingXmlBuilder Mapping Searchable Property 'com.company.police.Incident.timeOfCall' with property attributes [name:timeOfCall] and meta-data [timeOfCall:[:]] 
mapping.DefaultSearchableCompassClassMappingXmlBuilder com.company.police.Incident xml [<?xml version="1.0"?> 
<!DOCTYPE compass-core-mapping PUBLIC 
    "-//Compass/Compass Core Mapping DTD 2.0//EN" 
    "http://www.compass-project.org/dtd/compass-core-mapping-2.2.dtd"> 
<compass-core-mapping> 
    <class name='com.company.police.Incident' alias='Incident' root='true' poly='false' support-unmarshall='true'> 
    <id name='id' /> 
    <property name='howReceived'> 
     <meta-data>howReceived</meta-data> 
    </property> 
    <property name='timeOfArrival'> 
     <meta-data>timeOfArrival</meta-data> 
    </property> 
    <property name='timeOfCall'> 
     <meta-data>timeOfCall</meta-data> 
    </property> 
    </class> 
</compass-core-mapping>] 
mapping.SearchableClassPropertySearchableGrailsDomainClassMappingConfigurator Adding [com.company.police.Incident] mapping to CompassConfiguration 
spring.SearchableCompassFactoryBean Done building Compass 
domain.DynamicDomainMethodUtils Adding searchable methods to [com.company.police.Incident] 
searchable.SearchableGrailsPlugin Started Compass::GPS 
compass.CompassGpsUtils Starting Searchable Plugin bulk index 

堆棧跟蹤

context.GrailsContextLoader Error initializing the application: No entities listed to be indexed, have you defined your entities correctly? 
java.lang.IllegalArgumentException: No entities listed to be indexed, have you defined your entities correctly? 
    at org.compass.gps.device.support.parallel.ConcurrentParallelIndexExecutor.performIndex(ConcurrentParallelIndexExecutor.java:88) 
    at org.compass.gps.device.support.parallel.AbstractParallelGpsDevice.index(AbstractParallelGpsDevice.java:119) 
    at org.compass.gps.impl.DefaultReplaceIndexCallback.buildIndexIfNeeded(DefaultReplaceIndexCallback.java:42) 
    at org.compass.core.lucene.engine.manager.DefaultLuceneSearchEngineIndexManager$ReplaceIndexOperationCallback.firstStep(DefaultLuceneSearchEngineIndexManager.java:281) 
    at org.compass.core.lucene.engine.manager.DefaultLuceneSearchEngineIndexManager.doOperate(DefaultLuceneSearchEngineIndexManager.java:218) 
    at org.compass.core.lucene.engine.manager.DefaultLuceneSearchEngineIndexManager.doReplaceIndex(DefaultLuceneSearchEngineIndexManager.java:266) 
    at org.compass.core.lucene.engine.manager.DefaultLuceneSearchEngineIndexManager.replaceIndex(DefaultLuceneSearchEngineIndexManager.java:261) 
    at org.compass.gps.impl.SingleCompassGps.doIndex(SingleCompassGps.java:118) 
    at org.compass.gps.impl.AbstractCompassGps.index(AbstractCompassGps.java:154) 
    at org.compass.gps.impl.AbstractCompassGps.index(AbstractCompassGps.java:128) 
    at grails.plugin.searchable.internal.compass.CompassGpsUtils.index(CompassGpsUtils.java:49) 
+0

兩件事檢查:1.'grails clean'(用手指劃過:))和2.檢查存儲索引的文件夾的權限 – aldrin

+0

謝謝,@aldrin。我幾次沒有運氣就完成了Grails的清理工作。我還檢查了存儲索引的文件夾的權限,並且正在寫入該文件夾,所以我認爲這不是問題。它正在創建一個'gpsindex'和一個'index'文件夾。在這些文件夾裏面有一個'incident'文件夾,裏面有文件'segments_1'和'segments.gen'。所以看起來權利不是問題。 :( – grantmcconnaughey

+0

如果你可以在某個地方分享你的應用程序代碼(或者有這個錯誤的示例),也許有人可以看一看。你的代碼沒有什麼明顯的錯誤,必須是一些安裝/配置問題 – aldrin

回答

1

的問題是使用一個數據源使用非默認名稱,在這種情況下, '警察'。我沒有看到文檔中的任何地方提到插件不會使用與「dataSource」不同的名稱的數據源。我會盡快更新他們的文檔。

我發現修復here。如果鏈接出現故障,請執行以下操作。以下內容添加到resources.groovy

import org.compass.gps.device.hibernate.HibernateGpsDevice 
import grails.plugin.searchable.internal.compass.config.SessionFactoryLookup 

beans = { 
    compassGpsDevice(HibernateGpsDevice) { bean -> 
     bean.destroyMethod = "stop" 
     name = "hibernate" 
     sessionFactory = { SessionFactoryLookup sfl -> 
      sessionFactory = ref('sessionFactory_datasourceName') 
     } 
     fetchCount = 5000 
    } 
} 

要添加其他數據源與可轉位類,添加以下內容:

anotherUniquecompassGpsDevice(HibernateGpsDevice) { bean -> 
    bean.destroyMethod = "stop" 
    name = "unqiueHibernateName" 
    sessionFactory = { SessionFactoryLookup sfl -> 
     sessionFactory = ref('sessionFactory_uniquedatasource') 
    } 
    fetchCount = 5000 
    } 

最後加......你可能想

import org.compass.gps.impl.SingleCompassGps 

compassGps(SingleCompassGps) { 
    compass = ref('compass') 
    gpsDevices = [compassGpsDevice, anotherUniqueCompassGpsDevice] 
} 
相關問題