-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 
Author Message
 Post subject: Programmatic configuration (goal: integrate with Grails)
PostPosted: Thu Mar 19, 2009 5:40 am 
Beginner
Beginner

Joined: Thu Sep 08, 2005 10:29 am
Posts: 21
Hi,

I'm investigating the possibilities to integrate Hibernate Search with Grails.

A typical Grails domain class looks like:

Code:
class Book {

    static belongsTo = [author: Author]

    String title
    String isbn

    static constraints = {
        author(nullable: false)
        title(nullable: false, blank: false, maxSize: 50)
        isbn(nullable: false, blank: false, minSize: 13, maxSize: 13, unique: true)
    }
}


The idea is to extend it with some Grails conventions like:

Code:
     static searchable = true


or something like:

Code:
     static searchable = ['title', 'isbn']


Off course there would be more mappings available.

Currently there is already a Searchable plugin for Grails available which uses Compass. Compass allows programmatic configuration.

Is something similar available in Hibernate Search? Otherwise it will be difficult to integrate at the moment.

Cheers,
Marcel
[/code]


Top
 Profile  
 
 Post subject: Similar like Compass
PostPosted: Thu Mar 19, 2009 9:30 am 
Beginner
Beginner

Joined: Thu Sep 08, 2005 10:29 am
Posts: 21
I'm looking for something similar as in the Compass Search Engine:

http://www.compass-project.org/docs/2.1 ... rceMapping)


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 21, 2009 2:04 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hi,
I'd love to see Search integrated with Grails;
As far as I know the entity mapping is currently only read by reflection from annotated classes;
you can see for yourself in
Code:
org.hibernate.search.impl.SearchFactoryImpl(SearchConfiguration cfg)


I'll ping Emmanuel to see if we can be more flexible ;-)

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 22, 2009 8:29 am 
Beginner
Beginner

Joined: Thu Sep 08, 2005 10:29 am
Posts: 21
I thought so from the docs.
I think it will be difficult to integrate then for non-annotated Grails domain classes (I guess Grails users use this 99% of the time).

Allthough I've tested a little bit with annotated Groovy classes (and if you are familiar with Grails) I've extended (using metaclass) the Domain Classes with a static search method to a execute a Hibernate search query. It works great.

So I was possible to do this:

Code:
Book.search("Grisham")
Book.search("Potter", [max:10, offset: 0])


I've put work on hold now as I don't see a way to configure non-annotated Grails domain classes.
Maybe Emmanuel has some idea on how to be more flexible and in what timeframe.

Goal for me is to create an os Grails plugin for this. I think a lot of Grails users would like this ;-)


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 22, 2009 10:29 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Hi Marcelo,
I am not sure why Grails people don't use annotations. It looks to me much better than the arbitrary static methods dynamic languages use.

Also I could not find where the Compass API to create a mapping are. The link you sent me shows how to programmatically configure it but we already have that.

Anyway, to test my Fluent designer skills and to avoid being nagged by people asking for XML support I have stated a programmatic mapping API for Hibernate Search this week end.

Code:
      SearchMapping mapping = new SearchMapping();
      mapping.analyzerDef( "stem", StandardTokenizerFactory.class )
               .tokenizerParam( "name", "value" )
               .tokenizerParam(  "name2", "value2" )
               .filter( LowerCaseFilterFactory.class )
               .filter( SnowballPorterFilterFactory.class)
                  .param("language", "English")
            .analyzerDef( "ngram", StandardTokenizerFactory.class )
               .tokenizerParam( "name", "value" )
               .tokenizerParam(  "name2", "value2" )
               .filter( LowerCaseFilterFactory.class )
               .filter( NGramFilterFactory.class)
                  .param("minGramSize", "3")
                  .param("maxGramSize", "3")
            .indexedClass(Address.class, "Address_Index")
               .property("street1", ElementType.FIELD)
                  .field()
                  .field()
                     .name("street1_iso")
                     .store( Store.YES )
                     .index( Index.TOKENIZED )
                     .analyzer( ISOLatin1Analyzer.class)
                  .field()
                     .name("street1_ngram")
                     .analyzer("ngram")
            .indexedClass(User.class)
               .property("name", ElementType.METHOD)
                  .field()
            .analyzerDef( "minimal", StandardTokenizerFactory.class  );

      configuration.getProperties().put( "hibernate.search.mapping_model", mapping );


It works nicely (analyzerDef is not wired yet).

Let me know what you think. Either I will complete the work or even better you can do it if you are interested in pursuing my initial investigation. I have removed all the difficulties but one and I know how to solve it.

It's available upstream and requires the upstream commons-annotations and annotations projects.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 23, 2009 4:36 am 
Beginner
Beginner

Joined: Thu Sep 08, 2005 10:29 am
Posts: 21
Hi Emmanuel,

Thanks for your reply.
The example you gave is exactly what I mean.

Is it in svn or is there also a nightly build available which include it?

As I don't have that much time, I would be cool if you could complete the stuff. Then I can do the Grails part, which will take some time also. But I understand you also a busy agenda I guess. So let's see how we can proceed.

As you mentioned, if this can be added you will get finally rid of people nagging you about this.... ;-)


Cheers,
Marcel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 24, 2009 12:05 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
yes that's in SVN at the moment. I will try to complete that slowly. Come a join the hibernate-dev list, that will be easier to track down progresses. I tend to forget forum posts.
Note that what I have already committed should be good enough for you to start already as it does class and property @Field mapping.

I'm sure you will get some demand on the query side (maybe a query builder model) and that's an area we want to work on for this release. You input will help.

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.