Skip Headers

Oracle Internet File System Developer Reference
Release 9.0.1.1.0

Part Number A90093-02
Go To Table Of Contents
Contents
Go To Index
Index

Go to previous page Go to next page

8
Building Search Applications

This chapter describes how to build search applications with Oracle 9iFS selectors and searches.

What Is Searching?

Searching is a way to locate information stored in Oracle 9iFS. A search dynamically retrieves information from the repository based on criteria about the information. For example, you might search for all documents whose Name contains the word XML. The search returns the documents that meet that criteria at the time that it is executed. Subsequently, if new documents are created that meet the criteria, executing the search again automatically retrieves these documents as well.

Oracle 9iFS allows you to store, search, and work with information in an object-oriented manner. All information, including documents, folders, users, and groups, are defined as objects; that is, instances of Oracle 9iFS classes (e.g., Document, Folder, DirectoryUser, and DirectoryGroup). The Oracle 9iFS Java API allows you to work with these objects without having to know the complexities of how the information is stored in the database. For example, you can fetch a document, modify it, and save it in the repository as a single object instead of several rows across different tables. In the same manner, Oracle 9iFS allows you to query for information and work with query results in an object-oriented manner. Rather than constructing complex SQL queries that join the tables across which the information is stored, you can query for objects based on criteria about their class, attributes, content, and relationship to other objects.

The Oracle 9iFS Java API enables you to leverage both the power of searching against a relational database and the ease of use of an object-oriented programming environment. The API allows you to build queries and work with query results in an object-oriented manner using Java. When the query is executed, Oracle 9iFS automatically translates the query's Java construct into a SQL select statement and executes the query against the Oracle 9iFS schema. Therefore, you can query for and manipulate documents, folders, and other information as Java objects without having to know how their attributes and content are stored in the underlying database tables.

The Oracle 9iFS Java API provides two primary interfaces to query for objects in Oracle 9iFS:

Working with Selectors

Selectors provide a convenient way to execute simple queries in the repository. If you need to search against a single class of information with static criteria, then a selector will be the most convenient and quickest way to do so.

Example 8-1 A Simple Query

select all Documents whose Owner is 'WTalman' and whose ModifiedDate is greater 
than 'January 01, 2001' 

Selector Object Model

Selectors are constructed from three components: a string specifying the class, a string specifying the search criteria, and a SortSpecification object, which specifies how the results are to be sorted. Figure 8-1 illustrates the construct of a selector.

Figure 8-1 Selector Object Model


Text description of selcon.gif follows.
Text description of the illustration selcon.gif

Selectors operate under the following rules:

Selector APIs

The Oracle 9iFS Java API provides two classes in the oracle.ifs.beans package for constructing selectors.

Selector

The Selector class is used to construct and execute the search. Table 8-1 lists the key methods on the Selector class.


Table 8-1 Selector Key Methods
Method  Purpose 

getSearchClassname()
setSearchClassname() 

Determine what class will be searched.  

isRecursiveSearch() 

Determines if the selector should search recursively across subclasses. 

getSearchSelection()
setSearchSelection() 

Determine the search criteria.  

getSortSpecification()
setSortSpecification() 

Determines the sort criteria. 

getItems()
getItems(int index) 

Execute the search and return an array of LibraryObjects. 

getItemCount()
openItems()
closeItems()
resetItems()
nextItem() 

Work with the search results.

  • getItemCount() determines how many items are in the array of results.

  • openItems() opens a cursor on the selector.

  • nextItem() uses the cursor to fetch the next item in the array of results.

  • resetItems() is used to clear the results.

  • closeItems() closes the selector.

 

SortSpecification

The SortSpecification class is used to construct the sort criteria set on the selector with the setSortSpecification() method. Table 8-2 lists the key methods on the SortSpecification class.

Table 8-2 SortSpecification Key Methods
Method  Purpose 

addSortQualifiers() 

Adds an array of attributes and sort orders that will be used to sort the results.  

addSortQualifier() 

Adds a single attribute, sort order, and, optionally, the class and alias for the attribute to the SortSpecification. 

getSortAttributes() 

Returns an array of all attributes currently in the SortSpecification. 

getSortOrders() 

Returns an array of all sort orders currently in the SortSpecification. 

getDefaultClass()
setDefaultClass() 

Determine the default class for attributes in the SortSpecification. 

getDefaultAlias()
setDefaultAlias() 

Determine the default alias for attributes in the SortSpecification. 

Constructing and Executing a Selector

To construct a selector, execute it, and retrieve the query results, follow these steps:

  1. Construct a selector.

  2. Specify the class name.

  3. Specify if any subclasses of this class should be included.

  4. Specify the query criteria.

  5. Construct a SortSpecification and set it on the Selector to specify sort criteria.

  6. Execute the query and retrieve the query results.

Construct a Selector

The first step is to instantiate the Selector class.

Selector selector = new Selector();



Note:

Instances of this class do not persist. To use the same selector in more than one session, consider using a SelectorObject, which can be saved. For more information on this class, consult the Javadoc for oracle.ifs.beans.SelectorObject. 


Specify the Class Names

Specify the names of the classes that the query should select, such as FOLDER and DOCUMENT. The classes specified will be included in the SQL FROM clause generated by Oracle 9iFS. In this case, the selector will query for instances of the Attribute class.

selector.setSearchClassname("ATTRIBUTE");

Specify whether Subclasses Are Included

Specify if the selector should query recursively across any subclasses of the specified classes.

selector.setRecursiveSearch(false);

Specify the Query Criteria

Specify the query criteria by constructing a string that will constitute the SQL WHERE clause (without the word "WHERE"), then pass the string to the setSearchSelection() method on Selector. In this case, the selector will search for all instances of the ATTRIBUTE class whose DATATYPE is Boolean.

s = "DATATYPE = " + Attribute.ATTRIBUTEDATATYPE_BOOLEAN;
selector.setSearchSelection(s);

Specify the Sort Criteria

Construct a SortSpecification to hold the sort order criteria for the query results. The attributes specified in the SortSpecification must be attributes on the class specified for the selector.

  1. The method new SortSpecification() is called to instantiate a SortSpecification. The SortSpecification object will hold all of the sort criteria.

  2. The method addSortQualifiers() is called on the SortSpecification to create an array of attributes and sort orders in the SortSpecification. In this case, the selector sort the results of the search by the NAME and REQUIRED attributes on the ATTRIBUTE class.

  3. The setSortSpecification() method is called on the selector to add the sort criteria to the search.

    ss = new SortSpecification();
    ss.addSortQualifiers(new String[] {"NAME", "REQUIRED"}, new boolean[] 
    {false, true});
    selector.setSortSpecification(ss);
    

Execute the Query and Fetch the Query Results

There are two ways to execute a selector and retrieve query results:

  1. Using an Array

  2. Using a Cursor

Using an Array

You can call the getItems() method to execute the selector and work with the query results as an array. Subsequently, you can loop through the array to retrieve each query result.

LibraryObject[] results = selector.getItems();
LibraryObject lo;

int count = (results == null) ? 0 : results.length;
for (int i = 0; i < count; i++)
{

lo = results[i];

}

You can fetch specific items from the array by specifying their index position in the getItems() method.

LibraryObject lo = selector.getItems(i);
Using a Cursor

