com.arsdigita.search.intermedia
Class SimpleSearchSpecification

java.lang.Object
  extended bycom.arsdigita.search.intermedia.SearchSpecification
      extended bycom.arsdigita.search.intermedia.SimpleSearchSpecification
Direct Known Subclasses:
SimpleSearchSpecification

public class SimpleSearchSpecification
extends SearchSpecification

This class provides methods to make it easier to specify a search. These methods may be used in two ways, depending on the complexity of the search.

If the search is simple (searching for a single string in either the xml or raw content fields, with no joined tables, and only the standard fields selected) then a SimpleSearchSpecification object can be created to do the search. Search results can then be accessed by method getSearchPage. This allows using accessor methods in class SearchDataQuery to easily retrieve the returned fields.

If the search cannot be done by creating a SimpleSearchSpecification object, then the more general SearchSpecification object will have to be created to do the search. However, in that case, two static methods in this class (cleanSearchString and containsClause) can be used to help build the search query that is passed into SearchSpecification.

Version:
1.0
Author:
Joseph A. Bank (jbank@alum.mit.edu)
See Also:
Searchable, SearchSpecification, SearchDataQuery

Field Summary
static String versionId
           
 
Constructor Summary
SimpleSearchSpecification(String searchString)
          Create a SimpleSearchSpecification object to search for objects of any type that contain the specified searchString.
SimpleSearchSpecification(String object_type, String searchString)
          Create a SimpleSearchSpecification object to search for objects of the given type that contain the specified searchString.
 
Method Summary
static String cleanSearchString(String searchString, String joinString)
          Cleanup the search string by removing characters |&,-*;{}%_$?!()\:@.<>#^+=[]~` and by combining multiple words with a join string.
static String containsClause(String sc, String searchString, String xml_label, String raw_label)
          Build a containsClause for a search query.
 DataQuery getPage(int page)
          Execute a search, returning a page of search results.
 SearchDataQuery getSearchPage(int page)
          Similar to getPage but returns results as a SearchDataQuery object.
 void setSelect(String sql, String[] columns)
          Set the Sql select statement and columns used to do a search.
 
Methods inherited from class com.arsdigita.search.intermedia.SearchSpecification
getColumns, getMaxResultRows, getParameter, getRowsPerPage, getSelect, reformatSqlForPage, setMaxResultRows, setParameter, setRowsPerPage
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

versionId

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

SimpleSearchSpecification

public SimpleSearchSpecification(String object_type,
                                 String searchString)
Create a SimpleSearchSpecification object to search for objects of the given type that contain the specified searchString. If the string contains more than one word, the search will be for objects that contain all of the words.

Parameters:
object_type - The type of object to search.
searchString - The string to search for.

SimpleSearchSpecification

public SimpleSearchSpecification(String searchString)
Create a SimpleSearchSpecification object to search for objects of any type that contain the specified searchString. If the string contains more than one word, the search will be for objects that contain all of the words.

Parameters:
searchString - The string to search for.
Method Detail

containsClause

public static String containsClause(String sc,
                                    String searchString,
                                    String xml_label,
                                    String raw_label)
Build a containsClause for a search query. The returned contains clause will be of the form:
   (contains(sc.xml_content, 'searchString', xml_label) > 0 OR
    contains(sc.raw_content, 'searchString', raw_label) > 0)
 

Specifying null for either the label parameters inhibits the generation of the contains clause for the corresponding column. For example, if the xml_label was null, only the contains for the raw_content field would be generated. If both xml_label and raw_label are null an empty string is returned.

Parameters:
sc - alias for search_content table name. For example, if the query contained:
           select ... from search_content c ...
        
then sc would be the string "c".
searchString - The string to be searched. It should have either been processed by cleanSearchString before being passed into this method or otherwise known not to contain invalid characters or words. Single quote characters (i.e. ') are allowed in the search string (each single quote character is escaped by replacing it with two single quote characters when the contains clause is generated).
xml_label - A label used to identify the score for matching on the xml_content field. Would normally be "1". If null, then the contains clause for the xml_content field is not created.
raw_label - A label used to identify the score for matching on the raw_content field. Would normally be "2". If null, then the contains clause for the raw_content field is not created.
Returns:
An oracle interMedia sql contains clause for performing the search.

cleanSearchString

public static String cleanSearchString(String searchString,
                                       String joinString)
Cleanup the search string by removing characters |&,-*;{}%_$?!()\:@.<>#^+=[]~` and by combining multiple words with a join string.

Parameters:
searchString - Input search string to be cleaned.
joinString - The join string. Normally this will be " and " to generate a search for objects containing all words in the searchString.
Returns:
The cleaned up string.

setSelect

public void setSelect(String sql,
                      String[] columns)
Description copied from class: SearchSpecification
Set the Sql select statement and columns used to do a search.

Overrides:
setSelect in class SearchSpecification
Parameters:
sql - Sql select statement to perform the search. See example above.
columns - The names of columns returned by the search.

getPage

public DataQuery getPage(int page)
Execute a search, returning a page of search results. If there is a "next page" of results after the returned page, the number of rows returned will be the number of rows per page plus one. This allows determining if a "next page" link should be generated by counting the number of rows returned; i.e. if the total is greater than rowsPerPage) then there is a next page, otherwise there is not. A row that flags the presence of a next page, should not be displayed to the user because it will be the first row returned on the next page.

Overrides:
getPage in class SearchSpecification
Parameters:
page - The page of search results to retrieve (page==1 means first page).

getSearchPage

public SearchDataQuery getSearchPage(int page)
Similar to getPage but returns results as a SearchDataQuery object. SearchDataQuery provides get methods for the fields returned.

Parameters:
page - The page of search results to retrieve (page==1 means first page).


Copyright (c) 2004 Red Hat, Inc. Corporation. All Rights Reserved. Generated at July 20 2004:2337 UTC