Oracle Text Application Developer's Guide Release 9.0.1 Part Number A90122-01 |
|
Introduction to Oracle Text , 6 of 8
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.
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.
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.
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;
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.
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. |
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.
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.
In your query application, you can use other query features such as proximity searching. The following table lists some of these features.
|
Copyright © 1996-2001, Oracle Corporation. All Rights Reserved. |
|