我在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?
我只列出了一个要编入索引的类。下面是那个类(简化了一点):
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
bean似乎未在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 [org.codehaus.groovy.grails.commons.DefaultGrailsApplication@10fdea05] and compassClassMappingXmlBuilder [grails.plugin.searchable.internal.compass.mapping.DefaultSearchableCompassClassMappingXmlBuilder@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)
问题是使用带有非默认名称的dataSource,在本例中为“police”。我没有在文档中看到任何提及插件不能使用与“dataSource”不同的名称的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
}
}
要添加具有可索引类的其他dataSource,请添加以下内容:
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]
}