If you expect your search to return many results, but you don't want to get them all at once, you can use a cursor.

  1. First, reset the cursor by calling the resetItems() method.

  2. Open a cursor on the search by calling the openItems() method on the selector.

  3. The getItemCount() method is a convenient way to determine the number of results returned by the query.

  4. Cycle through individual items by calling the nextItem() method on the selector.

  5. When finished, the closeItems() method is called on the selector to close the search after cursor-based access.

    selector.resetItems(); 
    selector.openItems();
    
    int count = selector.getItemCount();
    LibraryObject lo;
    
    for (int i = 0; i < count; i++) 
    {
      lo = selector.nextItem(); 
    }
    
    selector.closeItems(); 
    

Sample Code

Example 8-2 illustrates how to construct and execute a selector to query for all Attributes in Oracle 9iFS whose datatype is Boolean and to sort the results, as in the following SQL query:

SELECT * FROM ATTRIBUTE WHERE DATATYPE = BOOLEAN 
ORDER BY NAME DESC, REQUIRED

Example 8-2 Constructing and Executing a Selector

  1. Construct a selector.

    Selector selector = new Selector(session);
    
    
    
  2. Specify the class name.

    selector.setSearchClassname("ATTRIBUTE");
    
    
    
  3. Specify if any subclasses should be included.

    selector.setRecursiveSearch(false);
    
    
    
  4. Specify the query criteria.

    String s = "DATATYPE = " + 
    
          Attribute.ATTRIBUTEDATATYPE_BOOLEAN; 
    
    
    selector.setSearchSelection(s);
    
  5. Construct a SortSpecification to specify the sort order for the query results.

    SortSpecification ss = new SortSpecification();
    ss.addSortQualifiers(new String[] {"NAME", "REQUIRED"},
                         new boolean[] {false, true}); 
    selector.setSortSpecification(ss);
    
    
    
  6. Execute the query and retrieve the query results.

    LibraryObject[] attributes = selector.getItems();
    
    
  7. Loop through the results.

    Attribute att;
    int count = (attributes == null) ? 0 : attributes.length;
    for (int i = 0; i < count; i++) 
    { 
      att = (Attribute) attributes[i]; 
    }
    
    
  8. Fetch the first and the last objects in the results by using an index.

    att = (Attribute) selector.getItems(0); 
    att = (Attribute) selector.getItems(count - 1);
    
    
  9. Use a cursor to fetch results.

    selector.resetItems(); 
    selector.openItems();
    count = selector.getItemCount();
    
    for (int i = 0; i < count; i++) 
    { 
       attribute = (Attribute) selector.nextItem(); 
    } 
    
    

Working with Searches

Using a selector is sufficient for querying a single class of information with simple query criteria. However, selectors do not allow you to construct queries that join multiple classes, specify content and relationship criteria, or use bind variables.

Searches provide a more robust interface for constructing and executing complex queries in the repository. Searches can query against multiple classes of information based on criteria about attributes, content, folders, other relationships, and arbitrary metadata. You can dynamically assemble the components of a search and pass in bind variables. You can also save search criteria persistently so that it can be used to execute the search later.

Example 8-3 A Complex Query

find all Documents and Folders that are in my Home Folder, whose ModifiedDate is 
less than <VariableDate>, and whose Name contains 'XML' or whose Content 
contains 'XML'

Search Object Model

The Oracle 9iFS Search object model uses four primary Java objects to construct and execute queries, manipulate search results, and save search criteria:

SearchSpecification

The Search object model enables you to assemble complex queries in an object-oriented manner using SearchSpecifications. A SearchSpecification is a Java construct that is used to dynamically assemble the components of the query. Figure 8-2, "Search Object Model" illustrates how each component of the SQL select statement for your query against the repository can be expressed as a Java object, including the FROM clause, the WHERE clause, each EXPRESSION in the WHERE clause, and the ORDER BY clause. These various components are assembled into a SearchSpecification, which is then passed to a Search object that is used to execute the query. When Oracle 9iFS executes the query, it automatically generates the SQL select statement and runs the query against the repository. Subsequently, Oracle 9iFS returns the results of the query as an array of objects, which you can read and manipulate.

Figure 8-2 Search Object Model


Text description of srchcon.gif follows.
Text description of the illustration srchcon.gif

Table 8-3 illustrates how the components of a Search Specification map to the components of a SQL query.



Table 8-3 SQL to Java Comparison

SELECT <result> FROM <list> 

SearchClassSpecification 

WHERE 

SearchQualification 

SesarchClause 

<expression> 

AttributeQualification, FolderRestrictQualification, ContextQualification, ExistenceQualification, FreeFormQualification, or PropertyQualification 

<join> 

JoinQualification 

SearchClause 

<expression> 

AttributeQualification, FolderRestrictQualification, ContextQualification, ExistenceQualification, FreeFormQualification, or PropertyQualification 

<join> 

JoinQualification 

<expression> 

AttributeQualification, FolderRestrictQualification, ContextQualification, ExistenceQualification, FreeFormQualification, or PropertyQualification 

ORDER BY <list> 

SearchSortSpecification 

In this manner, the Oracle 9iFS Search interface enables you to programmatically assemble complex queries in an object-oriented manner. Using a Java structure to define your query gives you the flexibility to manipulate each component, dynamically modify the query, and run it multiple times against the repository. It also frees you from having to know the complexities of the underlying Oracle 9iFS schema.

Oracle 9iFS uses the following Java objects to construct the components of a SearchSpecification:

Figure 8-3 SearchSpecification Components


Text description of srchspec.gif follows.
Text description of the illustration srchspec.gif

Figure 8-4 SearchQualification Assembly


Text description of srchqual.gif follows.
Text description of the illustration srchqual.gif

Search

The Oracle 9iFS Search object model provides another type of object, Search, to execute the query. Once the SearchSpecification is assembled, it is used to create a new search. The search is then used to:

  1. Pass in any late bind variables for the search criteria.

  2. Specify a language for the search.

  3. Execute the query.

  4. Retrieve the results.

SearchResultObject

When a search is executed, Oracle 9iFS returns as an array of result hits for each object that met the search criteria. The result hits are sorted in the array according to the sort criteria specified in the SearchSpecification. Each result hit is represented in the array by a SearchResultObject. The SearchResultObject can be used to retrieve the actual object that incurred the result hit.

The objects returned are instances of the result classes specified in the SearchClassSpecification. Each object consists of any attributes and content pertaining to the object's class.

By retrieving the object from the SearchResultObject, a search application can display and manipulate any of the object's attributes and content without having to make a second call to retrieve the object from the repository. However, if the search application needs to display or manipulate related objects (e.g., a parent folder), then the application needs to perform a second operation to retrieve the related object from the repository.

SearchObject

SearchSpecifications can be saved persistently in Oracle 9iFS as SearchObjects. SearchObjects store the search criteria so that users can reconstruct and execute the search at any time. Since only the search criteria is saved, the search will dynamically return the objects that currently meet the search criteria.

SearchObjects provide a powerful means for user's to access information in the repository. For example, SearchObjects could be defined to locate information pertaining to a particular topic by storing criteria about attributes and content which indicate relevance to that topic. Researchers could use the SearchObjects to more easily find information on the topic. SearchObjects could also be used to implement virtual folders that dynamically organize the repository into sets of objects that have common attributes, content, or relationships. As new objects are created in the repository, they will automatically be referenced in the virtual folders to which they pertain. In this manner, SearchObjects provide a powerful way to organize the repository without requiring users to manually place objects in folders.

Since the SearchObject class extends PublicObject, users can share SearchObjects by applying AccessControlLists. AccessControlLists specify how the SearchObject can be accessed by users and groups. SearchObjects can also be foldered to make them more accessible to users.

