grails create-app myapp
cd myapp
grails install-plugin searchable
grails install-searchable-config
grails create-domain-class book
grails create-controller book
grails-app/conf/Searchable.groovy
compassSettings = [
'compass.engine.analyzer.myAnalyzer.filters':
'myAnalyzerfilter',
'compass.engine.analyzerfilter.myAnalyzerfilter.type':
'synonym',
'compass.engine.analyzerfilter.myAnalyzerfilter.lookup':
'sample.MySynonymLookupProvider'
]
src/groovy/sample/MySynonymLookupProvider.groovy
package sample
import org.compass.core.CompassException
import org.compass.core.config.CompassSettings
import org.compass.core.lucene.engine.analyzer.synonym.SynonymLookupProvider
class MySynonymLookupProvider implements SynonymLookupProvider {
String[] lookupSynonyms(String string) {
def synonyms = [string]
if (string == 'artifact') {
synonyms << 'artefact'
}
return synonyms as String[]
}
void configure(CompassSettings settings) throws CompassException {
}
}
grails-app/domain/Book.groovy
class Book {
String title
static searchable = {
analyzer 'myAnalyzer'
// title(analyzer: 'myAnalyzer') カラムごとに指定するなら
}
}
これで new Book(title: 'artifact').save() すると、artefactで検索に引っかかるようになる。日本語でやるならSen入れないとだめぽい。
0 件のコメント:
コメントを投稿