Write the methods of creating a query?
Answers
Explanation:
This chapter describes the different query methods you can use in your ConText application. You can use these methods with text queries and theme queries. The following topics are covered:
Selecting a Query Method
Using Two-Step Queries
Using One-Step Queries
Using In-Memory Queries
Counting Query Hits
Selecting a Query Method
Each of the query methods (two-step, one-step, and in-memory) provide advantages and disadvantages that you must consider when developing an application. The following table briefly describes each method and illustrates the various advantages and disadvantages to using each:
Query Method Use Advantage Disadvantage
One-step
Used in SQL*Plus. Best suited for interactive queries.
No pre-allocation of result tables
Uses standard SQL statements
Uses table and column names
Query results returned in a single step
Can retrieve all hits at once
Generally slower than two-step or in-memory queries
No access to result tables
Two-step
Two-step queries are best suited for PL/SQL-based applications that require all the results to a query.
Result tables can be manipulated
Generally faster than one-step queries, especially for mixed queries
Can retrieve all hits at once
Structured data can be queried as part of the CONTAINS (first step)
Requires pre-allocation of result tables
Uses policy names
Requires two steps to complete
Requires join to base text table to return document details
In-memory
In-memory queries are best suited for PL/SQL-based applications that might generate large hitlists, but where only a small portion of the hits are required at a time, such as World Wide Web applications.
No result tables
Faster response time than two-step, since you need not retrieve all hits in the hitlist.
Large hitlists generally faster than one-step and two-step queries
Can specify the number of hits returned
Uses policy names
Cannot retrieve all hits at once
With small hitlists, performance improvement over two-step is negligible
Requires three steps, including a loop, to complete
Queries for structured data must be performed separately and joined with in-memory results
Max and first/next operators are not supported
Using Two-Step Queries
To perform a two-step query, do the following:
Execute CTX_QUERY.CONTAINS. The procedure selects all documents that match the specified search criteria (query expression) and generates a score for each document.
The document textkeys and scores are stored in the specified result table.
Note:
You must create the result table before you execute the CONTAINS procedure.
Use a SELECT statement on the result table (and the base text table, if desired) to return the specified columns as a hitlist for the rows (documents) that satisfy the query expression.
Two-Step Query Example
The following example shows a simple two-step query. The query uses a policy named ARTICLES_POL to search the text column in a table named TEXTTAB for any articles that contain the word petroleum. The CONTAINS procedure populates the CTX_TEMP results table with the document primary keys that satisfy the query.
The select statement then joins the results in CTX_TEMP with TEXTAB to create a list of document titles ordered by score.