To learn more about applying AccessControlLists to PublicObjects, see Chapter 15, "Security".



NOTE:

The clients in this release of Oracle 9iFS do not support accessing SearchObjects. You must build a custom user interface which allows users to work with SearchObjects. 


Search APIs

The Oracle 9iFS Java API provides a set of Java classes for constructing and executing searches, and working with search results in custom applications. The oracle.ifs.search package includes the following Java classes for constructing the search:

The oracle.ifs.beans package includes the following two Java classes for executing the search, retrieving the search results, and saving the search criteria:

SearchSpecification

SearchSpecification is an abstract class for assembling all components of the search. AttributeSearchSpecification and ContextSearchSpecification extend this class. You do not instantiate the SearchSpecification class, but instead instantiate either of its subclasses depending on the search criteria.



Note:

The SearchSpecification can be used to create a custom SQL View of objects in the repository. For instructions on creating this view, consult the Oracle9i Database Administrator's Guide


AttributeSearchSpecification

The AttributeSearchSpecification class is used to construct searches that do not contain criteria about the content of documents.

Oracle 9iFS automatically optimizes the search in accordance with the nature of its criteria. A search that does not include content criteria (e.g., "find all documents whose owner is 'user1'") performs better if constructed with an AttributeSearchSpecification than if constructed with a ContextSearchSpecification.

Table 8-4 lists the most commonly used methods of the AttributeSearchSpecification class.


Table 8-4 AttributeSearchSpecification Methods

getSearchClassSpecification()
setSearchClassSpecification()
 

Establishes the SearchClassSpecification that specifies the classes of information that will be searched. 

getSearchQualification()

setSearchQualification() 

Establish the SearchQualification that specifies the classes of information that will be searched.  

getSearchSortSpecification

setSearchSortSpecification() 

Establish the SearchSortSpecification that specifies the sort order of the search results.  

ContextSearchSpecification

The ContextSearchSpecification class is used when constructing a search that contains content criteria (e.g., "find all documents whose content contains 'XML'"). The SearchQualification component of a ContextSearchSpecification should have at least one ContextQualification.


Note:

Context is a former name of Oracle Text, the database feature used optionally by Oracle 9iFS to index the contents of documents in the repository. 


Since ContextSearchSpecification extends AttributeSearchSpecification, it possesses the same methods defined in Table 8-4. Table 8-5 lists the additional methods provided with the ContextSearchSpecification class.


Table 8-5 ContextSearchSpecification Methods

setContextClassname()

getContextClassname() 

Specify the class that will be searched based on the criteria specified in a ContextQualification. By default, Oracle 9iFS stores the content of all Documents as an instance of ContentObject. The ContentObject is the class that possesses an attribute, Content, which stores the actual content of the document. 

SearchClassSpecification

The SearchClassSpecification class is used to specify the classes that will be searched. You can also specify if the search should execute recursively across any subclasses of the specified classes. When a search includes criteria that joins multiple classes of information, the SearchClassSpecification allows you to specify which classes should be returned. Table 8-6 lists the most commonly used methods of the SearchClassSpecification class.


Table 8-6 SearchClassSpecification Methods

addSearchClass()

addSearchClasses()

getSearchClassnames() 

Determine the specific classes of information against which the content criteria will be applied. They are also used to specify aliases for those classes. 

getSearchClassAliases() 

Retrieves a list of aliases for the classes in the SearchClassSpecification. 

getRecursiveBehavior() 

Determines if the search should be applied recursively across the classes' subclasses. 

addResultClass()

getResultClassnames() 

Determine the classes of information that should be returned by the search. Any class of information returned by the search, must also be specified in the Classes attribute.  

SearchQualification

SearchQualification is an abstract class for assembling the search criteria. AttributeQualification, FolderRestrictQualification, ContextQualification, ExistenceQualification, FreeFormQualification, PropertyQualification, JoinQualification and SearchClause extend this class, and are used to construct different types of conditions. All conditions are ultimately combined together into a single SearchQualification that is passed to the setSearchQualification() method on the SearchSpecification.

AttributeQualification

The AttributeQualification class is used to construct a condition about the value of an attribute.

Table 8-7 lists the most commonly used constants and methods of the AttributeQualification class.


Table 8-7 AttributeQualification Constants and Methods

getAttributeName()

getAttributeClassname()

setAttribute() 

Determine the attribute that serves as the basis for the condition. 

getOperatorType()

setOperatorType()

EQUAL

GREATER_THAN

GREATER_THAN_EQUAL

IS_NOT_N ULL

IS_NULL

LESS_THAN

LESS_THAN_EQUAL

LIKE

NOT_EQUAL 

Determine the operator which compares the attribute and the value specified.

The constants represent the comparison operator in the condition. Currently, Oracle 9iFS only supports the operators 'IS_NULL', 'IS_NOT_NULL', and 'LIKE' for Strings. 

getValue()

setValue() 

Determine the value against which the attribute is being compared.

NOTE: When using the operator LIKE, you can include valid SQL wildcards (e.g., '%' and '_') in the value. 

getDateComparisonLevel()

setDateComparisonLevel()

DATE_COMP_DAY

DATE_COMP_HOUR

DATE_COMP_MIN

DATE_COMP_MONTH

DATE_COMP_SEC

DATE_COMP_YEAR 

For attributes with a datatype of Date, these methods and constants specify the level to which Oracle 9iFS will compare the attribute and the date value.

For example, an AttributeQualification can be used to compare the 'CreateDate' Attribute against a system generated date, 'SYSDATE', which is set to 'March 21, 2001 08:30 am' (e.g., 'CreateDate < SYSDATE'). However, you may want to retrieve all information that was created prior to March 21, 2001, meaning on or prior to March 20, 2001 23:59 pm. To prevent the AttributeQualification from returning information created on March 21, 2001 at 7:00 am, you can set the date comparison level to DATE_COMP_DAY. 

isCaseIgnored()

setCaseIgnored() 

Determine if the condition should be case sensitive.

For example, if IgnoreCase is set to 'true', then the condition NAME = 'XML' will not return information whose NAME is 'xml'. 

ContextQualification

The ContextQualification class is used to construct a condition about the content of documents.

Table 8-8 lists the most commonly used constants and methods of the ContextQualification class.


Table 8-8 ContextQualification Constants and Methods

getName()

setName() 

Determine the Name of the ContextQualification. The name can be used to include the relevancy score generated by Oracle Text as sort criteria. 

ORDER_PREFIX 

Used when including the relevancy score generated by Oracle Text in SearchSortSpecification. The constant is attached to the Name of the ContextQualification, and is used by Oracle 9iFS to generate the correct SQL syntax in the ORDER BY clause. 

getQuery()

setQuery() 

Determine the text query string that is passed to Oracle Text as the criteria for the content search. The query string is passed by Oracle 9iFS, unmodified, into the text string argument of the CONTAINS() SQL function, which calls Oracle Text to execute a content query. Since it is not modified by Oracle 9iFS, the query string can include any number of tokens, expansion operators, and join operators in accordance with the syntax required by Oracle Text.  


Note:

For more information about syntax rules for text query strings against Oracle Text, see the Oracle9i SQL Reference Manual


FolderRestrictQualification

The FolderRestrictQualification is used to construct a condition that the search should be limited to a specified folder or folder branch.

Table 8-9 lists the most commonly used methods of the FolderRestrictQualification class.


Table 8-9 FolderRestrictQualification Methods

getStartingFolder()

