![]() | ![]() |
Home |
|
|
Full-Text Search Specialty Data Store User's Guide |
|
| Chapter 3: Configuring Adaptive Server for Full-Text Searches |
This chapter describes how to configure Adaptive Server to perform full-text searches. Topics include:
The Full-Text Search engine is a remote server that Adaptive Server connects to through Component Integration Services (CIS). Before you can use the Full-Text Search engine, configure Adaptive Server for a Full-Text Search engine as follows:
To connect to the Full-Text Search engine, Adaptive Server must be running with the enable cis and rpc configuration parameters enabled. If those parameters are not enabled, log in to Adaptive Server using isql and use sp_configure to enable them. For example:
exec sp_configure "enable cis", 1
exec sp_configure "rpc", 1
Adaptive Server displays a series of messages stating that you have altered a configuration parameter and that Adaptive Server must be rebooted for the new configuration parameters to take effect.
The installtextserver script:
Run the installtextserver script only once (see "Running the installtextserver Script"). To add Full-Text Search engines at a later time, use sp_addserver. See "Configuring Multiple Full-Text Search Engines" for more information about sp_addserver.
All Full-Text Search engines use the same database for storing text index metadata. This database is referred to in this book as the text_db database, the default name.
For a list and description of the system procedures added with the installtextserver script, see Appendix A, "System Procedures."
The installtextserver script is located in the $SYBASE/sds/text/scripts directory. Use a text editor (such as vi or emacs) to open the script, and make your edits. The edits you can make are as follows:
Note: If you change the name of the text_db database, you must change the name in the defaultDb configuration parameter (see "Modifying the Configuration Parameters").
/*
** Add the text server
*/
exec sp_addserver textsvr,sds,textsvr
go
Add an entry for each Full-Text Search engine you are configuring. For example, if you are configuring three Full-Text Search engines named KRAZYKAT, OFFICAPUP, and MOUSE, replace the default "textsvr" line with the following lines:
exec sp_addserver KRAZYKAT, sds, KRAZYKAT
exec sp_addserver OFFICAPUP, sds, OFFICAPUP
exec sp_addserver MOUSE, sds, MOUSE
go
exec sp_addobjectdef "vesaux","SYBASE.master.dbo.vesaux","table"
exec sp_addobjectdef "vesauxcol","SYBASE.master.dbo.vesauxcol", "table"
to something similar to:
exec sp_addobjectdef "vesaux","REMOTE.master.dbo.vesaux","table"
exec sp_addobjectdef "vesauxcol","REMOTE.master.dbo.vesauxcol", "table"
Use isql to run the installtextserver script. For example, to run the installtextserver script in an Adaptive Server named MYSVR, enter:
isql -Usa -P -SMYSVR -i $SYBASE/sds/text/scripts/installtextserver
The Full-Text Search engine has its own set of system procedure messages that you must install in Adaptive Server. Use the installmessages script to install the messages. You run the installmessages script only once, even if you have multiple Full-Text Search engines.
For example, to run the installmessages script in a server named MYSVR, enter:
isql -Usa -P -SMYSVR -i $SYBASE/sds/text/scripts/installmessages
Each database containing tables referenced by a text index must contain a text_events table, which logs inserts, updates, and deletes to indexed columns. It is used to propagate updated data to the Verity collections.
Run the installevent script, as described below, to create the text_events table and associated system procedures in a database. Use the installevent script as follows:
Note: If a text_events table does not exist in a database that includes source tables that require text indexing, changes to the source table will not be propagated to the Verity collections.
The installevent script is located in the $SYBASE/sds/text/scripts directory. Use a text editor (such as vi or emacs) to open the script, and make the edits. The edits you can make are:
Note: The name of the text_db database must be the same as the name in the defaultDb configuration parameter (see "Modifying the Configuration Parameters").
Note: The text_db database must exist before you run the installevent script. If it does not exist, run the installtextserver script first.
Using isql, run the installevent script to install the text_events table and related system procedures in Adaptive Server. For example, to run the installevent script in a server named MYSVR, enter:
isql -Usa -P -SMYSVR -i $SYBASE/sds/text/scripts/installevent
Before the Full-Text Search engine can process full-text searches, you must create text indexes for the source tables in the user database. After the text indexes are created, you must update them when the source data changes to keep the text indexes current. To create and maintain the text indexes:
For an example of setting up a text index, see the sample script sample_text_main.sql in the $SYBASE/sds/text/sample/scripts directory.
The source table contains the data on which you perform searches (for example, the blurbs table in the pubs2 database). For more information on source tables, see "The Source Table".
Before you can create text indexes on a source table, you must:
Every source table must contain an IDENTITY column to uniquely identify each row and provide a means of joining the index table and the source table. When you create a text index, the IDENTITY column is passed with the indexed columns to the Full-Text Search engine. The IDENTITY column value is stored in the text index and is mapped to the id column in the index table.
The IDENTITY column must have sufficient precision and scale to guarantee a unique IDENTITY for each row. Sybase recommends a precision of 10 and a scale of 0. You can use an existing IDENTITY column, if it is defined with sufficient precision and scale to identify each row uniquely.
For example, to create an IDENTITY column in a table named composers, define the table as follows:
create table composers (
id numeric(10,0) identity,
comp_fname char(30) not null,
comp_lname char(30) not null,
text_col text
)
To add an IDENTITY column to an existing table, enter:
alter table table_name add id numeric(10,0) identity
For optimum performance, Sybase recommends creating a unique index on the IDENTITY column. For example, to create a unique index named comp_id on the IDENTITY column created above, enter:
create unique index comp_id
on composers(id)
For more information about creating a unique index, see Chapter 11, "Creating Indexes on Tables," of the Transact-SQL User's Guide.
Use the sp_create_text_index system procedure to create the text indexes. sp_create_text_index does the following:
The text index can contain up to 16 columns. Columns of the following datatypes can be indexed:
char, varchar, nchar, nvarchar, text, image, datetime, smalldatetime
All Standard version datatypes, plus:
int, smallint, and tinyint
For example, to create a text index and an index table named i_blurbs for the copy column in the blurbs table in pubs2 on KRAZYKAT, enter:
sp_create_text_index "KRAZYKAT", "i_blurbs", "blurbs", " ", "copy"
where:
See "sp_create_text_index" for more information.
Note: Make sure the text_db database name in the configuration file (listed after the defaultDb parameter) matches the database name in Adaptive Server. If they do not match, the text index cannot be created. Also, verify that the text_events table exists in the user database. If it does not exist, run the installevent script for that database (refer to "Running the installevent Script").
Populating the Verity collections can take a few minutes or several hours, depending on the amount of data you are indexing. You may want to perform this step when the server is not being heavily used. Increasing the batch_size configuration parameter will also expedite the process. See "batch_size" for more information.
When you create a text index on two or more columns, each column in the text index is placed into its own document zone. The name of the zone is the name of the column. For example, to create a text index and an index table named i_blurbs for both the copy column and the au_id column in the blurbs table in pubs2 on KRAZYKAT, enter:
sp_create_text_index "KRAZYKAT", "i_blurbs", "blurbs", " ", "copy", "au_id"
sp_create_text_index creates two zones in the text index named "copy" and "au_id." When you issue a query against the i_blurbs text index, the search includes the copy and au_id columns. However, you can limit your search to a particular column by using the in operator to specify a document zone (for more information, see "in").
With the Standard version of Full-Text Search engine, you must manually bring a database online before issuing full-text queries on a source table in the database. When you bring a database online, the Full-Text Search engine initializes the internal Verity structures and confirms that the Verity collections exist.
Note: With the Enhanced Full-Text Search engine, the database is automatically brought online when the auto_online configuration parameter is set to 1.
Use the sp_text_online system procedure to bring a database online for full-text searches if it is not automatically brought online. For example, to bring the pubs2 database online before issuing full-text searches on the blurbs table in a Full-Text Search engine named KRAZYKAT, enter:
sp_text_online KRAZYKAT, pubs2
This message appears:
Database 'pubs2' is now online
The pubs2 database is now available for performing full-text searches.
See "sp_text_online" for more information.
When you insert, update, or delete data in your source table, the text indexes are not updated automatically. After you update data, run the sp_refresh_text_index system procedure to log the changes to the text_events table. Then, run the sp_text_notify system procedure to notify the Full-Text Search engine that changes need to be processed. The Full-Text Search engine then connects to Adaptive Server, reads the entries in the text_events table, determines which indexes, tables, and rows are affected, and updates the appropriate collections.
See "sp_refresh_text_index" and "sp_text_notify" for more information on these system procedures.
To have sp_refresh_text_index run automatically after each insert, update, or delete, you can create triggers on your source tables, as follows:
Triggers are not fired when you use writetext to update a text column. To have sp_refresh_text_index automatically run after a writetext:
For examples of each of these triggers, see the sample script sample_text_main.sql in the $SYBASE/sds/text/sample/scripts directory.
To replicate tables that have text indexes, follow these guidelines:
Note: You must issue an update against a non-text column whenever a writetext command is performed. This ensures that the trigger that inserts data into the text_events table is fired.
This example describes the steps for creating a text index on the plot column of the reviews table in the movies database. This process assumes that:
Each database containing tables referenced by a text index must contain a text_events table, which logs inserts, updates, and deletes to indexed columns.
If a text_events table is in your model database, it will be in all new databases. If a text_events table is not in your model database, run the installevent script to install the text_events table in the new database. For example, to install the text_events table in the movies database:
isql -Usa -P -SMYSVR -i $SYBASE/sds/text/scripts/installeventmovies
See "Running the installevent Script" for information on installing the text_events table.
Every source table must contain an IDENTITY column, which uniquely identifies each row and provides a means of joining the index table and the source table.
For example, to add an IDENTITY column to the reviews table, enter:
alter table reviews add id numeric(10,0) identity
See "Adding an IDENTITY Column to a Source Table" for more information on creating an IDENTITY column.
This step is optional. To enhance performance, Sybase recommends creating a unique index that contains only the IDENTITY column. For example, to create a unique index named reviews_id on the IDENTITY column created in step 2, issue the command:
create unique index reviews_id on reviews(id)
For more information about creating a unique index, see Chapter 11, "Creating Indexes on Tables," of the Transact-SQL User's Guide.
The source tables in the user database need to be indexed so that you can perform full-text searches. For example, to create a text index and an index table named reviews_idx for the plot column in the reviews table, enter:
sp_create_text_index "MYTXTSVR", "reviews_idx", "reviews", " ", "plot"
The reviews table is now available for running full-text searches.
See "sp_create_text_index" for more information.
To bring the movies database online for the Full-Text Search engine named MYTXTSVR, enter:
sp_text_online MYTXTSVR, movies
Note: Omit this step if you have Enhanced Full-Text Search engine and your auto_online configuration parameter is set to "1".
See "sp_text_online" for more information.
|
|