public interface SearchPredicateFactoryContext
This is the main entry point to the predicate DSL.
match()
predicate or the range()
predicate,
target an index field and define an Object
parameter (MatchPredicateFieldSetContext.matching(Object)
,
RangePredicateFieldSetContext.from(Object)
, ...).
The type of arguments passed to these methods is expected to be consistent with the targeted field:
if you want a field "myField" to be between values X
and Y
,
Hibernate Search needs to be able to convert the values X
and Y
to something comparable to the indexed value of "myField".
Generally the expected type of this argument should be rather obvious:
for example if you created a field by mapping an Integer
property,
then an Integer
value will be expected when building a predicate;
if you mapped a LocalDate
, then a LocalDate
will be expected.
Note that the type that is actually stored in the index does not matter:
if you mapped a custom enum type, then this same enum type will be expected throughout the predicate DSL,
even if it is stored as a String
in the index.
Sometimes a predicate targets multiple fields, either explicitly
(multiple field names passed to the onFields
method when defining the predicate)
or implicitly (multiple targeted indexes).
In that case, the type of the targeted fields must be compatible.
For example targeting an Integer
field and a LocalDate
field
in the same match()
predicate won't work, because you won't be able to pass a non-null argument
that is both an Integer
and a LocalDate
to the MatchPredicateFieldSetContext.matching(Object)
method.
Thus you generally cannot target fields with different types in the same predicate.
When targeting different fields in the same index, you can, however,
define one predicate for each field and combine them using a boolean predicate
.
Note that custom bridges have the ability to customize the expected type of arguments in the DSL:
for example they could accept String
arguments when targeting Integer
fields.
See the documentation of bridges for more information on custom bridges.
Modifier and Type | Method and Description |
---|---|
BooleanJunctionPredicateContext |
bool()
Match documents if they match a combination of boolean clauses.
|
SearchPredicate |
bool(Consumer<? super BooleanJunctionPredicateContext> clauseContributor)
Match documents if they match a combination of boolean clauses,
which will be defined by the given consumer.
|
SearchPredicateFactoryExtensionContext |
extension()
Create a context allowing to try to apply multiple extensions one after the other,
failing only if none of the extensions is supported.
|
<T> T |
extension(SearchPredicateFactoryContextExtension<T> extension)
Extend the current context with the given extension,
resulting in an extended context offering different types of predicates.
|
MatchIdPredicateContext |
id() |
MatchPredicateContext |
match()
Match documents where targeted fields have a value that "matches" a given single value.
|
MatchAllPredicateContext |
matchAll()
Match all documents.
|
NestedPredicateContext |
nested()
Match documents where a
nested object
matches a given predicate. |
RangePredicateContext |
range()
Match documents where targeted fields have a value within lower and upper bounds.
|
SpatialPredicateContext |
spatial()
Access the different types of spatial predicates.
|
MatchAllPredicateContext matchAll()
get the resulting predicate
.MatchAllPredicateContext
MatchIdPredicateContext id()
BooleanJunctionPredicateContext bool()
get the resulting predicate
.BooleanJunctionPredicateContext
SearchPredicate bool(Consumer<? super BooleanJunctionPredicateContext> clauseContributor)
Best used with lambda expressions.
clauseContributor
- A consumer that will add clauses to the context passed in parameter.
Should generally be a lambda expression.SearchPredicate
BooleanJunctionPredicateContext
MatchPredicateContext match()
Note that "value matching" may be exact or approximate depending on the type of the targeted fields: numeric fields in particular imply exact matches, while analyzed, full-text fields imply approximate matches depending on how they are analyzed.
get the resulting predicate
.MatchPredicateContext
RangePredicateContext range()
get the resulting predicate
.RangePredicateContext
NestedPredicateContext nested()
nested object
matches a given predicate.get the resulting predicate
.NestedPredicateContext
SpatialPredicateContext spatial()
SpatialPredicateContext
<T> T extension(SearchPredicateFactoryContextExtension<T> extension)
T
- The type of context provided by the extension.extension
- The extension to the predicate DSL.SearchException
- If the extension cannot be applied (wrong underlying backend, ...).SearchPredicateFactoryExtensionContext extension()
If you only need to apply a single extension and fail if it is not supported,
use the simpler extension(SearchPredicateFactoryContextExtension)
method instead.
Copyright © 2006-2018 Red Hat, Inc. and others. Licensed under the GNU Lesser General Public License (LGPL), version 2.1 or later.