public class Search extends Object
Search s1 = new Search("title", curTitle); // search where title equals value of curTitleSearch s2 = new Search("title", curTitle, Restriction.NOT_EQUALS); // search where title not equals value of curTitleSearch s2 = new Search(
new Restriction("title", curTitle),
new Order("title")
); // search where title equals value of curTitle and order is by title ascendingaddOrder(Order) and addRestriction(Restriction) allow restrictions and orders
to be added after the search was constructed, they will correctly handle duplicate values as well.isEmpty() and getRestrictionByProperty(String) and getRestrictionsProperties()
make it easier to get the restriction information out of the search object| Modifier and Type | Field and Description |
|---|---|
boolean |
conjunction
if true then all restrictions are run using AND, if false then all restrictions are run using OR
|
| Constructor and Description |
|---|
Search()
Empty constructor,
if nothing is changed then this indicates that the search should return
all items in default order
|
Search(Restriction restriction)
Defines a search which defines only a single restriction,
defaults to AND restriction comparison and returning all results
|
Search(Restriction[] restrictions)
Defines a search which defines only restrictions,
defaults to AND restriction comparisons and returning all results
|
Search(Restriction[] restrictions,
Order order)
Defines a search which defines restrictions and return ordering,
defaults to AND restriction comparisons and returning all results
|
Search(Restriction[] restrictions,
Order[] orders)
Defines a search which defines restrictions and return ordering,
defaults to AND restriction comparisons and returning all results
|
Search(Restriction[] restrictions,
Order[] orders,
long start,
long limit)
Defines a search which defines restrictions and return ordering and limits the returns,
defaults to AND restriction comparisons
|
Search(Restriction[] restrictions,
Order[] orders,
long start,
long limit,
boolean conjunction)
Defines a search which defines restrictions and return ordering and limits the returns,
also specifies the types of restriction comparisons (AND or OR)
|
Search(Restriction[] restrictions,
Order order,
long start,
long limit)
Defines a search which defines restrictions and return ordering and limits the returns,
defaults to AND restriction comparisons
|
Search(Restriction[] restrictions,
Order order,
long start,
long limit,
boolean conjunction)
Defines a search which defines restrictions and return ordering and limits the returns,
also specifies the types of restriction comparisons (AND or OR)
|
Search(Restriction restriction,
Order order)
Defines a search which defines only a single restriction and returns all items,
defaults to AND restriction comparisons
|
Search(Restriction restriction,
Order order,
long start,
long limit)
Defines a search which defines only a single restriction and limits the returns,
defaults to AND restriction comparisons
|
Search(Search search)
Copy constructor
Use this create a duplicate of a search object |
Search(String queryString)
Do a search using a query string
|
Search(String[] properties,
Object[] values)
Do a search of multiple properties which must equal corresponding values,
all arrays should be the same length
|
Search(String[] properties,
Object[] values,
boolean conjunction)
Do a search of multiple properties which must equal corresponding values,
control whether to do an AND or an OR between restrictions,
all arrays should be the same length
|
Search(String[] properties,
Object[] values,
int[] comparisons)
Do a search of multiple properties which are compared with corresponding values,
all arrays should be the same length
|
Search(String[] properties,
Object[] values,
int[] comparisons,
boolean conjunction)
Do a search of multiple properties which are compared with corresponding values,
all arrays should be the same length
|
Search(String[] properties,
Object[] values,
int[] comparisons,
Order[] orders)
Do a search of multiple properties which are compared with corresponding values,
sort the returned results in ascending order defined by specific sortProperties,
all arrays should be the same length
|
Search(String[] properties,
Object[] values,
int[] comparisons,
Order[] orders,
long firstResult,
long maxResults)
Do a search of multiple properties which are compared with corresponding values,
sort the returned results in ascending order defined by specific sortProperties,
all arrays should be the same length
|
Search(String property,
Object value)
Do a simple search of a single property which must equal a single value
|
Search(String property,
Object value,
int comparison)
Do a simple search of a single property with a single type of comparison
|
| Modifier and Type | Method and Description |
|---|---|
void |
addOrder(Order order) |
void |
addRestriction(Restriction restriction) |
static <T> T[] |
appendArray(T[] array,
T value)
Append an item to the end of an array and return the new array
|
static String |
arrayToString(Object[] array)
Utility method to convert an array to a string
|
protected Object |
clone() |
static <T> int |
contains(T[] array,
T value)
Checks to see if an array contains a value,
will return the position of the value or -1 if not found
|
static Search |
copy(Search original,
Search copy)
Make a copy of a search object
|
boolean |
equals(Object obj) |
long |
getLimit() |
Order[] |
getOrders()
Orders define the order of the returned results of a search, You can add as many orders as you like and they will
be applied in the array order
|
String |
getQueryString()
Defines a search query string which will be interpreted into search params,
If not null this indicates that this is a string based "search"
The search string is just text - there is no required structure nor any modifiers. |
Restriction |
getRestrictionByProperties(String[] properties)
Finds if there are any search restrictions with one of the given properties,
if so it returns the first of the found restriction,
otherwise returns null
|
Restriction |
getRestrictionByProperty(String property)
Convenient method to find restrictions by their property,
if there happens to be more than one restriction with a property then
only the first one will be returned (since that is an invalid state)
|
Restriction[] |
getRestrictions()
Restrictions define limitations on the results of a search, e.g. propertyA > 100 or property B = 'jump'
You can add as many restrictions as you like and they will be applied in the array order |
List<String> |
getRestrictionsProperties() |
Object |
getRestrictionValueByProperties(String[] properties)
Finds if there are any search restrictions with one of the given properties,
if so it returns the first non-null value in the found restrictions,
otherwise returns null
|
long |
getStart() |
int |
hashCode() |
boolean |
isConjunction()
if true then all restrictions are run using AND, if false then all restrictions are run using OR
|
boolean |
isEmpty() |
void |
reset()
Resets the search object to empty state
|
void |
setConjunction(boolean conjunction) |
void |
setLimit(long limit) |
void |
setOrders(Order[] orders) |
void |
setQueryString(String queryString) |
void |
setRestrictions(Restriction[] restrictions) |
void |
setStart(long start) |
String |
toString() |
public boolean conjunction
public Search()
public Search(Search search)
public Search(String queryString)
queryString - a search query string,
can be combined with other parts of the search objectqueryStringpublic Search(String property, Object value)
property - the name of the field (property) in the persisted objectvalue - the value of the property (can be an array of items)public Search(String property, Object value, int comparison)
property - the name of the field (property) in the persisted objectvalue - the value of the property (can be an array of items)comparison - the comparison to make between the property and the value,
use the defined constants from Restriction: e.g. EQUALS, LIKE, etc...public Search(String[] properties, Object[] values)
properties - the names of the properties of the objectvalues - the values of the properties (can be an array of items)public Search(String[] properties, Object[] values, boolean conjunction)
properties - the names of the properties of the objectvalues - the values of the properties (can be an array of items)conjunction - if true then all restrictions are run using AND,
if false then all restrictions are run using ORpublic Search(String[] properties, Object[] values, int[] comparisons)
properties - the names of the properties of the objectvalues - the values of the properties (can be an array of items)comparisons - the comparison to make between the property and the value,
use the defined constants from Restriction: e.g. EQUALS, LIKE, etc...public Search(String[] properties, Object[] values, int[] comparisons, boolean conjunction)
properties - the names of the properties of the objectvalues - the values of the properties (can be an array of items)comparisons - the comparison to make between the property and the value,
use the defined constants from Restriction: e.g. EQUALS, LIKE, etc...conjunction - if true then all restrictions are run using AND,
if false then all restrictions are run using ORpublic Search(String[] properties, Object[] values, int[] comparisons, Order[] orders)
properties - the names of the properties of the objectvalues - the values of the properties (can be an array of items)comparisons - the comparison to make between the property and the value,
use the defined constants from Restriction: e.g. EQUALS, LIKE, etc...orders - orders to sort the returned results bypublic Search(String[] properties, Object[] values, int[] comparisons, Order[] orders, long firstResult, long maxResults)
properties - the names of the properties of the objectvalues - the values of the properties (can be an array of items)comparisons - the comparison to make between the property and the value,
use the defined constants from Restriction: e.g. EQUALS, LIKE, etc...orders - orders to sort the returned results byfirstResult - the index of the first persisted result object to be retrieved (numbered from 0)maxResults - the maximum number of persisted result objects to retrieve (or <=0 for no limit)public Search(Restriction restriction)
restriction - define the limitations on the results of a search,
e.g. propertyA > 100 or property B = 'jump'public Search(Restriction[] restrictions)
restrictions - define the limitations on the results of a search,
e.g. propertyA > 100 or property B = 'jump'public Search(Restriction restriction, Order order)
restriction - define the limitations on the results of a search,
e.g. propertyA > 100 or property B = 'jump'order - define the order of the returned results of a search (only one order)public Search(Restriction[] restrictions, Order order)
restrictions - define the limitations on the results of a search,
e.g. propertyA > 100 or property B = 'jump'order - define the order of the returned results of a search (only one order)public Search(Restriction[] restrictions, Order[] orders)
restrictions - define the limitations on the results of a search,
e.g. propertyA > 100 or property B = 'jump'orders - define the order of the returned results of a search,
You can add as many orders as you like and they will be applied in the array orderpublic Search(Restriction restriction, Order order, long start, long limit)
restriction - define the limitations on the results of a search,
e.g. propertyA > 100 or property B = 'jump'order - define the order of the returned results of a search (only one order)start - the index of the first persisted result object to be retrieved (numbered from 0)limit - the maximum number of persisted result objects to retrieve (or <=0 for no limit)public Search(Restriction[] restrictions, Order order, long start, long limit)
restrictions - define the limitations on the results of a search,
e.g. propertyA > 100 or property B = 'jump'order - define the order of the returned results of a search (only one order)start - the index of the first persisted result object to be retrieved (numbered from 0)limit - the maximum number of persisted result objects to retrieve (or <=0 for no limit)public Search(Restriction[] restrictions, Order[] orders, long start, long limit)
restrictions - define the limitations on the results of a search,
e.g. propertyA > 100 or property B = 'jump'orders - define the order of the returned results of a search,
You can add as many orders as you like and they will be applied in the array orderstart - the index of the first persisted result object to be retrieved (numbered from 0)limit - the maximum number of persisted result objects to retrieve (or <=0 for no limit)public Search(Restriction[] restrictions, Order order, long start, long limit, boolean conjunction)
restrictions - define the limitations on the results of a search,
e.g. propertyA > 100 or property B = 'jump'order - define the order of the returned results of a search (only one order)start - the index of the first persisted result object to be retrieved (numbered from 0)limit - the maximum number of persisted result objects to retrieve (or <=0 for no limit)conjunction - if true then all restrictions are run using AND,
if false then all restrictions are run using ORpublic Search(Restriction[] restrictions, Order[] orders, long start, long limit, boolean conjunction)
restrictions - define the limitations on the results of a search,
e.g. propertyA > 100 or property B = 'jump'orders - define the order of the returned results of a search,
You can add as many orders as you like and they will be applied in the array orderstart - the index of the first persisted result object to be retrieved (numbered from 0)limit - the maximum number of persisted result objects to retrieve (or <=0 for no limit)conjunction - if true then all restrictions are run using AND,
if false then all restrictions are run using ORpublic void setStart(long start)
public long getStart()
public void setLimit(long limit)
public long getLimit()
public boolean isConjunction()
public void setConjunction(boolean conjunction)
public Restriction[] getRestrictions()
public void setRestrictions(Restriction[] restrictions)
public Order[] getOrders()
public void setOrders(Order[] orders)
public String getQueryString()
public void setQueryString(String queryString)
public void addRestriction(Restriction restriction)
restriction - add this restriction to the search filter,
will replace an existing restriction for a similar propertypublic void addOrder(Order order)
order - add this order to the search filter,
will replace an existing order for a similar propertypublic Restriction getRestrictionByProperty(String property)
property - the property to matchpublic List<String> getRestrictionsProperties()
public Restriction getRestrictionByProperties(String[] properties)
properties - an array of the properties (e.g. 'name','age') to find a value forpublic Object getRestrictionValueByProperties(String[] properties)
properties - an array of the properties (e.g. 'name','age') to find a value forpublic boolean isEmpty()
public void reset()
public static <T> int contains(T[] array,
T value)
T - array - any array of objectsvalue - the value to check forpublic static <T> T[] appendArray(T[] array,
T value)
array - an array of itemsvalue - the item to append to the end of the new arraypublic static String arrayToString(Object[] array)
array - any arrayprotected Object clone() throws CloneNotSupportedException
clone in class ObjectCloneNotSupportedExceptionpublic static Search copy(Search original, Search copy)
original - the search object to copycopy - the search object make equivalent to the original,
can be null to generate a new oneCopyright © 2007–2019 Sakai Project. All rights reserved.