setStartFolder() 

Determine to which folder the search should be restricted. If searching across multiple levels of a branch in a folder hierarchy, the StartFolder is the top node in the branch. 

isMultiLevel()

setMultiLevel() 

Determine if the search will traverse subfolders of the StartFolder. 

getSearchClassname()

setSearchClassname() 

Determine the class of information that will be searched for within the folder. The Search class is automatically included in the SearchSpecification along with the FolderRestrictQualification.  

ExistenceQualification

The ExistenceQualification is used to construct a condition that an attribute's value matches one of a list of possible values, or that an attribute's value matches the value of an attribute of another object.

Table 8-10 lists the most commonly used methods of the ExistenceQualification class.


Table 8-10 ExistenceQualification Methods

getLeftAttributeName()

getLeftAttributeClassname()

setLeftAttribute() 

Determine the attribute on the left-hand side of the condition, whose value must match one of the values specified in the right-hand side of the condition. 

getRightAttributeName()

getRightAttributeClassname()

setRightAttribute() 

Determine the list of values on the right-hand side of the condition via an attribute. 

getRightAttributeValue()

isRightAttributeValue()

setRightAttributeValue() 

Determine the list of values on the right-hand side of the condition via an AttributeValue[] array. 

PropertyQualification

The PropertyQualification represents a condition about a property in the object's PropertyBundle.

Table 8-11 lists the most commonly used methods of the PropertyQualification class.


Table 8-11 PropertyQualification Methods

getPropertyName()

setPropertyName() 

Determine the name of the property being searched. 

getOperatorType()

setOperatorType() 

Determine the operator used to compare the property against the value specified. The methods receive constants (e.g., EQUAL) defined on AttributeQualification to represent the comparison operator in the condition. Currently, Oracle 9iFS only supports the operators 'IS_NULL', 'IS_NOT_NULL', and 'LIKE' for Strings. 

getValue()

setValue() 

Determine the value against which the attribute is being compared. When using the operator LIKE, you can include valid SQL wildcards (e.g., '%' and '_') in the value. 

getDateComparisonLevel()

setDateComparisonLevel() 

For properties with a datatype of Date, these methods specify the level to which Oracle 9iFS will compare the attribute and the date value. The methods receive constants (e.g., DATE_COMP_DAY) defined on AttributeQualification to represent the different levels of comparison.

For example, a PropertyQualification can be used to compare the 'PublicationDate' property against a system-generated date, 'SYSDATE', which is set to 'March 21, 2001 08:30 am' (e.g., 'PublicationDate < SYSDATE'). However, you may want to retrieve all information that was created prior to March 21, 2001, meaning on or prior to March 20, 2001 23:59 pm. To prevent the AttributeQualification from returning information created on March 21, 2001 at 7:00 am, you can set the date comparison level to DATE_COMP_DAY. 

isCaseIgnored()

setCaseIgnored() 

Determine if the condition should be case sensitive.

For example, if IgnoreCase is set to 'true', then the condition NAME = 'XML' will not return information whose NAME is 'xml'. 

isLateBound()

getLateBoundDataType()

setLateBoundDataType() 

Specify that the value of the property will be supplied with a late bind variable. 

setClassname()

getClassname() 

Determine the class of the information that possesses the PropertyBundle. The Search class is automatically included in the SearchSpecification along with the PropertyQualification. 

FreeFormQualification

The FreeFormQualification class is used to include any other types of conditions via a free-form string of SQL syntax.

Table 8-12 lists the most commonly used methods of the FreeFormQualification class.


Table 8-12 FreeFormQualification Methods

getSQLExpression()

setSQLExpression() 

Determine the String that contains the SQL expression 

JoinQualification

JoinQualification is used to construct a join when including conditions about a related object.

Table 8-13 lists the most commonly used methods of the JoinQualification class.


Table 8-13 JoinQualification Methods

getLeftAttributeName()

getRightAttributeName()

setLeftAttribute()

setRightAttribute() 

Determine the left-hand side and right-hand side of the join condition. 

getLeftAttributeClassname()

getRightAttributeClassname() 

Retrieves the class for either attribute specified in the join condition. 

SearchClause

The SearchClause is used to assemble the components of the SearchQualification. SearchClause combines conditions using logical operators. SearchClause can combine other SearchClauses, allowing you to nest multiple SearchClauses into a single SearchQualification.

Table 8-14 lists the most commonly used constants and methods of the SearchClause class.


Table 8-14 SearchClause Constants and Methods

getLeftSearchQualification()

setLeftSearchQualification() 

Determine the condition on the left-hand side of the SearchClause.  

getOperatorType()

setOperatorType()

AND

OR

NOT 

Determine the operator that will be used to combine the conditions in the SearchClause.

These constants are used to represent the operator in the clause. 

getRightSearchQualification()

setRightSearchQualification() 

Determine the condition on the right-hand side of the SearchClause. 

SearchSortSpecification

SearchSortSpecification constructs the sort order for the search results.

Table 8-15 lists the most commonly used constants and methods of the SearchSortSpecification class.


Table 8-15 SearchSortQualification Constants and Methods

add() 

Adds one or more sort criteria to the SearchSortSpecification. 

getClassnames() 

Determines the classes of the attributes that will be used to order the search results. 

getAttributesNames() 

Determines the attributes that will be used to order the search results. 

getOrders()

ASCENDING

DESCENDING 

Determine the order of the results, ascending or descending, based on the attribute.

These constants are used to represent the order specified in the SearchSortSpecification. 

Search

The Search class is used to execute the query and retrieve the results. When the SearchSpecification is constructed, it is passed to the setSearchSpecification() method on Search. Subsequently, the open() method is called to pass in bind variables and execute the search. At this time, Oracle 9iFS compiles a SQL select statement from the SearchSpecification and executes the query against the Oracle 9iFS schema.

Table 8-16 lists the most commonly used methods of the Search class.


Table 8-16 Search Attributes Methods

getSearchSpecification()

setSearchSpecification() 

Determine the SearchSpecification that holds the query criteria for the Search. 

open() 

Passes in any late bind variables, executes the query, and opens a cursor to the search results. 

close() 

Closes the cursor on the search. 

dispose() 

Closes the cursor on the search and fully releases its resources. Once disposed, a Search cannot be reopened(). 

next()
getItemCount() 

Retrieve the results of the search. 

SearchResultObject

The SearchResultObject class is used to work with the results of the search. The next() method returns a SearchResultObject which represents a single search result. The SearchResultObject is used to retrieve the object which met the search criteria.

Table 8-17 lists the most commonly used methods of the SearchResultObject class.


Table 8-17 SearchResultObject Methods

getLibraryObject() 

Returns the LibraryObject that incurred the search result hit; e.g., SearchResultObject. 

getScore() 

Returns the score generated by Oracle Text to indicate the document's relevance to the content criteria specified in a ContextQualification. 

SearchObject

The SearchObject class is used to save search criteria persistently in the repository. The SearchObject stores a SearchSpecification so that it can be used to reconstruct and execute a search multiple times.

Table 8-18 lists the most commonly used methods of the SearchObject class.

Table 8-18 SearchObject Methods

getSearch() 

Constructs a new Search from the SearchSpecification stored by the SearchObject. 

getSearchSpecification()
setSearchSpecification() 

Determines the SearchSpecification which represents the search criteria stored in the SearchObject. 

Constructing and Executing a Search

To construct, execute, and save a search, your application performs these tasks:

  1. Construct a SearchSpecification

  2. Construct a SearchClassSpecification

  3. Construct a SearchQualification for Each Condition

  4. Combine the Conditions into a Single SearchQualification

  5. Construct a SearchSortSpecification

  6. Construct and Execute a Search

  7. Fetch the SearchResultObjects

  8. Save the SearchSpecification as a SearchObject

Construct a SearchSpecification

The first step in building a search application is constructing a SearchSpecification. If the query includes Document content criteria, you will construct a ContextSearchSpecification. Otherwise, you will construct an AttributeSearchSpecification.

Example 8-4 Constructing an AttributeSearchSpecification

AttributeSearchSpecification asp = new AttributeSearchSpecification();

Example 8-5 Constructing an ContextSearchSpecification

ContextSearchSpecification csp = new ContextSearchSpecification();

Construct a SearchClassSpecification

To specify the classes of information that will be searched and included in the search results, construct a SearchClassSpecification and pass it to the setClassSpecification() method on the SearchSpecification.

Example 8-6 Constructing a SearchClassSpecification

// Following code constructs a SearchClassSpecification 
// to represent the SELECT and FROM clauses in a query.
//
//   e.g.,  SELECT Document, Category 
//         FROM Document, Category, Folder

  1. Create an array for the class names, aliases, and recursive behavior

    String [] classNames = new String[] {"Document", "Category", "Folder"};
    String [] aliasNames = new String[] {"d", "c", "f"};
    Boolean [] delBvrs = new Boolean [] {false, false, false};
    Boolean [] recBvrs = new Boolean [] {false, true, false};
    
    
  2. Construct the SearchClassSpecification and pass in the class names.

    SearchClassSpecification scp = 
         new SearchClassSpecification(classNames, aliasNames, delBvrs, recBvrs); 
    
    
  3. Specify the classes of information to be returned by the search.

    scp.addResultClass("Document");
    scp.addResultClass("Category");
    
    
  4. Add the SearchClassSpecification component to the SearchSpecification.

    asp.setSearchClassSpecification(scp);
    

Construct a SearchQualification for Each Condition

For each condition in the query criteria, construct an instance of the appropriate SearchQualification subclass:

AttributeQualification

To construct a condition based on the value of an attribute, you will create an AttributeQualification. To construct an AttributeQualification, specify the three primary components of the condition: the attribute, the comparison operator, and the value.

Example 8-7 Constructing an AttributeQualification with a String Value

  1. Construct the AttributeQualification.

    AttributeQualification aq1 = new AttributeQualification();
    
    
  2. Specify the three primary components of the condition.

    aq1.setAttribute(PublicObject.NAME_ATTRIBUTE);
    aq1.setOperator(AttributeQualification.LIKE);
    aq1.setValue("Oracle 9iFS");
    
    
  3. Specify that the value's case should be ignored.

    aq1.setCaseIgnored(true);
    

Example 8-8 Constructing an AttributeQualification with a Late Bound Variable

  1. Construct the AttributeQualification.

    AttributeQualification aq1 = new AttributeQualification();
    
    
  2. Specify the three primary components of the condition. Set the value with the LATE_BIND_OPER constant.

    aq1.setAttribute(PublicObject.NAME_ATTRIBUTE);
    aq1.setOperator(AttributeQualification.EQUAL);
    aq1.setValue(SearchQualification.LATE_BIND_OPER);
    

Example 8-9 Constructing an AttributeQualification with a Date Value

  1. Construct the AttributeQualification.

    AttributeQualification aq1 = new AttributeQualification();
    
    
  2. Specify attribute and the operator for the condition.

    aq1.setAttribute(PublicObject.CREATEDATE_ATTRIBUTE);
    aq1.setOperator(AttributeQualification.LESS_THAN);
    
    
  3. Create an AttributeValue to supply the Date value.

    Date today = new Date();
    AttributeValue av = AttributeValue.newAttributeValue(today);
    aq1.setValue(av, session);
    
    
  4. Specify the level to which Oracle 9iFS will compare the attribute and the date value.

    aq1.setDateComparisionLevel(AttributeQualification.DATE_COMP_DAY);
    

Example 8-10 Constructing an AttributeQualification with an Object Value

  1. Construct the AttributeQualification.

    AttributeQualification aq1 = new AttributeQualification();
    
    
  2. Specify attribute and the operator for the condition.

    aq1.setAttribute(PublicObject.ACL_ATTRIBUTE);
    aq1.setOperator(AttributeQualification.EQUAL);
    
    
  3. Create an AttributeValue to supply the Date value.

    Collection aclColl = session.getSystemAccessControlListCollection();
    SystemAccessControlList publicAcl = 
               (SystemAccessControlList) aclColl.getItems("PUBLIC");
    AttributeValue av = AttributeValue.newAttributeValue(publicAcl);
    aq1.setValue(av);
    
FolderRestrictQualification

To specify the condition that the search should be restricted to objects referenced by a folder, construct a FolderRestrictQualification. FolderRestrictQualifications allow you to search in a specific folder, or across a branch of a folder hierarchy.

Example 8-11 Constructing a FolderRestrictQualification

  1. Construct the FolderRestrictQualification.

    FolderRestrictQualification frq1 = new FolderRestrictQualification();
    
    
    
  2. Specify the folder to which the search should be restricted.

    Folder startFolder = session.getPrimaryUserProfile().getHomeFolder();
    frq1.setStartFolder(startFolder);
    
    
  3. Specify that the search should traverse any subfolders in the folder branch.

    frq1.setMultiLevel(true);
    
    
  4. Specify the class of information to be selected from the folder.

    frq1.setSearchClassname(Document.CLASS_NAME);
    

Example 8-12 Constructing a FolderRestrictQualification with a Late Bound Variable

  1. Construct the FolderRestrictQualification.

    FolderRestrictQualification frq1 = new FolderRestrictQualification();
    
    
    
  2. Specify the folder to which the search should be restricted.

    frq1.setStartFolder(SearchQualification.LATE_BIND_OPER);
    
    
    
  3. Specify the class of information to be selected from the folder.

    frq1.setSearchClassName(PublicObject.CLASS_NAME);
    
JoinQualification

To join search criteria based on related objects, construct a JoinQualification. A JoinQualification is comprised of two attributes that are tested for equality. When constructing the JoinQualification, you will specify the attribute and its class for each side of the comparison (e.g., Document.CreateDate = Folder.CreateDate). If you are joining two classes based on an attribute that has an object datatype, the other side of the join would only specify the class of the object that the attribute would hold (e.g., Document.Owner = DirectoryUser). Since Oracle 9iFS is an object-oriented system, attributes with an object datatype reference the object, not a specific attribute on that object.

Example 8-13 Constructing a JoinQualification

  1. Construct the JoinQualification.

    JoinQualification jq1 = new JoinQualification();
    
    
    
  2. Specify the class and attribute that are on the left side of the join.

    jq1.setLeftAttribute(Document.CLASS_NAME,PublicObject.OWNER_ATTRIBUTE);
    
    
    
  3. Specify the class and attribute that are on the left side of the join. Note the 'null' being passed for attribute. That implies joining on ID.

    jq1.setRightAttribute(DirectoryUser.CLASS_NAME, null);
    
ContextQualification

To specify a condition about the content of documents; that is, instances of the Document class and its subclasses, construct a ContextQualification. ContextQualifications are constructed from two primary components: a text query string, and a unique name.

