[hibernate-dev] [HSEARCH] New Query API: last call
Hardy Ferentschik
hibernate at ferentschik.de
Thu Jun 3 05:42:35 EDT 2010
Looks fine to me looking at the examples. I haven't tried myself writing
my own queries though
to see the full potential.
On Wed, 02 Jun 2010 18:00:20 +0200, Emmanuel Bernard
<emmanuel at hibernate.org> wrote:
> Guys,
> I'me now done with the level of abstraction and fluidity I wanted out of
> the query DSL. Please review before we push that out. Key features:
> - fluent API
> - use the field bridge system: type is passed, not raw string
> - use the analyzer transparently
> - simple use case simple, complex use cases possible
>
> I'm showing below a few examples demonstrating key concepts.
>
> Please comment / ask questions.
>
> Term query
> query = monthQb
> .keyword()
> .onField( "monthValue" )
> .matching( 2 ) //note that monthValue is of type int
> .createQuery();
>
> //term query, showing analyzer integration
> query = monthQb
> .keyword()
> .onField( "mythology_ngram" )
> .matching( "snobored" ) //we apply the ngram filter here
> .createQuery();
>
> //use fuzzy query
> query = monthQb
> .keyword()
> .fuzzy()
> .threshold( .8f ) //optional
> .prefixLength( 1 ) //optional
> .onField( "mythology" )
> .matching( "calder" )
> .createQuery();
>
> //use wildcard queries
> monthQb
> .keyword()
> .wildcard()
> .onField( "mythology" )
> .matching( "mon*" )
> .createQuery();
>
> Alternative option
> //apply on multiple fields
> monthQb.keyword()
> .onField( "mythology" )
> .boostedTo( 30 )
> .andField( "history" )
> .matching( "whitening" )
> .createQuery();
>
> //boost a field
> monthQb
> .keyword()
> .onField( "history" )
> .boostedTo( 30 )
> .matching( "whitening" )
> .createQuery();
>
> Range query
> //Range query
> monthQb
> .range()
> .onField( "estimatedCreation" )
> .from( from ) #from and to are actual java.util.Date. We do the
> conversion
> .to( to ).exclude()
> .createQuery();
>
> monthQb
> .range()
> .onField( "estimatedCreation" )
> .below( brithDay )
> .createQuery();
>
> Phrase query
> monthQb
> .phrase()
> .slop( 1 )
> .onField( "mythology" )
> .sentence( "Month whitening" )
> .createQuery();
>
> Boolean query
> monthQb
> .bool()
> .should( monthQb.keyword().onField( "mythology" ).matching(
> "whitening" ).createQuery() )
> .should( monthQb.keyword().onField( "history" ).matching( "whitening"
> ).createQuery() )
> .createQuery();
>
> //Boolean query all except (recommended)
> monthQb
> .all()
> .except( monthQb.keyword().onField( "mythology" ).matching( "colder"
> ).createQuery() )
> .createQuery();
>
> _______________________________________________
> hibernate-dev mailing list
> hibernate-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/hibernate-dev
More information about the hibernate-dev
mailing list