The SQL repository supports full text searches via the QueryBuilder.createTextSearchQuery() method. In order for full text search queries to work, you must have a supported full text search engine installed and configured.

The following example demonstrates use of the full-text query feature. This class can be found in:

<ATG10dir>/DAS/src/Java/atg/adapter/gsa/sample/FullTextQuery.java

It must be run from DYNAMO_HOME. It also requires a repository definition file named gsa-template.xml to be in the current directory.

package atg.adapter.gsa.sample;

import atg.repository.*;

public class FullTextQuery
extends Harness
{
  //-------------------------------------
  /** Class version string */
  public static final String CLASS_VERSION =
  "$Id: FullTextQuery.java,v 1.1 2000/03/20 19:39:31 mstewart Exp $";

  //-------------------------------------
  /**
   * Run our sample.
   * @param pRepository repository to use
   * @exception RepositoryException if there is repository trouble
   **/
  public void go(Repository pRepository)
    throws RepositoryException
  {
    // print header
    pln("### Running Sample Full-Text Query ###");
    pln(CLASS_VERSION);
    pln("");

    /*
    ** This example demonstrates how do perform some simple full-text repository
    ** queries. In the repository API all queries are performed using Query
    ** or QueryExpression objects. A QueryExpression is a building block you
    ** can use to create simple or complex queries. A Query is a repository
    ** query that can be executed. A Query can also be used as a building
    ** block to create more complicated queries. Here we perform a simple
    ** query to find user repository items whose story property
    ** includes text in which the word 'dog' appears within 10 words of the
    ** word 'cat'.
    */

    // queries are created using QueryBuilders and executed by
    // RepositoryViews. A Query is defined in the context of a specific item
    // descriptor and thus must be built and executed with the right
    // QueryBuilder and RepositoryView.
    RepositoryItemDescriptor userDesc = pRepository.getItemDescriptor("user");
    RepositoryView userView = userDesc.getRepositoryView();
    QueryBuilder userBuilder = userView.getQueryBuilder();

    // create a QueryExpression that represents the property, story
    QueryExpression comment =
      userBuilder.createPropertyQueryExpression("story");

    // create a QueryExpression that represents a search expression
    // using the NEAR operator.
    QueryExpression dogNearCat =
      userBuilder.createConstantQueryExpression("NEAR((dog, cat), 10)");

            // define the format being used by the search expression
            // appropriate to the database being used. This assumes an Oracle
            // database with the interMedia/Context full-text search option
            // installed.
            QueryExpression format =
                  userBuilder.createConstantQueryExpression("ORACLE_CONTEXT");

            // pick a minimum required score that the results must meet or exceed
            // in order to be returned by the full-text search engine.
    // See your search engine vendor's docs for more information on the meaning
    // and use of the score value.
    QueryExpression minScore =
      userBuilder.createConstantQueryExpression(new Integer(1));


    // now we build our query: comment contains 'dog' within 10 words of 'cat'
    Query dogTenWordsNearCat =
      userBuilder.createTextSearchQuery(comment, dogNearCat, format, minScore);

    // finally, execute the query and get the results
    RepositoryItem[] answer = userView.executeQuery(dogTenWordsNearCat);

    pln("running query: story contains 'dog' within 10 words of 'cat' ");
    if (answer == null)
      {
        pln("no items were found");
      }
    else
      {
        for (int i=0; i<answer.length; i++)
          pln("id: " + answer[i].getRepositoryId());
      }

   }

  //-------------------------------------
  /**
   * Main routine. This example uses no command line arguments
   **/
  public static void main(String[] pArgs)
    throws Exception
  {
    runParser(FullTextQuery.class.getName(), pArgs);
  }

} // end of class FullTextQuery

You can specify what properties a text search query should search, with the text-search-properties attribute in the <item-descriptor> tag that defines an item type. For example, the following value indicates that a text search should examine the keywords and content properties for matches:

<item-descriptor name="newsItems
    text-search-properties="keywords,content">
...