When executing the search, Oracle 9iFS employs Oracle Text to search across an index of the document's content. When the SQL is generated, the content condition will take the form of a CONTAINS clause (e.g., CONTAINS(<index>, <text query string>, <order prefix>) > 0 ). The <index> parameter is determined by Oracle 9iFS based on the indexes generated on installation. The <text query string> is passed untouched from the value you supply to the setQuery() method. Therefore, the the value supplied to the setQuery() method must comply with Oracle Text's syntax rules for text query strings. The <order prefix> parameter is constructed by Oracle 9iFS from the value supplied to the setName() method.

When Oracle Text searches for documents based on content criteria, it ranks the documents according to their relevance to the criteria. Each document is given a score between 0 and 100, 100 representing the most relevant documents. You can sort the results of the search based on the score by including the Name of the ContextQualification in the SearchSortSpecification.

To use a ContextQualification to specify a content condition, you should:

  1. Construct a ContextSearchSpecification.

  2. Construct a ContextQualification to hold the content criteria.

  3. Include the ContentObject class or a subclass of ContentObject in the SearchClassSpecification.

  4. Construct a JoinQualification to join the ContentObject class with the Document class or Document subclass that pertain to other conditions (e.g., AttributeQualifications, FolderRestrictQualifications) about the information

  5. Specify which class in the SearchClassSpecification contains the content that Oracle Text should search.

  6. Optionally, sort the results by the relevancy score returned by Oracle Text.

Example 8-14 Constructing a ContextQualification

  1. Construct the ContextQualification.

    ContextQualification cq1 = new ContextQualification();
    
    
    
  2. Specify the text query string that is passed to Oracle Text as the <text query string> parameter in the CONTAINS() function.

    cq.setQuery("XML");
    
    
    
  3. Specify the Name of the ContextQualification. The Name is used by Oracle 9iFS to supply the <order prefix> parameter in the CONTAINS() function.

    String contextClauseName = "CQ1";
    cq.setName(contextClauseName);
    
    
    
  4. When constructing the SearchSortSpecification, you can sort the results by the score generated by Oracle Text from the CONTAINS() function by specifying the Name of the ContextQualification.

    SearchSortSpecification sortSpec;
    sortSpec.add(Document.CLASS_NAME, 
                 ContextQualification.ORDER_PREFIX + "." + ctxClauseName, true);
    
    
    
  5. Since content is stored as a ContentObject, you must add both the Document and ContentObject classes to the SearchClassSpecification and then join Document and ContentObject classes.

    String [] classNames = new String[] {"Document", "ContentObject"};
    SearchClassSpecification scp = new SearchClassSpecification(classNames); 
    scp.addResultClass("Document");
    
    JoinQualification jq1 = new JoinQualification();
    jq1.setLeftAttribute(Document.CLASS_NAME, Document.CONTENTOBJECT_ATTRIBUTE); 
    jq1.setRightAttribute(ContentObject.CLASS_NAME, null); 
    
ExistenceQualification

To include a condition that an a Attribute matches one of a list of possible values, construct an ExistenceQualification. When constructing an ExistenceQualification, you will specify the attribute on the left-hand side of the comparison, and a list of values on the right-hand side of the comparison. The attribute can be any scalar attribute. Currently, Oracle 9iFS does not support specifying array type attributes as the left-hand side of the comparison. The list of values can be specified either as another attribute of type scalar or array, or as an AttributeValue[] array.

Example 8-15 Constructing an ExistenceQualification for String Values

// Suppose you want to look for, all documents 
// whose name appears in STRINGVALUE attribute of any PROPERTY
// Generates query - DOCUMENT.Name in (select STRINGVALUE from PROPERTY)
// This shows scalar attributes on both LHS and RHS.

  1. Construct the ExistenceQualification.

    ExistenceQualification eq1 = new ExistenceQualification();
    
    
    
  2. Specify the attribute whose value should exist in the list of values.

    eq1.setLeftAttribute(Document.CLASS_NAME, PublicObject.NAME_ATTRIBUTE); 
    
    
    
  3. Specify the list of user supplied values.

    eq1.setRightAttribute(Property.CLASS_NAME, Property.STRINGVALUE_ATTRIBUTE); 
    

Example 8-16 Constructing an ExistenceQualification for Array Values

// Suppose you want to look for, all documents whose name appears in
// STRINGVALUES array type attribute in a property.
// Generates query - DOCUMENT.Name in (select STRINGVALUES[] 
// from PROPERTY)
// This flattens out the array attribute on the right hand side 
// and generates a concatenated list of all values in 
// STRINGVALUES attribute in each row.

  1. Construct the ExistenceQualification.

    ExistenceQualification eq1 = new ExistenceQualification();
    
    
  2. Specify the attribute whose value should exist in the list of values.

    eq1.setLeftAttribute(Document.CLASS_NAME, PublicObject.NAME_ATTRIBUTE); 
    
    
    
  3. Specify the list of user supplied values.

    eq1.setRightAttribute(Property.CLASS_NAME, Property.STRINGVALUES_ATTRIBUTE); 
    
    
    

Example 8-17 Constructing an ExistenceQualification for User-supplied Values

// Suppose you want to look for documents whose name is 
// in {"FOO", "BAR", "NOTES"},
// then you use the EQ in the following manner.

  1. Construct the ExistenceQualification.

    ExistenceQualification eq1 = new ExistenceQualification();
    
    
  2. Specify the attribute whose value should exist in the list of values.

    eq1.setLeftAttribute(Document.CLASS_NAME, PublicObject.NAME_ATTRIBUTE); 
    
    
  3. Specify the list of user supplied values.

    AttributeValue [] avArray = new AttributeValue[3];
    avArray[0] = AttributeValue.newAttributeValue("FOO");
    avArray[1] = AttributeValue.newAttributeValue("BAR");
    avArray[2] = AttributeValue.newAttributeValue("NOTES");
    
    eq1.setRightAttributeValue(avArray); 
    
PropertyQualification

To specify a condition about a property in the object's PropertyBundle, construct a PropertyQualification. PropertyQualifications are comprised of: the name of the property, the value of the property, and a comparison operator. The value must be supplied as an instance of AttributeValue so that Oracle 9iFS can automatically compare the value to the property's Value attribute regardless of its datatype. In addition, constructing a PropertyQualification will automatically add another Search class for the class of the object that possesses the PropertyBundle.

Example 8-18 Constructing a PropertyQualification for a String Value

  1. Construct the PropertyQualification.

    PropertyQualification pq = new PropertyQualification();
    
    
    
  2. Specify the class of information on which the Property would exist.

    pq.setClassname(Document.CLASS_NAME);
    
    
    
  3. Specify the Name, Value, and comparison operator for the Property. Also, specify if Oracle 9iFS should ignore the value's case.

    pq.setPropertyName("color");
    pq.setOperatorType(AttributeQualification.EQUAL);
    pq.setValue(AttributeValue.newAttributeValue("RED"));
    pq.setCaseIgnored(ignoreCase);
    

Example 8-19 Constructing a PropertyQualification for a Date Value

  1. Construct the PropertyQualification.

    PropertyQualification pq = new PropertyQualification();
    
    
    
  2. Specify the class of information on which the property would exist.

    pq.setClassname(Document.CLASS_NAME);
    
    
    
  3. Specify the Name, Value, and comparison operator for the property. Also, specify the level to which Oracle 9iFS should compare the date value.

    pq.setPropertyName("expire-date");
    pq.setOperatorType(AttributeQualification.EQUAL);
    pq.setValue(
           AttributeValue.newAttributeValue(
               new GregorianCalendar(1995, 0, 15).getTime()));
    pq.setDateComparisonLevel(AttributeQualification.DATE_COMP_MONTH);
    
              // Using DOCUMENT(or any object type) type attribute value
              // This looks for a particular document in a property 
              // containing DOCUMENT objects 
    

