對於背景,我使用Grails v2.2.1和可搜索插件(v0.6.4)作爲我的應用程序,儘管我是配置Lucene的新手。Grails lucene搜索需要花費過多的時間
日誌顯示搜索服用26毫秒,但指南針交易大約需要15秒返回:
2013-04-23 00:40:34,269 DEBUG grails.plugin.searchable.internal. compass.search.DefaultSearchMethod - query: [+kind:band +name:snoop], [4] hits, took [26] millis
2013-04-23 00:40:49,965 DEBUG org.compass.core.transaction.LocalTransaction - Committing local transaction on thread [http-bio-8080-exec-10] Compass [1176020804] Session [2089649487]
這似乎是與北斗比Lucene的作爲更成問題查詢執行速度很快,但Compass映射在我的Java進程接近100%的CPU時掛起,並且掛起的時間太長。
我有大約3500個域對象編入索引,我的域模型如下所示: 我試圖僅索引字段名稱和ID,但它似乎映射了通過盧克看到的域中的所有內容。在我的控制器
package com.bandbot
class Band {
def slugGeneratorService
static searchable = {
mapping {
spellCheck "exclude"
only: ['name', 'id']
}
}
String name
String biography
String profileImage
String slug
String similarBands // this will store bands/url/pic in the form of Kanye West::url::img.png~Queen::url::img.png
boolean onTour // is this band currently touring? (Info from lastfm)
String mbid // This band's MusicBrainz ID see @ http://musicbrainz.org/doc/MusicBrainz_Identifier
String bandUrl
String lastFMUrl // stores the lastfm url
Date dateOfInception
Date dateDisbanded
Date lastUpdated
static belongsTo = [Genre, BandbotUser]
static hasMany = [ events : Event, genres : Genre ]
def beforeInsert() {
lastUpdated = new Date()
this.slug = slugGeneratorService.generateSlug(this.class, "slug", name)
}
def beforeUpdate() {
lastUpdated = new Date()
if (isDirty('name')) {
this.slug = slugGeneratorService.generateSlug(this.class, "slug", name)
}
}
static constraints = {
name(nullable: false, blank: false, unique: true)
slug(nullable: true)
bandUrl(nullable: true)
dateDisbanded(nullable: true)
mbid(nullable: true)
dateOfInception(nullable: true)
biography(nullable: true)
similarBands(nullable: true)
lastUpdated(nullable: true)
lastFMUrl(nullable: true)
kind(display: false)
}
static mapping = {
onTour defaultValue: false
biography type: 'text'
similarBands type: 'text'
}
String toString(){name}
}
我的搜索邏輯樂隊:
def search() {
if (!params.q?.trim()) {
return [:]
}
try {
def searchResult
if (params.sort) {
searchResult = searchableService.search(
params.q.trim(),
[offset: params.offset ? params.int('offset') : 0,
max: params.max ? params.int('max') : 10,
sort: params.sort, order: params.order? params.order : 'asc']
)
}
else {
searchResult = searchableService.search(
params.q.trim(),
[offset: params.offset ? params.int('offset') : 0,
max: params.max ? params.int('max') : 10]
)
}
return [searchResult: searchResult, params: params]
} catch (SearchEngineQueryParseException ex) {
return [parseException: true, params: params]
}
}
任何想法,將不勝感激。這是我的一個自學項目,我真的想以正確的方式進行搜索。 :)謝謝, Kevin
你可以發佈你的搜索代碼? – allthenutsandbolts 2013-04-24 16:55:26
確定我會更新我的問題。 – vinberts 2013-04-24 18:23:24
我沒有看到任何明顯的。你可以嘗試在bootstrap中使用searchableService.reindex() ,看看是否有幫助 – allthenutsandbolts 2013-04-24 19:50:42