org.openprivacy.reptile.search
Class SearchRequest

java.lang.Object
  |
  +--org.openprivacy.reptile.search.SearchRequest
Direct Known Subclasses:
AdvancedSearchRequest

public class SearchRequest
extends java.lang.Object

A SearchRequest is used to represent a new search we want to run on a SearchProvider. All search query abstraction is handled here.

All options need to be specified here before a search can be executed.

In order to execute a search provider on you just need to specify the fields you should search on. getFields().add( "title" ); ... and then specify a string or strings to search for as the criteria.

You can then specify the boolean operator for this request with the setBooleanOperator method.

In some situations this may not be enough information necessary for a SearchProvider to excute a search. For example if you need to restrict your information to a certain peergroup or some other functionaity which is specific to a provider.

There are two solutions for this:

  1. Implement a custom search request byte extending SearchRequest. You can then place any necessary additional information int your new class.
  2. Use the Criteria object to restrict items on a per field basis.

Either strategy is acceptable, you should just make the most appropriate decision for your situation.

Version:
$Id: SearchRequest.java,v 1.12 2002/02/24 22:45:07 burton Exp $
Author:
Kevin A. Burton

Field Summary
static java.lang.String ALL
          Comparison type.
static java.lang.String ALT_NOT_EQUAL
          Comparison type.
static int BOOLEAN_AND
          Boolean AND operator
static int BOOLEAN_OR
          Boolean OR operator
static java.lang.String CUSTOM
          Comparison type.
static java.lang.String DISTINCT
          Comparison type.
static java.lang.String EQUAL
          Comparison type.
static java.lang.String GREATER_EQUAL
          Comparison type.
static java.lang.String GREATER_THAN
          Comparison type.
static java.lang.String IN
          Comparison type.
static java.lang.String JOIN
          Comparison type.
static java.lang.String LESS_EQUAL
          Comparison type.
static java.lang.String LESS_THAN
          Comparison type.
static java.lang.String LIKE
          Comparison type.
static int NO_MAXCOUNT
           
static java.lang.String NOT_EQUAL
          Comparison type.
static java.lang.String NOT_IN
          Comparison type.
 
Constructor Summary
SearchRequest()
           
 
Method Summary
 void addCriteria(java.lang.Long criteria)
          Add a criteria to this request.
 void addCriteria(java.lang.String criteria)
          Add a criteria to this request.
 void addSearchField(java.lang.String field)
          Add a search field.
 void addSortOrder(java.lang.String field)
           
 void assertValid()
          Assert that this request is valid, that it specifies a criteria, etc.
 int getBooleanOperator()
          Get the default type of boolean operation this should support.
 java.lang.String getComparator()
          Get the value of comparator.
 java.util.List getCriteria()
           This represents the data you are searching for.
 org.apache.commons.collections.ExtendedProperties getExtendedProperties()
           Allows you to specify ExtendedProperties for this SearchRequest.
 int getMaxCount()
          Get the value of maxCount.
 java.util.List getSearchFields()
          Get the fields that this search applies to.
 java.util.List getSortOrder()
           Get the sort order for this SearchRequest.
 org.jdom.Element serialize()
          Serialize this as XML suitable for using as an XML results set.
 void setBooleanOperator(int booleanOperator)
          Set the value of booleanOperator.
 void setComparator(java.lang.String comparator)
          Set the value of comparator.
 void setCriteria(java.util.List criteria)
           
 void setMaxCount(int maxCount)
          Set the value of maxCount.
 void setSearchFields(java.util.List searchFields)
           
 void setSortOrder(java.util.List sortOrder)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BOOLEAN_OR

public static final int BOOLEAN_OR
Boolean OR operator

See Also:
Constant Field Values

BOOLEAN_AND

public static final int BOOLEAN_AND
Boolean AND operator

See Also:
Constant Field Values

EQUAL

public static final java.lang.String EQUAL
Comparison type.

See Also:
Constant Field Values

NOT_EQUAL

public static final java.lang.String NOT_EQUAL
Comparison type.

See Also:
Constant Field Values

ALT_NOT_EQUAL

public static final java.lang.String ALT_NOT_EQUAL
Comparison type.

See Also:
Constant Field Values

GREATER_THAN

public static final java.lang.String GREATER_THAN
Comparison type.