Example 8-20 Constructing a PropertyQualification for an Object Value

  1. Construct the PropertyQualification.

    PropertyQualification pq = new PropertyQualification();
    
    
    
  2. Specify the class of information on which the property would exist.

    pq.setClassname(Document.CLASS_NAME);
    
    
    
  3. Specify the Name, Value, and comparison operator for the property. Also, specify the level to which Oracle 9iFS should compare the date value.

    pq.setPropertyName("related-docs");
    pq.setOperatorType(AttributeQualification.EQUAL);
    pq.setValue(AttributeValue.newAttributeValue(new Document[] {d}));
    

Example 8-21 Constructing a PropertyQualification with Late Bound Variables

  1. Construct the PropertyQualification.

    PropertyQualification pq = new PropertyQualification();
    
    
    
  2. Specify the class of information on which the property would exist.

    pq.setClassname(Document.CLASS_NAME);
    
    
    
  3. Specify the Name, Value, and comparison operator for the property.

    AttributeValue srchDate = 
          AttributeValue.newAttributeValue(
             new GregorianCalendar(1995, 0, 1).getTime());
    pq.setPropertyName("expire-date");
    pq.setOperatorType(AttributeQualification.EQUAL);
    pq.setLateBoundDataType(srchDate.getDataType());
    
FreeFormQualification

To include an ad-hoc SQL expression in the WHERE clause generated by Oracle 9iFS, construct a FreeFormQualification. The FreeFormQualification class provides a hook for advanced developers to specify search criteria that cannot be constructed by Oracle 9iFS. For example, a custom search application may need to build a search based on Oracle Text indexes on an attribute (e.g., Description) that is not full-text indexed automatically by Oracle 9iFS. To do so, the application can construct a FreeFormQualification that constructs a CONTAINS() function on that attribute. Or, an application may need to use other SQL functions (e.g., SUM) that are not yet automatically generated by the Oracle 9iFS API.

The SQL expression specified in the FreeFormQualification will not be validated by Oracle 9iFS. In addition, FreeFormQualifications don't support late binding. Therefore, the SQL string cannot contain '?'.

Using FreeFormQualifications requires that you have a good understanding of the Oracle 9iFS schema. The search application can only access secure tables in the Oracle 9iFS schema if the current session user is an administrator and if AdministrationMode is turned on for the session (e.g., ifsSession.setAdministrationMode(true)).

The SQL generated by the FreeFormQualification is inserted into the WHERE clause generated by Oracle 9iFS. Therefore, you can not use FreeFormQualifications for executing DDL or DML statements, nor for constructing complete SQL select statements.

Example 8-22 Constructing a FreeFormQualification

// Create a FreeFormQualification to find CONTENTOBJECTS 
// that are greater than the average content size.

  1. Construct the FreeFormQualification.

    FreeFormQualification ffq= new FreeFormQualification();
    
    
    
  2. Construct the SQL string and pass it to the FreeFormQualification.

    String sqlExpression = "co.contentsize > " + 
                           "(select AVG(contentsize) " + 
                           "from odm_contentobject c, odm_document d " + 
                           "where c.id = d.contentobject)");
    ffq.setSqlExpression(sqlExpression);
    

Combine the Conditions into a Single SearchQualification

If your search includes more than one condition, combine the conditions into a single SearchQualification. After constructing each condition as an instance of the corresponding SearchQualification subclass, combine the conditions together into a tree of nested criteria by constructing SearchClauses. Pass the resulting SearchClause to the setSearchQualification() method to set the search criteria for the SearchSpecification.

SearchClauses can be used to combine two conditions together with Boolean operators (e.g., AND and OR). In this case, the SearchClause is comprised of a left-hand side condition, right-hand side condition, and the Boolean operator.

SearchClauses can also be used to construct negative statements with the operator NOT. In this case, the SearchClause is comprised of the operator, and the right-hand side condition.

You can nest SearchClauses by passing a SearchClause in as the left-hand and/or right-hand side of another SearchClause (e.g., <condition> OR (<condition> AND <condition>)).

Example 8-23 Constructing SearchClauses

/*
 * SearchClauses are used to construct the following WHERE statement:
 * WHERE (Document.contentobject = ContentObject
 * AND ContentObject.Format = Format)
 * AND (Document.name = ? AND Format.extension = 'html')
 * OR (Document.owner = ? AND Format.name = 'MS Word')
 */ 

  1. Construct JoinQualification for Document.ContentObject = ContentObject.

    JoinQualification jq1 = new JoinQualification();
    jq1.setLeftAttribute("DOCUMENT", "CONTENTOBJECT");
    jq1.setRightAttribute("CONTENTOBJECT"); 
    
    
  2. Construct JoinQualification for ContentObject.Format = Format.

    JoinQualification jq2 = new JoinQualification();
    jq2.setLeftAttribute("CONTENTOBJECT", "FORMAT");
    jq2.setRightAttribute("FORMAT"); 
    
    
  3. Construct AttributeQualifications for DOCUMENT.NAME and FORMAT.XTENSION.

    AttributeQualification aq1 = new AttributeQualification();
    aq1.setAttribute("DOCUMENT", "NAME");
    aq1.setOperatorType("=");
    aq1.setValue("?");
    
    AttributeQualification aq2 = new AttributeQualification()
    aq2.setAttribute("FORMAT", "EXTENSION");
    aq2.setOperatorType("=");
    aq2.setValue("html");
    
    
    
  4. Construct the AttributeQualifications for DOCUMENT.OWNER and FORMAT.NAME.

    AttributeQualification aq3 = new AttributeQualification();
    aq3.setAttribute("DOCUMENT", "OWNER");
    aq3.setOperatorType("=");
    aq3.setValue("?");
    
    AttributeQualification aq4 = new AttributeQualification();
    aq4.setAttribute("FORMAT", "NAME");
    aq4.setOperatorType("=");
    aq4.setValue("MS Word");
    
    
  5. Construct the full WHERE Clause by combining the pieces into SearchClauses using a constructor.

    SearchClause sc1 = new SearchClause(aq1, aq2, SearchClause.AND);
    SearchClause sc2 = new SearchClause(aq3, aq4, SearchClause.AND);
    SearchClause sc3 = new SearchClause(jq1, jq2, SearchClause.AND);
    SearchClause sc4 = new SearchClause(sc1, sc2, SearchClause.OR);
    SearchClause scComplete = new SearchClause(sc3, sc4, SearchClause.AND);
    
    

Alternatively, the SearchClause class provides methods that you can use to build and retrieve the clause with more granular control. This may be useful if you want to reuse or manipulate components of the SearchClause in the application.

