简体   繁体   中英

Oracle text search across multiple tables and columns

In my java web application want to put "global search" text box that would search against multiple tables (different columns) using "Oracle Text"?

eg

Table Student {name}

Table Teacher {name}

Table Department{name, description}

Table subject{name, title}

Now what I would like to do is that if user enter "Chem" that this word should be searched against Student:name, Teacher:name, Department:name, Department:description, Subject:name, Subject:title column and it would sort the result according to its Oracle Text Score?

Can anyone advise what the best way to achieve this? Not sure how to search all those column across multiple tables with single query using "Contains" oracle text function?

Also, please assume no relation between tables. Thanks in advance!

You could do something like this:

with search_fields as (
    select 'student' as table,
           'name' as field,
           name as text
       from student
    union all 
    select 'teacher' as table,
           'name'    as field,
           name as text
       from student 
    union all
    ...
)
select * from search_fields where text contains ...

You might have to add to this if you need to link back to the original table in some way.

从表中创建视图,然后从中选择:

 SELECT * FROM your_view WHERE UPPER(name) Like Upper('Chem%'); -- or '%Chem%'

The user datastore allows you to glue multiple tables into one virtual document, that Oracle Text uses to index and search. This would allow you to have one contains clause that searches multiple tables. When you create the user datastore, you define the columns in each of the tables that you wish to index.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM