Oracle Text Application Developer's Guide
Release 9.0.1

Part Number A90122-01
Go To Documentation Library
Go To Product List
Book List
Go To Table Of Contents
Go To Index

Master Index


Go to previous page Go to beginning of chapter Go to next page

Introduction to Oracle Text , 6 of 8

Querying your Index

With Oracle Text, you use the CONTAINS operator to query a context index. This is the most common operator and index used to build query applications.

For more advanced applications, you use the CATSEARCH operator to query a ctxcat index, and you use the MATCHES operator to query the ctxrule index.

Querying with CONTAINS

You can use CONTAINS to retrieve documents that contain a word or phrase. Your document must be indexed before you can issue a CONTAINS query.

Use the CONTAINS operator in a SELECT statement. With CONTAINS, you can issue two types of queries:

You can also optimize queries for better response time to obtain the top n hits. The following sections give an overview of these query scenarios.

Word Query Example

A word query is a query on the exact word or phrase you enter between the single quotes in the CONTAINS or CATSEARCH operator.

The following example finds all the documents in the text column that contain the word oracle. The score for each row is selected with the SCORE operator using a label of 1:

SELECT SCORE(1) title FROM news WHERE CONTAINS(text, 'oracle', 1) > 0;

In your query expression, you can use text operators such as AND and OR to achieve different results. You can also add structured predicates to the WHERE clause.

See Also:

Oracle Text Reference for more information about the different operators you can use in queries.  

You can count the hits to a query using the SQL COUNT(*) statement, or CTX_QUERY.COUNT_HITS.

ABOUT Query Example

In all languages, ABOUT queries increases the number of relevant documents returned by a query.

In English and French, ABOUT queries can use the theme component of the index, which is created by default. As such, this operator returns documents based on the concepts of your query, not only the exact word or phrase you specify.

For example, the following query finds all the documents in the text column that are about the subject politics, not just the documents that contain the word politics:

SELECT SCORE(1) title FROM news WHERE CONTAINS(text, 'about(politics)', 1) > 0;

See Also:

Oracle Text Reference to learn more about the ABOUT operator. 

Optimizing Query for Response Time

You can optimize any CONTAINS query (word or ABOUT) for response time in order to retrieve the highest ranking hits in a result set in the shortest time possible. Optimizing for response time is useful in a web-based search application.

See Also:

"Optimizing Queries for Response Time" in Chapter 5, "Query Tuning"

Structured Field Searching

Your application interface can give the user the option of querying on structured fields related to the text such as item description, author, or date as a means of further limiting the search criteria.

You can issue structured searches with CONTAINS using a structured clause in the SELECT statement. However, for optimal performance, consider creating a ctxcat index which gives better performance for structured queries with the CATSEARCH operator.

Your application can also present the structured information related to each document in the hitlist.

See Also:

"Creating a CTXCAT Index" in Chapter 2, "Indexing" for more information about creating a ctxcat index to improve structured queries with CATSEARCH. 

Thesaural Queries

Oracle Text enables you to define a thesaurus for your query application.

Defining a custom thesaurus allows you to process queries more intelligently. Since users of your application might not know which words represent a topic, you can define synonyms or narrower terms for likely query terms. You can use the thesaurus operators to expand your query with thesaurus terms.

See Also:

Chapter 7, "Working With a Thesaurus" 

Document Section Searching

Section searching enables you to narrow text queries down to sections within documents.

Section searching can be implemented when your documents have internal structure, such as HTML and XML documents. For example, you can define a section for the <H1> tag that allows you to query within this section using the WITHIN operator.

You can set the system to automatically create sections from XML documents.

You can also define attribute sections to search attribute text in XML documents.


Section searching is supported for only word queries with a context index type. 

See Also:

Chapter 6, "Document Section Searching" 

Other Query Features

In your query application, you can use other query features such as proximity searching. The following table lists some of these features.

Feature  Description  Implement With 

Proximity Searching 

Enables searches for words near one another. 

NEAR operator at query-time. 


Enables searching for words with same root as specified term. 

$ operator at query-time.


Fuzzy Searching 

Search for words that have similar spelling to specified term. 

fuzzy operator at query-time.


Case Sensitive Searching 

Enables case-sensitive searches. 

Enable with basic_lexer at index-time. 

Base Letter Conversion 

Queries match words with or without diacritical marks such as tildes, accents, and umlauts. For example, with a Spanish base-letter index, a query of energía matches documents containing energía and energia

Enable with basic_lexer at index-time.


Word Decompounding

(German and Dutch) 

Enables searching on words that contain specified term as sub-composite. 

Enable with basic_lexer at index-time.


Alternate Spelling

(German, Dutch, and Swedish) 

Enables searches on alternate spellings of words. 

Enable with basic_lexer at index-time.


Query Explain Plan 

Generate query parse information. 


Hierarchical Query Feedback 

Generate broader term, narrower term and related term information for a query. 


Browse index 

Browse the words around a seed word in the index. 


Count hits 

Count the number of hits in a query 


Stored Query Expression 

Stores a query expression 


Thesaural Queries 

Use a thesaurus to expand queries. 

Thesaurus operators such as SYN and BT as well as the ABOUT operator.

Use CTX_THES package to maintain thesaurus. 

Go to previous page Go to beginning of chapter Go to next page
Copyright © 1996-2001, Oracle Corporation.

All Rights Reserved.
Go To Documentation Library
Go To Product List
Book List
Go To Table Of Contents
Go To Index

Master Index