public interface PojoQueryBuilder<T>
the
pojo facade
is to simplify working with custom pojos.
PojoQueryBuilder keeps all the powerful queries available via
StructuredQueryBuilder while enabling queries across objects
persisted using PojoRepository
.
For methods which accept a "pojoProperty" argument we are refering to properties appropriate for JavaBeans, including properties accessible via public getters and setters, or public fields.
Where StructuredQueryBuilder accepts
StructuredQueryBuilder.TextIndex as a first argument to
value(TextIndex, String...)
and
word(TextIndex, String...)
methods,
PojoQueryBuilder adds shortcut methods which accept as the first
argument a String name of the pojoProperty. Similarly,
PojoQueryBuilder accepts String pojoProperty arguments wherever
StructuredQueryBuilder accepts StructuredQueryBuilder.Element,
StructuredQueryBuilder.Attribute, and
StructuredQueryBuilder.PathIndex as arguments to
geoAttributePair(Element, Attribute, Attribute)
,
geoElement(Element)
,
geoElement(Element, Element)
,
geoElementPair(Element, Element, Element)
,
geoPath(PathIndex)
Here are a couple examples. Without the pojo facade you might
persist your products using JacksonDatabindHandle
and query the json property thusly:
StructuredQueryBuilder sqb = new StructuredQueryBuilder();
QueryDefinition query = sqb.value(sqb.jsonProperty("productId"), 12345);
If you use PojoRepository
to persist your products, you can query more simply:
PojoQueryBuilder pqb = pojoRepository.getQueryBuilder();
QueryDefinition query = pqb.value("productId", 12345);
Similarly, without the pojo facade you might persist your pojos
using JAXBHandle
and
if they have a geoPosition property which is an object with
latitude and longitude pojoProperty's (which persist as elements)
you might query them thusly:
StructuredQueryBuilder sqb = new StructuredQueryBuilder();
StructuredQueryBuilder.GeospatialIndex geoIdx = sqb.geoElementPair(
sqb.element("geoPosition"), sqb.element("latitude"), sqb.element("longitude"));
But if you use PojoRepository
to persist your pojos with a latitude and longitude pojoProperty's,
you can query them more simply:
PojoQueryBuilder pqb = pojoRepository.getQueryBuilder();
StructuredQueryBuilder.GeospatialIndex geoIdx =
pqb.geoPair("latitude", "longitude");
As custom pojos may have nested pojos, PojoQueryBuilder also makes it easy to query those nested pojos. For example, if you had the following classes:
class City { @Id int id; Country country; int getId(); void setId(int id); Country getCountry(); void setCountry(Country country); } class Country { String continent; String getContinent(); void setContinent(); }
That is, you have a pojo class City with a property "country" of type Country, you could query properties on the nested country thusly:
PojoRepository<City, Integer> cities =
databaseClient.newPojoRepository(City.class, Integer.class);
PojoQueryBuilder<City> citiesQb = cities.getQueryBuilder();
PojoQueryBuilder<Country> countriesQb = citiesQb.containerQueryBuilder("country", Country.class);
QueryDefinition query = countriesQb.value("continent", "EU");
Modifier and Type | Interface | Description |
---|---|---|
static class |
PojoQueryBuilder.Operator |
Copied directly from
StructuredQueryBuilder.Operator . |
Modifier and Type | Method | Description |
---|---|---|
StructuredQueryDefinition |
and(StructuredQueryDefinition... queries) |
Copied directly from
StructuredQuerybuilder.and . |
StructuredQueryDefinition |
andNot(StructuredQueryDefinition positive,
StructuredQueryDefinition negative) |
Copied directly from
StructuredQuerybuilder.andNot . |
StructuredQueryDefinition |
boost(StructuredQueryDefinition matchingQuery,
StructuredQueryDefinition boostingQuery) |
Copied directly from
StructuredQuerybuilder.boost . |
StructuredQueryBuilder.Region |
box(double south,
double west, double north, double east) |
Copied directly from
StructuredQuerybuilder.box . |
RawStructuredQueryDefinition |
build(StructuredQueryDefinition... queries) |
Copied directly from
StructuredQuerybuilder.build . |
StructuredQueryBuilder.Region |
circle(double latitude,
double longitude, double radius) |
Copied directly from
StructuredQuerybuilder.circle(double, double,
double) . |
StructuredQueryBuilder.Region |
circle(StructuredQueryBuilder.Point center,
double radius) |
Copied directly from
StructuredQuerybuilder.circle(StructuredQueryBuilder.Point,
double) . |
StructuredQueryDefinition |
collection(java.lang.String... uris) |
Copied directly from
StructuredQuerybuilder.collection(String...) . |
StructuredQueryDefinition |
containerQuery(java.lang.String pojoProperty,
StructuredQueryDefinition query) |
|
<C> PojoQueryBuilder<C> |
containerQueryBuilder(java.lang.String pojoProperty,
java.lang.Class<C> clazz) |
Use this method to provide a query builder that
can query a nested object within your pojo.
|
PojoQueryDefinition |
filteredQuery(StructuredQueryDefinition query) |
Wraps the structured query into a combined query
with options containing <search-option>filtered</search-option>
so results are accurate though slower.
|
StructuredQueryBuilder.GeospatialIndex |
geoPair(java.lang.String latitudePropertyName,
java.lang.String longitudePropertyName) |
For use in a
geospatial query, reference a pair of
properties. |
StructuredQueryBuilder.GeospatialIndex |
geoPath(java.lang.String pojoProperty) |
For use in a
geospatial query, reference a geo property which
has a corresponding Geospatial Path Range Index configured in the
database. |
StructuredQueryDefinition |
geospatial(StructuredQueryBuilder.GeospatialIndex index,
StructuredQueryBuilder.Region... regions) |
|
StructuredQueryDefinition |
geospatial(StructuredQueryBuilder.GeospatialIndex index,
java.lang.String[] options, StructuredQueryBuilder.Region... regions) |
Copied from
StructuredQuerybuilder.geospatial(StructuredQueryBuilder.GeospatialIndex,
StructuredQueryBuilder.FragmentScope, String[],
StructuredQueryBuilder.Region...) but without
StructuredQueryBuilder.FragmentScope. |
StructuredQueryDefinition |
near(int distance,
double weight, StructuredQueryBuilder.Ordering order,
StructuredQueryDefinition... queries) |
|
StructuredQueryDefinition |
near(StructuredQueryDefinition... queries) |
Copied directly from
StructuredQuerybuilder.near(StructuredQueryDefinition...) . |
StructuredQueryDefinition |
not(StructuredQueryDefinition query) |
Copied directly from
StructuredQuerybuilder.not . |
StructuredQueryDefinition |
notIn(StructuredQueryDefinition positive,
StructuredQueryDefinition negative) |
Copied directly from
StructuredQuerybuilder.and . |
StructuredQueryDefinition |
or(StructuredQueryDefinition... queries) |
Copied directly from
StructuredQuerybuilder.and . |
StructuredQueryBuilder.Region |
point(double latitude,
double longitude) |
Copied directly from
StructuredQuerybuilder.point . |
StructuredQueryBuilder.Region |
polygon(StructuredQueryBuilder.Point... points) |
Copied directly from
StructuredQuerybuilder.polygon . |
StructuredQueryDefinition |
range(java.lang.String pojoProperty,
PojoQueryBuilder.Operator operator,
java.lang.Object... values) |
Query a Path Range Index configured in the
database for a pojo property.
|
StructuredQueryDefinition |
range(java.lang.String pojoProperty,
java.lang.String[] options, PojoQueryBuilder.Operator operator,
java.lang.Object... values) |
Query a Path Range Index configured in the
database for a pojo property.
|
StructuredQueryDefinition |
term(double weight,
java.lang.String... terms) |
Copied directly from
StructuredQuerybuilder.term(double,
String...) . |
StructuredQueryDefinition |
term(java.lang.String... terms) |
Copied directly from
StructuredQuerybuilder.term(String...) . |
StructuredQueryDefinition |
value(java.lang.String pojoProperty,
java.lang.Boolean value) |
Filter search results by properties matching
specified value.
|
StructuredQueryDefinition |
value(java.lang.String pojoProperty,
java.lang.Number... values) |
Filter search results by properties matching
specified values.
|
StructuredQueryDefinition |
value(java.lang.String pojoProperty,
java.lang.String... values) |
Filter search results by properties matching
specified values.
|
StructuredQueryDefinition |
value(java.lang.String pojoProperty,
java.lang.String[] options, double weight,
java.lang.Boolean value) |
Filter search results by properties matching
specified values.
|
StructuredQueryDefinition |
value(java.lang.String pojoProperty,
java.lang.String[] options, double weight,
java.lang.Number... values) |
Filter search results by properties matching
specified values.
|
StructuredQueryDefinition |
value(java.lang.String pojoProperty,
java.lang.String[] options, double weight,
java.lang.String... values) |
Filter search results by properties matching
specified values.
|
StructuredQueryDefinition |
word(java.lang.String pojoProperty,
java.lang.String... words) |
Filter search results by properties with at
least one of the specified words or phrases.
|
StructuredQueryDefinition |
word(java.lang.String pojoProperty,
java.lang.String[] options, double weight,
java.lang.String... words) |
Filter search results by properties with at
least one of the specified words or phrases.
|
StructuredQueryDefinition containerQuery(java.lang.String pojoProperty, StructuredQueryDefinition query)
pojoProperty
- the property container to match
againstquery
- the query to match within the
container<C> PojoQueryBuilder<C> containerQueryBuilder(java.lang.String pojoProperty, java.lang.Class<C> clazz)
C
- the type of the class contained by
pojoPropertypojoProperty
- the name of a field or JavaBean
property (accessed via getter or setter) on class T that is a pojo
of type clazzclazz
- the class type of the nested pojoStructuredQueryBuilder.GeospatialIndex geoPair(java.lang.String latitudePropertyName, java.lang.String longitudePropertyName)
geospatial
query, reference a pair of properties.
These properties should ideally have Geospatial Element Pair
Indexes configured in the database. For help creating these
indexes, see GenerateIndexConfig
,
GeospatialLatitude
,
and GeospatialLongitude
.latitudePropertyName
- the name of a field or
JavaBean property (accessed via getter or setter) ideally annotated
with @GeospatialLatitude
longitudePropertyName
- the name of a field or
JavaBean property (accessed via getter or setter) ideally annotated
with @GeospatialLongitude
StructuredQueryBuilder.GeospatialIndex geoPath(java.lang.String pojoProperty)
geospatial
query, reference a geo property which
has a corresponding Geospatial Path Range Index configured in the
database. For help creating this index, see GenerateIndexConfig
and GeospatialPathIndexProperty
.pojoProperty
- the name of a field or JavaBean
property (accessed via getter or setter) on class T ideally
annotated with @GeospatialPathIndexProperty
StructuredQueryDefinition range(java.lang.String pojoProperty, PojoQueryBuilder.Operator operator, java.lang.Object... values)
datatype
configured. For help creating this index, see GenerateIndexConfig
and PathIndexProperty
.pojoProperty
- the name of a field or JavaBean
property (accessed via getter or setter) on class T annotated with
@PathIndexProperty
operator
- the operator used to compare property
values with passed valuesvalues
- the possible datatyped values for the
comparison. Make sure the datatypes match the datatype
configured.StructuredQueryDefinition range(java.lang.String pojoProperty, java.lang.String[] options, PojoQueryBuilder.Operator operator, java.lang.Object... values)
datatype
configured. For help creating this index, see GenerateIndexConfig
and PathIndexProperty
.pojoProperty
- the name of a field or JavaBean
property (accessed via getter or setter) on class T annotated with
@PathIndexProperty
options
- options
for fine tuning the queryoperator
- the operator used to compare property
values with passed valuesvalues
- the possible datatyped values for the
comparison. Make sure the datatypes match the datatype
configured.StructuredQueryDefinition value(java.lang.String pojoProperty, java.lang.String... values)
pojoProperty
- the name of a field or JavaBean
property (accessed via getter or setter) on class Tvalues
- match a persisted pojo of type T if it
has the property with any of the valuesStructuredQueryDefinition value(java.lang.String pojoProperty, java.lang.Boolean value)
pojoProperty
- the name of a field or JavaBean
property (accessed via getter or setter) on class Tvalue
- match a persisted pojo of type T if it has
the property with the boolean valueStructuredQueryDefinition value(java.lang.String pojoProperty, java.lang.Number... values)
pojoProperty
- the name of a field or JavaBean
property (accessed via getter or setter) on class Tvalues
- match a persisted pojo of type T if it
has the property with any of the numeric valuesStructuredQueryDefinition value(java.lang.String pojoProperty, java.lang.String[] options, double weight, java.lang.String... values)
pojoProperty
- the name of a field or JavaBean
property (accessed via getter or setter) on class Toptions
- options
for fine tuning the queryweight
- the multiplier for the match in the
document rankingvalues
- match a persisted pojo of type T if it
has the property with any of the valuesStructuredQueryDefinition value(java.lang.String pojoProperty, java.lang.String[] options, double weight, java.lang.Boolean value)
pojoProperty
- the name of a field or JavaBean
property (accessed via getter or setter) on class Toptions
- options
for fine tuning the queryweight
- the multiplier for the match in the
document rankingvalue
- match a persisted pojo of type T if it has
the property with the boolean valueStructuredQueryDefinition value(java.lang.String pojoProperty, java.lang.String[] options, double weight, java.lang.Number... values)
pojoProperty
- the name of a field or JavaBean
property (accessed via getter or setter) on class Toptions
- options
for fine tuning the queryweight
- the multiplier for the match in the
document rankingvalues
- match a persisted pojo of type T if it
has the property with any of the numeric valuesStructuredQueryDefinition word(java.lang.String pojoProperty, java.lang.String... words)
pojoProperty
- the name of a field or JavaBean
property (accessed via getter or setter) on class Twords
- match a persisted pojo of type T if it has
the property with any of the words or phrasesStructuredQueryDefinition word(java.lang.String pojoProperty, java.lang.String[] options, double weight, java.lang.String... words)
pojoProperty
- the name of a field or JavaBean
property (accessed via getter or setter) on class Toptions
- options for
fine tuning the queryweight
- the multiplier for the match in the
document rankingwords
- match a persisted pojo of type T if it has
the property with any of the words or phrasesStructuredQueryDefinition and(StructuredQueryDefinition... queries)
StructuredQuerybuilder.and
. Defines an AND query
over the list of query definitions.queries
- the query definitionsStructuredQueryDefinition andNot(StructuredQueryDefinition positive, StructuredQueryDefinition negative)
StructuredQuerybuilder.andNot
. Defines an AND NOT
query combining a positive and negative query. You can use an AND
or OR query over a list of query definitions as the positive or
negative query.positive
- the positive query definitionnegative
- the negative query definitionStructuredQueryDefinition boost(StructuredQueryDefinition matchingQuery, StructuredQueryDefinition boostingQuery)
StructuredQuerybuilder.boost
. Defines a boost
query for the matching and boosting query definitions. The matching
or boosting query definitions can each be an AND or OR query
definition for complex combinations of criteria.matchingQuery
- the query definition that filters
documentsboostingQuery
- the query definition that
increases the rank for some filtered documentsStructuredQueryBuilder.Region box(double south, double west, double north, double east)
StructuredQuerybuilder.box
. Specifies a geospatial
region as a box, supplying the coordinates for the perimeter.south
- the latitude of the south coordinatewest
- the longitude of the west coordinatenorth
- the latitude of the north coordinateeast
- the longitude of the east coordinateRawStructuredQueryDefinition build(StructuredQueryDefinition... queries)
StructuredQuerybuilder.build
. Builds a structured
query in XML from the list of query definitions. The structured
query can be passed to the search() method of QueryManager.queries
- the query definitionsStructuredQueryBuilder.Region circle(double latitude, double longitude, double radius)
StructuredQuerybuilder.circle(double, double,
double)
. Specifies a geospatial region as a circle,
supplying coordinates for the center.latitude
- the latitude coordinate of the
centerlongitude
- the longitude coordinate of the
centerradius
- the radius of the circleStructuredQueryBuilder.Region circle(StructuredQueryBuilder.Point center, double radius)
StructuredQuerybuilder.circle(StructuredQueryBuilder.Point,
double)
. Specifies a geospatial region as a circle,
supplying a point for the center.center
- the point defining the centerradius
- the radius of the circleStructuredQueryDefinition collection(java.lang.String... uris)
StructuredQuerybuilder.collection(String...)
.
Matches documents belonging to at least one of the criteria
collections.uris
- the identifiers for the criteria
collectionsStructuredQueryDefinition geospatial(StructuredQueryBuilder.GeospatialIndex index, java.lang.String[] options, StructuredQueryBuilder.Region... regions)
StructuredQuerybuilder.geospatial(StructuredQueryBuilder.GeospatialIndex,
StructuredQueryBuilder.FragmentScope, String[],
StructuredQueryBuilder.Region...)
but without
StructuredQueryBuilder.FragmentScope. Matches an element, element
pair, element attribute, pair, or path specifying a geospatial
point that appears within one of the criteria regions.index
- the container for the coordinates of the
geospatial pointoptions
- options for fine tuning the queryregions
- the possible regions containing the
pointStructuredQueryDefinition geospatial(StructuredQueryBuilder.GeospatialIndex index, StructuredQueryBuilder.Region... regions)
StructuredQuerybuilder.geospatial(StructuredQueryBuilder.GeospatialIndex,
StructuredQueryBuilder.Region...)
. Matches an element,
element pair, element attribute, pair, or path specifying a
geospatial point that appears within one of the criteria
regions.index
- the container for the coordinates of the
geospatial pointregions
- the possible regions containing the
pointStructuredQueryDefinition near(int distance, double weight, StructuredQueryBuilder.Ordering order, StructuredQueryDefinition... queries)
StructuredQuerybuilder.near(int, double,
StructuredQueryBuilder.Ordering,
StructuredQueryDefinition...)
. Defines a NEAR query over
the list of query definitions with specified parameters.distance
- the proximity for the query termsweight
- the weight for the queryorder
- the ordering for the query termsqueries
- the query definitionsStructuredQueryDefinition near(StructuredQueryDefinition... queries)
StructuredQuerybuilder.near(StructuredQueryDefinition...)
.
Defines a NEAR query over the list of query definitions with
default parameters.queries
- the query definitionsStructuredQueryDefinition not(StructuredQueryDefinition query)
StructuredQuerybuilder.not
. Defines a NOT query
for a query definition. To negate a list of query definitions,
define an AND or OR query over the list and define the NOT query
over the AND or OR query.query
- the query definitionStructuredQueryDefinition notIn(StructuredQueryDefinition positive, StructuredQueryDefinition negative)
StructuredQuerybuilder.and
. Defines a not-in query
for the positive and negative query definitions. These query
definitions can each be an AND or OR query definition for complex
combinations of criteria.positive
- the query definition that includes
documentsnegative
- the query definition that excludes
documentsStructuredQueryDefinition or(StructuredQueryDefinition... queries)
StructuredQuerybuilder.and
. Defines an OR query
over the list of query definitions.queries
- the query definitionsStructuredQueryBuilder.Region point(double latitude, double longitude)
StructuredQuerybuilder.point
. Specifies a
geospatial point.latitude
- the latitude coordinatelongitude
- the longitude coordinateStructuredQueryBuilder.Region polygon(StructuredQueryBuilder.Point... points)
StructuredQuerybuilder.polygon
. Specifies a
geospatial region as an arbitrary polygon.points
- the list of points defining the perimeter
of the regionStructuredQueryDefinition term(double weight, java.lang.String... terms)
StructuredQuerybuilder.term(double, String...)
.
Matches documents containing the specified terms, modifying the
contribution of the match to the score with the weight.weight
- the multiplier for the match in the
document rankingterms
- the possible terms to matchStructuredQueryDefinition term(java.lang.String... terms)
StructuredQuerybuilder.term(String...)
. Matches
documents containing the specified terms.terms
- the possible terms to matchPojoQueryDefinition filteredQuery(StructuredQueryDefinition query)
query
- the query to mark as filteredCopyright © 2013-2019 MarkLogic Corporation.