Spring Data Solr

org.springframework.data.solr.core.query
Class Criteria

java.lang.Object
  extended by org.springframework.data.solr.core.query.Node
      extended by org.springframework.data.solr.core.query.Criteria
Direct Known Subclasses:
Crotch, SimpleStringCriteria

public class Criteria
extends Node

Criteria is the central class when constructing queries. It follows more or less a fluent API style, which allows to easily chain together multiple criteria.

Author:
Christoph Strobl, Philipp Jardas, Francisco Spaeth

Nested Class Summary
static class Criteria.OperationKey
           
static class Criteria.Predicate
          Single entry to be used when defining search criteria
 
Field Summary
static String CRITERIA_VALUE_SEPERATOR
           
static String WILDCARD
           
 
Constructor Summary
Criteria()
           
Criteria(Field field)
          Creates a new Criteria for the given field
Criteria(Function function)
           
Criteria(String fieldname)
          Creates a new Criteria for the Filed with provided name
 
Method Summary
 Crotch and(Node node)
          Combine two Nodes using and.
 Crotch and(String fieldname)
          Combine node with new Node for given fieldname using and.
 Criteria between(Object lowerBound, Object upperBound)
          Crates new Criteria.Predicate for RANGE [lowerBound TO upperBound]
 Criteria between(Object lowerBound, Object upperBound, boolean includeLowerBound, boolean includeUppderBound)
          Crates new Criteria.Predicate for RANGE [lowerBound TO upperBound]
 Criteria boost(float boost)
          Boost positive hit with given factor. eg. ^2.3
 Criteria contains(Iterable<String> values)
          Crates new Criteria.Predicate with leading and trailing wildcards for each entry
NOTE: mind your schema as leading wildcards may not be supported and/or execution might be slow.
 Criteria contains(String... values)
          Crates new Criteria.Predicate with leading and trailing wildcards for each entry
NOTE: mind your schema as leading wildcards may not be supported and/or execution might be slow.
 Criteria contains(String s)
          Crates new Criteria.Predicate with leading and trailing wildcards
NOTE: mind your schema as leading wildcards may not be supported and/or execution might be slow.
 Criteria endsWith(Iterable<String> values)
          Crates new Criteria.Predicate with leading wildcard for each entry
NOTE: mind your schema and execution times as leading wildcards may not be supported.
 Criteria endsWith(String... values)
          Crates new Criteria.Predicate with leading wildcard for each entry
NOTE: mind your schema and execution times as leading wildcards may not be supported.
 Criteria endsWith(String s)
          Crates new Criteria.Predicate with leading wildcard