See Also:
Constant Field Values

LESS_THAN

public static final java.lang.String LESS_THAN
Comparison type.

See Also:
Constant Field Values

GREATER_EQUAL

public static final java.lang.String GREATER_EQUAL
Comparison type.

See Also:
Constant Field Values

LESS_EQUAL

public static final java.lang.String LESS_EQUAL
Comparison type.

See Also:
Constant Field Values

LIKE

public static final java.lang.String LIKE
Comparison type.

See Also:
Constant Field Values

CUSTOM

public static final java.lang.String CUSTOM
Comparison type.

See Also:
Constant Field Values

DISTINCT

public static final java.lang.String DISTINCT
Comparison type.

See Also:
Constant Field Values

IN

public static final java.lang.String IN
Comparison type.

See Also:
Constant Field Values

NOT_IN

public static final java.lang.String NOT_IN
Comparison type.

See Also:
Constant Field Values

ALL

public static final java.lang.String ALL
Comparison type.

See Also:
Constant Field Values

JOIN

public static final java.lang.String JOIN
Comparison type.

See Also:
Constant Field Values

NO_MAXCOUNT

public static final int NO_MAXCOUNT
See Also:
Constant Field Values
Constructor Detail

SearchRequest

public SearchRequest()
Method Detail

getCriteria

public java.util.List getCriteria()

This represents the data you are searching for.

For example if you want to search for 'linux' you would set the query to 'linux'.

In a lot of frameworks this is called a 'term'. I wanted to avoid use of that definition because it is slightly confusing in an API.

The way your criteria are handled is up to the SearchProvider. Generally it is a good idea to tokenize before hand but it is possible to let your SearchProvider to handle tokenizing for you.

This is required. By default it is 'null'

IMPLEMENTATION NOTE: Right now this only supports Strings. in the future we might create a ComplexSearchCriteria object so that you can specify more complex queries.


addCriteria

public void addCriteria(java.lang.String criteria)
Add a criteria to this request.

This is required.


addCriteria

public void addCriteria(java.lang.Long criteria)
Add a criteria to this request.

This is required.


setCriteria

public void setCriteria(java.util.List criteria)
See Also:
getCriteria(), addCriteria(java.lang.String)

getSearchFields

public java.util.List getSearchFields()
Get the fields that this search applies to. For example in a database query you could specify the fields 'title' and 'description'.


addSearchField

public void addSearchField(java.lang.String field)
Add a search field.

See Also:
getSearchFields()

setSearchFields

public void setSearchFields(java.util.List searchFields)
See Also:
getSearchFields()

getSortOrder

public java.util.List getSortOrder()

Get the sort order for this SearchRequest.

Basically this is a list of fields that we need to sort by.

Note that all SearchProviders do not need to support this.


addSortOrder

public void addSortOrder(java.lang.String field)
See Also:
getSortOrder()

setSortOrder

public void setSortOrder(java.util.List sortOrder)
See Also:
getSortOrder()

getMaxCount

public int getMaxCount()
Get the value of maxCount.

This is optional, by default we use NO_MAXCOUNT

Note that all SearchProviders may not implement this. For example at the time of this writing Lucene does not support this.


setMaxCount

public void setMaxCount(int maxCount)
Set the value of maxCount.

See Also:
getMaxCount()

getExtendedProperties

public org.apache.commons.collections.ExtendedProperties getExtendedProperties()

Allows you to specify ExtendedProperties for this SearchRequest. A SearchProvider implementation can support any type of named search properties what can be set here.

It is up to the SearchProvider implementation to document these correctly.


serialize

public org.jdom.Element serialize()
Serialize this as XML suitable for using as an XML results set.


assertValid

public void assertValid()
                 throws java.lang.Exception
Assert that this request is valid, that it specifies a criteria, etc.

java.lang.Exception

getBooleanOperator

public int getBooleanOperator()
Get the default type of boolean operation this should support. This is only really necessary if you have lists of strings as criteria.

See Also:
BOOLEAN_OR, BOOLEAN_AND

setBooleanOperator

public void setBooleanOperator(int booleanOperator)
Set the value of booleanOperator.


getComparator

public java.lang.String getComparator()
Get the value of comparator.


setComparator

public void setComparator(java.lang.String comparator)
Set the value of comparator.