For background, I am using Grails v2.2.1 and Searchable plugin (v0.6.4) for my application, although I am a newbie when it comes to configuring Lucene.
Logs show the search taking 26 mili seconds but the compass transaction takes about 15 seconds to return:
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]
This seems to be more an issue with Compass than Lucene as the query executes quickly but the Compass mapping pegs my Java process at near 100% CPU and hangs for way too long.
I have about 3500 domain objects indexed and my domain model looks like the following: I've tried to index only the fields name and id but it seems to map everything in the domain when seen through Luke.
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}
}
My search logic in my controller for bands:
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]
}
}
Any ideas would be greatly appreciated. This is for a self-learning project of mine and I really want to do search the right way. :) Thanks, Kevin