Example 8-24 Constructing SearchClauses

  1. Create JoinQualification for Document.ContentObject = ContentObject

    JoinQualification jq1 = new JoinQualification();
    jq1.setLeftAttribute("DOCUMENT", "CONTENTOBJECT");
    jq1.setRightAttribute("CONTENTOBJECT"); 
    
    
  2. Create JoinQualification for ContentObject.Format = Format

    JoinQualification jq2 = new JoinQualification();
    jq2.setLeftAttribute("CONTENTOBJECT", "FORMAT");
    jq2.setRightAttribute("FORMAT"); 
    
    
  3. Setup AttributeQualifications for DOCUMENT.NAME and FORMAT.EXTENSION

    AttributeQualification aq1 = new AttributeQualification();
    aq1.setAttribute("DOCUMENT", "NAME");
    aq1.setOperatorType("=");
    aq1.setValue("?");
    
    
  4. AttributeQualification aq2 = new AttributeQualification()

    aq2.setAttribute("FORMAT", "EXTENSION");
    aq2.setOperatorType("=");
    aq2.setValue("html");
    
    
  5. Use the clone() method to easily create a new AttributeQualification based on aq2 which has the same Attribute.

    AttributeQualification aq3 = aq2.clone();
    aq3.setValue("txt");
    
    
  6. Construct the full WHERE Clause by explicitly combining the pieces into SearchClauses explicitly with methods.

    SearchClause sc1 = new SearchClause();
    sc1.setLeftSearchQualification(aq1);
    sc1.setRightSearchQualification(aq2);
    sc1.setOperatorType(SearchClause.AND);
    
    
  7. Use the clone() method to create another SearchClause based on sc1 which has the same left-hand side SearchQualification.

    SearchClause sc2 = sc1.clone();
    sc2.setRightSearchQualification(aq3);
    sc2.setOperatorType(SearchClause.AND);
    
    
  8. Combine the remaining pieces into a complete SearchClause using constructors.

    SearchClause sc3 = new SearchClause(jq1, jq2, SearchClause.AND);
    SearchClause sc4 = new SearchClause(sc1, sc2, SearchClause.OR);
    SearchClause scComplete = new SearchClause(sc3, sc4, SearchClause.AND);
    

Construct a SearchSortSpecification

To specify the sort order for the search results, construct a SearchSortSpecification. The SearchSortSpecification class provides methods for specifying the attributes and their classes that will be used to order the results. The class also provides constants and methods for specifying whether the results should be listed in ASCENDING or DESCENDING order.

The easiest way to construct a SearchSortSpecification is by using the following constructor to initialize it with a set of sort criteria:

Example 8-25 Constructing SearchSortSpecification on Initialization

SearchSortSpecification ss = new SearchSortSpecification(
       new String[] {"CATEGORY", "FOLDER"}, 
       new String[] {"NAME", "NAME"}, 
       new boolean[] {SearchSortSpecification.ASCENDING,
                      SearchSortSpecification.ASCENDING});

Alternatively, the SearchSortSpecification class provides methods that you can use to build and retrieve the sort criteria with more granular control. This may be useful if you want to reuse or manipulate components of the SearchSortSpecification in the application.

Example 8-26 Constructing SearchSortSpecification with the Add method

SearchSortSpecification ss = new SearchSortSpecification();
ss.add("CATEGORY", "NAME", SearchSortSpecification.ASCENDING);
ss.add("FOLDER", "NAME", SearchSortSpecification.ASCENDING); 

Construct and Execute a Search

Once the query criteria has been assembled into a SearchSpecification, execute the query with the Search class. The Search class provides methods for passing in bind variables and executing the search. The Search class also provides methods for traversing the results of the search.

Example 8-27 Constructing and Executing a Search

  1. Construct an AttributeSearchSpecification to hold the query criteria

    AttributeSearchSpecification asp = new AttributeSearchSpecification(); 
    
    
    
  2. Construct a SearchClassSpecification

    SearchClassSpecification scp = new SearchClassSpecification("DOCUMENT'); 
    asp.setSearchClassnames(scp); 
    
    
    
  3. Construct an AttributeQualifications for DOCUMENT.OWNER

    AttributeQualification aq3 = new AttributeQualification();
    aq.setAttribute("DOCUMENT", "OWNER");
    aq.setOperatorType("=");
    aq.setValue("?");
    asp.setSearchQualification(aq); 
    
    
  4. Construct the Search object

    Search srch = new Search(session, asp);
    
    
    
  5. Construct an array to hold the bind variables

    AttributeValue[] bindValues = new AttributeValue[1];
    DirectoryUser dsUser = session.getDirectoryUser();
    bindValues[0] = AttributeValue.newAttributeValue(dsUser); 
    
    
  6. Open a cursor on the search and pass in the bind variables. The open() method executes the query.

    srch.open(bindValues); 
    
    
    
  7. Close the cursor on the search.

    srch.close(); 
    

Fetch the SearchResultObjects

To fetch the results of your search, you can use the open() method to open a cursor on the search and then use the next() method to fetch each resulting object. The next() method will return a SearchResultObject that represents a single search hit. Subsequently, you can call the getLibraryObject() method on the SearchResultObject to retrieve the piece of information that incurred the hit by meeting the search criteria.

Example 8-28

  1. Open a cursor on the search and pass in the bind variables. The open() method executes the query.

    srch.open(bindValues); 
    
    
    
  2. Fetch each search result hit incrementally and print the name of the LibraryObject.

    int i;
    SearchResultObject sro = srch.next();
    LibraryObject lo;
    
    while (sro != null)
    {
      lo = sro.getLibraryObject();
      try
      {
         sro = srch.next();
      }
      catch (IfsException e)
      {
        if (e.getErrorCode() == 22000)
        {
           break;
        }
        else
        {
           e.printStackTrace();
        }
      }
    }
    
    
  3. Close the cursor on the search.

    srch.close();
    

Save the SearchSpecification as a SearchObject

To save the search criteria persistently in the repository, you can construct a SearchObject from the SearchSpecification. To construct a SearchObject, follow these steps:

  1. Construct a SearchObjectDefinition.

  2. Set the SearchSpecification on the SearchObjectDefinition.

  3. Pass the SearchObjectDefinition to the LibrarySession to construct a SearchObject.

Example 8-29 Saving the SearchSpecification as a SearchObject

  1. Assume that the application has already constructed a SearchSpecification.

    SearchSpecification ss = ....
    
    
  2. Construct a SearchObjectDefinition.

    SearchObjectDefinition sod = new SearchObjectDefinition(session);
    sod.setAttributeByUpperCaseName("NAME",
       AttributeValue.newAttributeValue("XML Research"));
    
    Collection aclColl = session.getSystemAccessControlListCollection();
    AccessControlList acl = (AccessControlList) aclColl.getItems("Public");
    sod.setAttributeByUpperCaseName("ACL"
       AttributeValue.newAttributeValue(acl));
    
    Folder folder =
      session.getUser().getPrimaryUserProfile().getHomeFolder();
    sod.setAddToFolderOption(folder);
    
    
  3. Set the SearchSpecification on the SearchObjectDefinition.

    sod.setSearchSpecification(ss);
    
    
    
  4. Pass the SearchObjectDefinition to the LibrarySession to construct a SearchObject.

    SearchObject so = session.createPublicObject(sod);
    

Sample Code

Oracle 9iFS is installed with sample code that helps you get started working with the Java API. The API sample code is located in the <ORACLE_HOME>/9ifs/samplecode/oracle/ifs/examples/devdoc/api directory.

Table 8-19 lists the API sample code that is relevant to this chapter.


Table 8-19 API Sample Code
Class  Usage 

SearchSample.java 

Creates and executes attribute search. Creates a SearchObject. Shows the SQL generated from a search. 

SelectorSample.java 

Creates and executes selector searches. 

TextSearchSample.java 

Creates and executes content-based searches. 

ViewsSample.java 

Creates a view from a search. 


Go to previous page Go to next page
Oracle
Copyright © 2001 Oracle Corporation.

All Rights Reserved.
Go To Table Of Contents
Contents
Go To Index
Index