[hibernate-dev] [HSEARCH] New Query API: last call
Sanne Grinovero
sanne.grinovero at gmail.com
Thu Jun 3 10:40:00 EDT 2010
It's looking very good; I'll seek a couple of hours this weekend to
actually try it for real.
I don't think it need changes, but if you seek for in depth-criticism
I might add some additional fuel:
I'm not 100% convinced about the use of "matching()" as method name,
it confuses me a bit. This might be because of my non-native english,
not sure.
Doesn't "match()" sound better? "searchMatch" ?
Having:
monthQb
.phrase()
.slop( 1 )
.onField( "mythology" )
.sentence( "Month whitening" )
Here "sentence" takes the same logical role as "matching" ?
WDYT about
monthQb
.phraseQuery() // stress that's a kind of Query
.havingSlop( 1 ) || .withSlop( 1 )
.onField( "mythology" )
.searchSentence( "Month whitening" )
?
The method names are longer, but Imho there's a left part of the
sentence and a right part of the sentence; the left part migh have
options and be compound, the right part too. Waht is curretnyl missing
to make it better readable is to choose appropriate nouns to have a
clear separation to demark the end of the left part and the beginning
of the right part.
In the example above "slop" might look like a command, it sounds to me
like "do a slop with option 1", of course that doesn't make sense, but
is impairing readability.
"searchSentence"
"searchMatch"
might be good delimiters for interpretation?
Sanne
2010/6/3 Hardy Ferentschik <hibernate at ferentschik.de>:
> 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
>
> _______________________________________________
> 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