Closed sarbogast closed 12 years ago
You can annotate your domain class as specified by hibernate search official documentation.
Since analyzers have to be unique (by name) within the whole application, you could also define analyzers in Config.groovy (cf documentation). Thus, all analyzers are grouped within same config file.
Then, when indexing you need to use a named analyzer, the documentation says:
Set the analyzer at the entity level: all fields will be indexed with the analyzer
class MyDomainClass {
String author
String body
...
static search = {
analyzer = 'ngram'
author index: 'tokenized'
body index: 'tokenized'
}
}
Or set the analyzer at the field level:
class MyDomainClass {
String author
String body
...
static search = {
author index: 'tokenized'
body index: 'tokenized', analyzer: 'ngram'
}
}
By default, Hibernate Search queries with the configured analyzers. No specific code is required. This is also true for the search DSL On the other side, you could need to query by ignoring the configured analyzer. This is also documented:
When searching for data, you may want to not use the field bridge or the analyzer. All methods (below, above, between, keyword, fuzzy) accept an optional map parameter to support this:
MyDomainClass.search().list {
keyword "status", Status.DISABLED, [ignoreAnalyzer: true]
}
Sorry, I hadn't seen documentation in Github and documentation on Grails plugin portal seems to be out of sync. Thanks a lot.
Oups, you're right! I should put a link pointing to the full documentation on the portal.
Apart from the search example in the doc, is there any reference documentation where I can find the exact meaning of each of the terms (should, mustNot, wildcard, etc.) as well as a comprehensive list of all the available terms?
No, there is not yet reference documentation. All these terms come from hibernate search official DSL.
I agree with you: The documentation should have a table with definition of all these terms.
I figured that those terms came from Hibernate Search's API but unfortunately their documentation is not very clear either. I'm still struggling to understand the meaning of must/should. For example, how would you go about search for object whose status is either OPEN or PUBLISHED and description field matches "something"?
Here is your solution:
MyDomainClass.search().list{
should {
keyword "myStatus", "OPENED"
keyword "myStatus", "PUBLISHED"
}
keyword "description", "java"
}
equivalent to:
MyDomainClass.search().list{
must {
should {
keyword "myStatus", "OPENED"
keyword "myStatus", "PUBLISHED"
}
keyword "description", "java"
}
}
because the root node is a must condition.
Thanks a lot! It works!
Could you please elaborate on how your search DSL works. More specifically, how can I specify a custom analyser for a field. I had to annotate my entity so that fields with HTML content could be indexed without HTML tags, but then I have to query using the same analyzer. Hibernate Search documentation shows how to do that with standard API, but how does it work with your search DSL?