How to search full Text using Oracle Text

Source: Internet
Author: User

The following articles describe how to correctly use Oracle Text for full-Text retrieval, therefore, the like syntax is used to query the full text of the law, which is slow. Therefore, the full-text retrieval function is added to the original system.

Full-Text retrieval relies on Oracle Text. First, ensure that the Oracle Text Component is installed in the database. Then create an index

SQL code

Add an index for fields in the legal full text

 
 
  1. create index idx_flqw_nr on flqw(nr) indextype is ctxsys.context; 

Add an index to the legal terms Field

 
 
  1. create index idx_fltk_nr on fltk(nr) indextype is ctxsys.context; 

Because the ctxsys. context index used by Oracle Text is not automatically maintained, the index needs to be updated regularly and optimized, and the number of index optimization times is slightly less.

SQL code

Update Index

 
 
  1. exec ctx_ddl.sync_index('idx_flqw_nr');  
  2. exec ctx_ddl.sync_index('idx_fltk_nr');  

Optimize Indexes

 
 
  1. exec ctx_ddl.optimize_index('idx_flqw_nr','full');  
  2. exec ctx_ddl.optimize_index('idx_fltk_nr','full');  

You can also write the updated index and optimization into a job, which can be run on a regular basis. The job should be created in the same directory as the user.

First, create a corresponding stored procedure.

SQL code

Grant the flyy user the permission to perform full-text indexing during the stored procedure.

 
 
  1. GRANT EXECUTE ANY PROCEDURE TO flyy; 

Stored Procedure for updating indexes

 
 
  1. CREATE OR REPLACE PROCEDURE flyy.sync_index  
  2. AS  
  3. BEGIN  
  4. ctxsys.ctx_ddl.sync_index ('idx_flqw_nr');  
  5. ctxsys.ctx_ddl.sync_index ('idx_fltk_nr');  

END;

Optimize the index storage process

 
 
  1. CREATE OR REPLACE PROCEDURE flyy.optimize_index  
  2. AS  
  3. BEGIN  
  4. ctx_ddl.optimize_index ('idx_flqw_nr', 'full');  
  5. ctx_ddl.optimize_index ('idx_fltk_nr', 'full');  
  6. END;  

Create a scheduled job.

SQL code

Update indexes every 15 minutes

 
 
  1. VARIABLE job1 number;  
  2. BEGIN  
  3. DBMS_JOB.submit (:job1, 'sync_index;', SYSDATE, 'sysdate+1/24/4');  
  4. END;  

Optimize indexes and run once a day

After tests, optimizing indexes may lead to deadlocks. It is best to optimize indexes manually and use them with caution!

 
 
  1. VARIABLE job1 number;  
  2. BEGIN  
  3. DBMS_JOB.submit (:job1, 'optimize_index;', SYSDATE, 'sysdate+1');  
  4. END;  

Run the preceding job and query the job ID.

SQL code

Find the corresponding JOB

 
 
  1. SELECT job, schema_user, INTERVAL, what FROM user_jobs; 

Start the job based on the query results.

SQL code

Start job

 
 
  1. EXEC dbms_job.run(41);  

Is the job number queried above.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.