mathpere / grails-hibernate-search-plugin

Integrates Hibernate Search features to Grails
http://grails.org/plugin/hibernate-search
Apache License 2.0
21 stars 18 forks source link

Documentation about your search DSL #8

Closed sarbogast closed 12 years ago

sarbogast commented 12 years ago

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?

mathpere commented 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:

Use named analyzers

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:

Support for ignoreAnalyzer() or ignoreFieldBridge() functions

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]
}
sarbogast commented 12 years ago

Sorry, I hadn't seen documentation in Github and documentation on Grails plugin portal seems to be out of sync. Thanks a lot.

mathpere commented 12 years ago

Oups, you're right! I should put a link pointing to the full documentation on the portal.

sarbogast commented 12 years ago

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?

mathpere commented 12 years ago

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.

sarbogast commented 12 years ago

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"?

mathpere commented 12 years ago

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.

sarbogast commented 12 years ago

Thanks a lot! It works!