NOTE: mind your schema and execution times as leading wildcards may not be supported.
 Criteria expression(String s)
          Crates new Criteria.Predicate allowing native solr expressions
 Criteria function(Function function)
          Creates Criteria.Predicate for given Function.
 Criteria fuzzy(String s)
          Crates new Criteria.Predicate with trailing ~
 Criteria fuzzy(String s, float levenshteinDistance)
          Crates new Criteria.Predicate with trailing ~ followed by levensteinDistance
 float getBoost()
          Boost criteria value
 Field getField()
          Target field
 Set<Criteria.Predicate> getPredicates()
           
 Criteria greaterThan(Object lowerBound)
          Crates new Criteria.Predicate for RANGE &#123;lowerBound TO *]
 Criteria greaterThanEqual(Object lowerBound)
          Crates new Criteria.Predicate for RANGE [lowerBound TO *]
 Criteria in(Iterable<?> values)
          Crates new Criteria.Predicate for multiple values (arg0 arg1 arg2 ...)
 Criteria in(Object... values)
          Crates new Criteria.Predicate for multiple values (arg0 arg1 arg2 ...)
 Criteria is(Iterable<?> values)
          Creates new Criteria.Predicate without any wildcards for each entry
 Criteria is(Object... values)
          Crates new Criteria.Predicate without any wildcards for each entry
 Criteria is(Object o)
          Crates new Criteria.Predicate without any wildcards.
 boolean isNegating()
           
 Criteria isNotNull()
          Crates new Criteria.Predicate for {@code !
 Criteria isNull()
          Crates new Criteria.Predicate for null values
 Criteria lessThan(Object upperBound)
          Crates new Criteria.Predicate for RANGE [* TO upperBound&#125;
 Criteria lessThanEqual(Object upperBound)
          Crates new Criteria.Predicate for RANGE [* TO upperBound]
 Criteria near(org.springframework.data.geo.Box box)
          Creates new Criteria.Predicate for {@code !
 Criteria near(org.springframework.data.geo.Circle circle)
          Creates new Criteria.Predicate for {@code !
 Criteria near(org.springframework.data.geo.Point location, org.springframework.data.geo.Distance distance)
          Creates new Criteria.Predicate for {@code !
 Criteria not()
          Negates current criteria usinng - operator
 Crotch or(Node node)
          Combine two Nodes using or.
 Crotch or(String fieldname)
          Combine node with new Node for given fieldname using and.
 Criteria sloppy(String phrase, int distance)
          Crates new Criteria.Predicate with trailing ~ followed by distance
 Criteria startsWith(Iterable<String> values)
          Crates new Criteria.Predicate with trailing wildcard for each entry
 Criteria startsWith(String... values)
          Crates new Criteria.Predicate with trailing wildcard for each entry
 Criteria startsWith(String s)
          Crates new Criteria.Predicate with trailing wildcard
NOTE: Strings will not be automatically split on whitespace.
 String toString()
           
static Criteria where(Field field)
          Static factory method to create a new Criteria for provided field
static Criteria where(Function function)
          Static factory method to create a new Criteria for function
static Criteria where(String fieldname)
          Static factory method to create a new Criteria for field with given name
 Criteria within(org.springframework.data.geo.Circle circle)
          Creates new Criteria.Predicate for {@code !
 Criteria within(org.springframework.data.geo.Point location, org.springframework.data.geo.Distance distance)
          Creates new Criteria.Predicate for {@code !
 
Methods inherited from class org.springframework.data.solr.core.query.Node
getParent, getSiblings, hasSiblings, isOr, isRoot, setParent, setPartIsOr
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

WILDCARD

public static final String WILDCARD
See Also:
Constant Field Values

CRITERIA_VALUE_SEPERATOR

public static final String CRITERIA_VALUE_SEPERATOR
See Also:
Constant Field Values
Constructor Detail

Criteria

public Criteria()

Criteria

public Criteria(Function function)
Parameters:
function -
Since:
1.1

Criteria

public Criteria(String fieldname)
Creates a new Criteria for the Filed with provided name

Parameters:
fieldname -

Criteria

public Criteria(Field field)
Creates a new Criteria for the given field

Parameters:
field -
Method Detail

where

public static Criteria where(String fieldname)
Static factory method to create a new Criteria for field with given name

Parameters:
fieldname - must not be null
Returns:

where

public static Criteria where(Function function)
Static factory method to create a new Criteria for function

Parameters:
function - must not be null
Returns:
Since:
1.1

where

public static Criteria where(Field field)
Static factory method to create a new Criteria for provided field

Parameters:
field - must not be null
Returns:

is

public Criteria is(Object o)
Crates new Criteria.Predicate without any wildcards. Strings with blanks will be escaped "string\ with\ blank"

Specified by:
is in class Node
Parameters:
o -
Returns:

is

public Criteria is(Object... values)
Crates new Criteria.Predicate without any wildcards for each entry

Specified by:
is in class Node
Parameters:
values -
Returns:

is

public Criteria is(Iterable<?> values)
Creates new Criteria.Predicate without any wildcards for each entry

Specified by:
is in class Node
Parameters:
values -
Returns:

isNull

public Criteria isNull()
Crates new Criteria.Predicate for null values

Specified by:
isNull in class Node
Returns:

isNotNull

public Criteria isNotNull()
Crates new Criteria.Predicate for !null values

Specified by:
isNotNull in class Node
Returns:

contains

public Criteria contains(String s)
Crates new Criteria.Predicate with leading and trailing wildcards
NOTE: mind your schema as leading wildcards may not be supported and/or execution might be slow. NOTE: Strings will not be automatically split on whitespace.

Specified by:
contains in class Node
Parameters:
s -
Returns:
Throws:
InvalidDataAccessApiUsageException - for strings with whitespace

contains

public Criteria contains(String... values)
Crates new Criteria.Predicate with leading and trailing wildcards for each entry
NOTE: mind your schema as leading wildcards may not be supported and/or execution might be slow.

Specified by:
contains in class Node
Parameters:
values -
Returns:
Throws:
InvalidDataAccessApiUsageException - for strings with whitespace

contains

public Criteria contains(Iterable<String> values)
Crates new Criteria.Predicate with leading and trailing wildcards for each entry
NOTE: mind your schema as leading wildcards may not be supported and/or execution might be slow.

Specified by:
contains in class Node
Parameters:
values -
Returns:
Throws:
InvalidDataAccessApiUsageException - for strings with whitespace

startsWith

public Criteria startsWith(String s)
Crates new Criteria.Predicate with trailing wildcard
NOTE: Strings will not be automatically split on whitespace.

Specified by:
startsWith in class Node
Parameters:
s -
Returns:
Throws:
InvalidDataAccessApiUsageException - for strings with whitespace

startsWith

public Criteria startsWith(String... values)
Crates new Criteria.Predicate with trailing wildcard for each entry

Specified by:
startsWith in class Node
Parameters:
values -
Returns:
Throws:
InvalidDataAccessApiUsageException - for strings with whitespace

startsWith

public Criteria startsWith(Iterable<String> values)
Crates new Criteria.Predicate with trailing wildcard for each entry

Specified by:
startsWith in class Node
Parameters:
values -
Returns:
Throws:
InvalidDataAccessApiUsageException - for strings with whitespace

endsWith

public Criteria endsWith(String s)
Crates new Criteria.Predicate with leading wildcard
NOTE: mind your schema and execution times as leading wildcards may not be supported. NOTE: Strings will not be automatically split on whitespace.

Specified by:
endsWith in class Node
Parameters:
s -
Returns:
Throws:
InvalidDataAccessApiUsageException - for strings with whitespace

endsWith

public Criteria endsWith(String... values)
Crates new Criteria.Predicate with leading wildcard for each entry
NOTE: mind your schema and execution times as leading wildcards may not be supported.

Specified by:
endsWith in class Node
Parameters:
values -
Returns:
Throws:
InvalidDataAccessApiUsageException - for strings with whitespace

endsWith

public Criteria endsWith(Iterable<String> values)
Crates new Criteria.Predicate with leading wildcard for each entry
NOTE: mind your schema and execution times as leading wildcards may not be supported.

Specified by:
endsWith in class Node
Parameters:
values -
Returns:
Throws:
InvalidDataAccessApiUsageException - for strings with whitespace

not

public Criteria not()
Negates current criteria usinng - operator

Specified by:
not in class Node
Returns:

fuzzy

public Criteria fuzzy(String s)
Crates new Criteria.Predicate with trailing ~

Specified by:
fuzzy in class Node
Parameters:
s -
Returns:

fuzzy

public Criteria fuzzy(String s,
                      float levenshteinDistance)
Crates new Criteria.Predicate with trailing ~ followed by levensteinDistance

Specified by:
fuzzy in class Node
Parameters:
s -
levenshteinDistance -
Returns:

sloppy

public Criteria sloppy(String phrase,
                       int distance)
Crates new Criteria.Predicate with trailing ~ followed by distance

Specified by:
sloppy in class Node
Parameters:
phrase -
distance -
Returns:

expression

public Criteria expression(String s)
Crates new Criteria.Predicate allowing native solr expressions

Specified by:
expression in class Node
Parameters:
s -
Returns:

boost

public Criteria boost(float boost)
Boost positive hit with given factor. eg. ^2.3

Specified by:
boost in class Node
Parameters:
boost -
Returns:

between

public Criteria between(Object lowerBound,
                        Object upperBound)
Crates new Criteria.Predicate for RANGE [lowerBound TO upperBound]

Specified by:
between in class Node
Parameters:
lowerBound -
upperBound -
Returns:

between

public Criteria between(Object lowerBound,
                        Object upperBound,
                        boolean includeLowerBound,
                        boolean includeUppderBound)
Crates new Criteria.Predicate for RANGE [lowerBound TO upperBound]

Specified by:
between in class Node
Parameters:
lowerBound -
upperBound -
includeLowerBound -
includeUppderBound -
Returns:

lessThan

public Criteria lessThan(Object upperBound)
Crates new Criteria.Predicate for RANGE [* TO upperBound&#125;

Specified by:
lessThan in class Node
Parameters:
upperBound -
Returns:

lessThanEqual

public Criteria lessThanEqual(Object upperBound)
Crates new Criteria.Predicate for RANGE [* TO upperBound]

Specified by:
lessThanEqual in class Node
Parameters:
upperBound -
Returns:

greaterThan

public Criteria greaterThan(Object lowerBound)
Crates new Criteria.Predicate for RANGE &#123;lowerBound TO *]

Specified by:
greaterThan in class Node
Parameters:
lowerBound -
Returns:

greaterThanEqual

public Criteria greaterThanEqual(Object lowerBound)
Crates new Criteria.Predicate for RANGE [lowerBound TO *]

Specified by:
greaterThanEqual in class Node
Parameters:
lowerBound -
Returns:

in

public Criteria in(Object... values)
Crates new Criteria.Predicate for multiple values (arg0 arg1 arg2 ...)

Specified by:
in in class Node
Parameters:
values -
Returns:

in

public Criteria in(Iterable<?> values)
Crates new Criteria.Predicate for multiple values (arg0 arg1 arg2 ...)

Specified by:
in in class Node
Parameters:
values - the collection containing the values to match against
Returns:

within

public Criteria within(org.springframework.data.geo.Point location,
                       org.springframework.data.geo.Distance distance)
Creates new Criteria.Predicate for !geodist

Specified by:
within in class Node
Parameters:
location - Point in degrees
distance -
Returns:

within

public Criteria within(org.springframework.data.geo.Circle circle)
Creates new Criteria.Predicate for !geodist.

Parameters:
circle -
Returns:
Since:
1.2

near

public Criteria near(org.springframework.data.geo.Box box)
Creates new Criteria.Predicate for !bbox with exact coordinates

Specified by:
near in class Node
Parameters:
box -
Returns:

near

public Criteria near(org.springframework.data.geo.Point location,
                     org.springframework.data.geo.Distance distance)
Creates new Criteria.Predicate for !bbox for a specified distance. The difference between this and within is this is approximate while within is exact.

Specified by:
near in class Node
Parameters:
location -
distance -
Returns:
Throws:
IllegalArgumentException - if location is null
InvalidDataAccessApiUsageException - if distance is negative

near

public Criteria near(org.springframework.data.geo.Circle circle)
Creates new Criteria.Predicate for !circle for a specified distance. The difference between this and within(Circle) is this is approximate while within is exact.

Parameters:
circle -
Returns:
Since:
1.2

function

public Criteria function(Function function)
Creates Criteria.Predicate for given Function.

Specified by:
function in class Node
Parameters:
function - must not be null
Returns:
Throws:
IllegalArgumentException - if function is null
Since:
1.1

getField

public Field getField()
Target field

Returns:
null if not set

isNegating

public boolean isNegating()
Returns:
true if not() criteria

getBoost

public float getBoost()
Boost criteria value

Returns:
Float.NaN if not set

getPredicates

public Set<Criteria.Predicate> getPredicates()
Returns:
unmodifiable set of all Criteria.Predicate

toString

public String toString()
Overrides:
toString in class Object

and

public Crotch and(Node node)
Description copied from class: Node
Combine two Nodes using and.

Specified by:
and in class Node
Returns:

and

public Crotch and(String fieldname)
Description copied from class: Node
Combine node with new Node for given fieldname using and.

Specified by:
and in class Node
Returns:

or

public Crotch or(Node node)
Description copied from class: Node
Combine two Nodes using or.

Specified by:
or in class Node
Returns:

or

public Crotch or(String fieldname)
Description copied from class: Node
Combine node with new Node for given fieldname using and.

Specified by:
or in class Node
Returns:

Spring Data Solr

Copyright © 2011-2014-2014 Pivotal Software, Inc.. All Rights Reserved.