Oracle text contains and mixed queries

Trying to optimize the following sql statement using oracle text.  When postal code is given, I would like to limit the contains to only filter the smaller subset.  Both of these queries produce the same results in the same amount of time with practically identical explain plans. Is there any way to get contains to only search the subset of postal codes and not the entire table.
select *
from ADDRESS
where CONTAINS(ADDRESS1_TEXT, ' "1%" AND "%str%" ') > 0
and POSTAL_CODE like '77539%'
select *
from ADDRESS
where address_id in (select address_id from address where POSTAL_CODE like '77539%')
and CONTAINS(ADDRESS1_TEXT, ' "1%" AND "%str%" ') > 0
Thanks for any help,
Gus

You can use FILTER BY in the index creation and SDATA in the query, as shown below.
SCOTT@orcl12c> CREATE TABLE address
  2    (address1_text  VARCHAR2(15),
  3      postal_code    VARCHAR2(15))
  4  /
Table created.
SCOTT@orcl12c> INSERT INTO address VALUES ('12 astrb', '775391')
  2  /
1 row created.
SCOTT@orcl12c> INSERT INTO address
  2  SELECT SUBSTR (object_name, 1, 15),
  3          object_id
  4  FROM  all_objects
  5  /
89979 rows created.
SCOTT@orcl12c> CREATE INDEX test_idx
  2  ON address (address1_text)
  3  INDEXTYPE IS CTXSYS.CONTEXT
  4  FILTER BY postal_code
  5  /
Index created.
SCOTT@orcl12c> SET AUTOTRACE ON EXPLAIN
SCOTT@orcl12c> SELECT * FROM address
  2  WHERE  CONTAINS
  3            (address1_text,
  4            '"1%" AND "%str%" AND SDATA (postal_code LIKE ''77539%'')') > 0
  5  /
ADDRESS1_TEXT  POSTAL_CODE
12 astrb        775391
1 row selected.
Execution Plan
Plan hash value: 3864510387
| Id  | Operation                  | Name    | Rows  | Bytes | Cost (%CPU)| Time    |
|  0 | SELECT STATEMENT            |          |    44 |  1320 |    13  (0)| 00:00:01 |
|  1 |  TABLE ACCESS BY INDEX ROWID| ADDRESS  |    44 |  1320 |    13  (0)| 00:00:01 |
|*  2 |  DOMAIN INDEX              | TEST_IDX |      |      |    4  (0)| 00:00:01 |
Predicate Information (identified by operation id):
  2 - access("CTXSYS"."CONTAINS"("ADDRESS1_TEXT",'"1%" AND "%str%" AND SDATA
              (postal_code LIKE ''77539%'')')>0)
Note
  - dynamic statistics used: dynamic sampling (level=2)
SCOTT@orcl12c>

Similar Messages

  • Oracle Text contain query limit with 9i

    The Oracle Text contain query is defined as this:
    CONTAINS(
    [schema.]column,
    text_query VARCHAR2
    [,label NUMBER])
    RETURN NUMBER;
    Is the size limit of text_query 4000 bytes with 9i? Is it increased with 10g or is it accepting CLOB in 10g?
    I always got the error: "ORA-01460: unimplemented or unreasonable conversion requested" when I do the following where p_var was dynamically passed with size of more than 4000 bytes:
    p_statement varchar2(20000);
    p_var varchar2(8000);
    p_statement := select count(*) from dewey_table where contains(concat, :x)>0;
    open m_cursor for p_statement using p_var;
    Thanks very much,
    Kevin

    The limit is definitely 4000 characters in 9i and the 10g documentation shows no change in the calling spec for that parameter.

  • Search for Special Character in  Oracle Text CONTAINS Query

    Hi,
    We have to write few query which will search for email id in the Oracle Text.
    The Search text will be like <[email protected]> .
    So email id should be searched correctly with the @ symbol.
    Similarly we want the following special character to be searched in the Text like ",',*

    You will need to escape the special characters by either using \ in front of each special character or putting {} around the whole phrase that contains the special characters, as per the online documentation:
    http://download.oracle.com/docs/cd/B28359_01/text.111/b28304/cqspcl.htm#CCREF2091

  • Using xsql params w/in oracle text "contains" clause

    Hello,
    Regarding the xsql code below:
    <?xml version="1.0"?>
    <?xml-stylesheet type="text/xsl" href="hrefs.xsl"?>
    <page connection="rxschema" xmlns:xsql="urn:oracle-xsql">
    <xsql:query file="%winping-utility%" version="1.0"
    null-indicator="yes" link="">
    select distinct c.contentpathname
    from rx_schema.ct_shared s, rx_schema.contentstatus c
    where s.contentid = c.contentid
    and contains (s.ul_file, '{@link} within href') > 0
    and s.revisionid = (select max(revisionid)
    from rx_schema.ct_shared
    where contentid = s.contentid)
    order by contentpathname
    </xsql:query>
    </page>
    specifically this line:
    and contains (s.ul_file, '{@link} within href') > 0
    This query doesn't work, I think the "{@link}" xsql param (passed in) is being interpreted as an xml attribute (since it's within the "contains" clause), is there a way to force it to read this as a param? I also tried it w/o the braces (and I also verified that it works when I hardcode a value in place of "@link").
    Thanks,
    JSK

    The syntax of a 'Contains' query should contain only the 'Contains' query operators.
    http://www.cise.ufl.edu/help/database/oracle-docs/text.920/a96518/cqoper.htm#1360

  • Installing Oracle TEXT and XML DB Components on New Instance

    I was told this may be the best place to ask my quesion
    I have set up a New Instance or Oracle on a Solaris Unix box that already had Oracle 10g installed.
    The instance was created fine, however I need the Oracle Text Component and XML DB Component installed as well.
    Those are not installed with this instance. They are installed on the other instance on the box that was setup when oracle was first installed.
    How can I add these components to this new instance?
    DBCA was not used when the instance was created. The DBA here does not care for this tool.
    Thanks

    Hi,
    the installation of XMLDB is described in the XML manual: http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14259/appaman.htm#sthref2372
    the installation of Text is described on Metalink in document 280713.1.
    A nice document to start is on Metalink, it is document 472937.1. It gives Oracle components and the links how to install the components on different versions of Oracle.
    Herald ten Dam
    Superconsult.nl

  • How do I get Oracle Text to index files on a file server?

    I am new to Oracle (I'm a MS-SQL DBA looking for a Full-Text Search solution that is better than linking to a MS index server.)
    So - Here's the objective:
    I have Oracle Server(Express) installed on a Windows server.
    I would like for Oracle to build a Full-Text Catalog of the files on a separate file server based on file paths in a table in the database.
    (No desire to store terabytes of images and documents inside the database)
    I can get Oracle text up and running, using the URL_Datastore:
    CREATE TABLE files (id NUMBER PRIMARY KEY, issue_id NUMBER, path VARCHAR(255) UNIQUE, ot_format VARCHAR(6), ot_version VARCHAR(10));
    The Compaq server is a remote windows server on my local workgroup, so the fully qualified path is just "compaq" and the URL is valid:
    INSERT INTO files VALUES (9,9,'file://Compaq/FTQ/00000003.pdf',NULL,NULL);
    INSERT INTO files VALUES (13,13,'file://Compaq/FTQ/01.txt',NULL,NULL);
    CREATE INDEX file_index ON files(path) INDEXTYPE IS ctxsys.context
    PARAMETERS ('datastore ctxsys.URL_DATASTORE format column ot_format');
    but when I enter:
    Select * from CTX_User_Index_errors, I see the following errors:
    DRG-11609: URL store: unable to open local file specified by file://Compaq/FTQ/00000003.pdf
    DRG-11609: URL store: unable to open local file specified by file://Compaq/FTQ/01.txt
    Did I miss something?
    Do I need to install anything on the file server?
    I would like to convince my company that Oracle can be much quicker than Microsoft's Indexing Service because it can avoid joining two large result sets (one result set from Full_text (indexing service) and one for specific data contained in fields in the MS-SQL database.) Full Text Searches commonly take 40 - 60 seconds where there are 1.5 million multi-page PDF files for a particular set that I sample search on. Without this massive join, I believe I can get the search to run in under 10 seconds.

    Thank you!
    File_Datastore worked fine.
    I was staying away from File_Datastore because the information I gathered from googling suggested that file_datastore would only work locally.
    Now I just have to get Oracle to pull data out of tables in a MS-SQL database on the local network (don't have a clue yet), and then have it index compiled file paths.
    Then MS-SQL can query Oracle with index and full-text criteria and Oracle can send back a result set
    It may sound like a bad way of performing Full-Text Queries, but anything will be better than the way things are currently running. We are currently performing Full Text Searches on a table that is rebuilt nightly, so the table containing millions of file paths is not live..
    It would be so much better if we just migrated to Oracle, but we currently do not have the resources.

  • Oracle Text with eBusiness Suite

    I'm trying to understand if Oracle eBusiness Suite uses Oracle Text for indexing certain queries such as item description, etc.. I was told that iStore uses it for searching on items. Is that true? Does the Oracle Apps standard Item form use it? Can it be set up for use with the apps? I know the query syntax is different (CONTAINS), and I don't see any non standard indexes on MTL_SYSTEM_ITEMS_B, so I'm not sure how I could implement the functionality in the apps. Please help!!!!

    Yes, Oracle Text is used in iStore Search Feature, Refer to code under $JAVA_TOP/oracle/apps/ibe/catalog/Search.java for an example, also look at table ibe_ct_imedia_search table and its indexes which gives an idea of how Oracle iStore is leveraging Oracle Test for Searching.
    get the data into a staging table and then create whichever index you want, dont modify the indexes on key tables like MTL_SYSTEM_ITEMS_B

  • Using Oracle Text in Apex

    Hi,
    from what I've read about it, the following has to be done.
    e.g. CREATE index ticket_keywords_index ON ticket(keywords) indextype IS ctxsys.context;
    CREATE index ticket_solution_index ON ticket(solution) indextype IS ctxsys.context;
    SELECT * from ticket where ctxsys.contain(:P12Value_to_find);
    But I wonder, how does it know on which index it has to look ?
    Is there anyway to specify on what it should look ?
    If yes, any idea how one goes on about that ?
    If no, any idea how to avoid getting information from the two columns back, if one only needs one ?
    Could it in a way be done, by adding a column in apex, that allows to put in a checkbox, at the top, to say include this column in the search, or not, or is this not the good way to do so ?
    Or am i missing a point ?
    Thanks for the help,
    Floris

    Floris,
    Your query should be of the form:
    SELECT   *
    FROM   ticket
    WHERE   contains(indexed_col,:P12_VALUE_TO_FIND) > 0Where indexed_col is the name of the column on which you have built your Oracle Text index and :P12_VALUE_TO_FIND is the page item that contains the Search String.
    Andy
    http://atulley.wordpress.com/

  • Oracle Text Help with XML column values

    Hello. In addition to being new to Oracle Text, I am inheriting an Oracle Text application and have a couple of questions.
    First, A context-based index has been set-up on a CLOB column which contains an XML formatted document. The Auto Section Group parameter has been set to created zones for each tag of the XML document. I have found that when using a browser to display the content of the CLOB, some of the column values have trouble displaying in the browser, where I receive an XML processing error. I believe this is due to the fact that some of the XML document rows contain URLs that are not embedded in the CDATA tag. In any case, if the browser has trouble displaying the XML, will oracle text have trouble indexing the XML and creating the section group zones?
    Second, I understand that the NOT operator takes a right operand term and left operand term. Can either of the terms be the results of the WITHIN operator, i.e. "dogs not (cats within animals)".
    Thank you.

    I bet you just whipped that out, and I thank you with all my
    heart, its amazing to me how many ways I tried to do what you did.
    Thanks
    I have a second question relating to the same problem and
    that is in referencing the over state. Currently, I can write
    'text' into the text field and see what I have coming in from xml
    in its place during the 'up' state.
    However, when the timeline hits the 'over' state, the
    textfield will display nothing, or 'text' if I have that written
    in. I suspect that I am not referencing the'over' state correctly.
    Should I add one line of code sort of referencing the text
    field and not just the button while in the over state?

  • Using Oracle Text for searching with UCM 10g

    I am using Oracle text with UCM 10gR3 and Site Studio 10gR4 and I am trying to sort the search results by relevancy and to also include a snippet of the retrieved document. I have the fields that the SS_GET_SEARCH_RESULTS service returns but the relevancy score is always equals 5 and the snippet contains characters such as &lt; idcnull, /p, etc., which you can see are XML/HTML/UCM tags but which result sin even more strangeness in the snippet if I try to remove them programmatically.
    I have read the Oracle Text documentation and there appear to be ways you can configure Oracle Text but I am not clear at all on what I can do from UCM. It looks like the configuration is either done in database tables or in the query itself, neither of which are readily configurable to me.
    Is anyone experienced in this or know of any documentation this might help?
    Bill

    Hi
    If I remember correctly then this issue was seen with an older version of OTS component and Core Update patch / bundle . Upgrade the UCM instance with the latest CS10gr35 update bundle patchset 6907073 and also upgrade OTS component from the same patchset .
    Let me know how it goes after this .
    Thanks
    Srinath

  • Document management system using oracle text

    i plan to create document management system using oracle text with following features
    1) document comparision
    2) document search
    and more...
    can oracle text be used to display documents of various formats by converting them to HTML. and can search keywords be highlighted in the document.
    please help!

    Have you ever considered doing this in Oracle Application Express (free on top of the Oracle database)? How about something like:
    http://download-west.oracle.com/docs/cd/B31036_01/doc/appdev.22/b28839/up_dn_files.htm
    Index the files using the CONTEXT index, and perhaps the docs' meta with it using the Oracle Text MULTI_COLUMN_DATASTORE, and then when you write your query for a report on the documents include a search string.
    I've created a number of APEX-based document management systems and it is quite easy once you get the hang of using this environment. I suggest looking at some of the tutorials/how-to documents and you'll be on your way quickly.
    Start with the upload application. Once you can get your documents in, create a report that shows everything except the document. Verify all of this works correctly.
    Add some "items" to the page for the report, and include them as bind variables in the where clause.
    After that, add your Oracle Text index to the database, and toss in a "text-field" item to the APEX page. Modify your report query, adding the CONTAINS clause, and use the newly created item as a bind variable. There's your keyword search.
    Linking to Oracle Apps is done through API's and may be over database links.
    Hope it helps. Though not a step-by-step how to document, this should point you in the right direction. Get familiar with APEX as that covers most of what you described.
    -Ron

  • NEAR operator alternative when not using. oracle Text ?

    hi,
    I'm working on a project where i would need a Oracle Text 'NEAR like' operator ...
    here is my scenario ...
    in db we have Customers ... and every customer has some criterias like different search words( names, towns,cars,etc...) so for every customer i can create an SQL query out of criterias . ....
    now .... we can have a criteria like. ...... WHERE fulltext like 'john%'. or even distance search line NEAR inside CONTAINS. ... but then the Oracle text index is needed .....
    the only tAble on which Text index is created is our storage table that holds more then 4mil records and growing...
    my question is ... is there any way to have a query that would do the same thing as NEAR but without Text index ?
    here is how I start ....
    I get full newspaper article text from our OCR library ......
    then i need to check customer's criterias against this text to see which article is for which customer and then bind the article to the customer
    I could do it without Oracle using RegEx , but criterias can get really complicated ... like customer wants only specific MEDIA, or specific category , type , only articles that are from medias that are from specific country etc ... and many more different criterias ... and all this can be wrapped inside brackets with ANDs, ORs, NOT. ....
    So the only way to do it is to put it in Oracle and execute the correct query and let Oracle decide if the result is true or false .... but due to NEAR operator I need Oracle text ...
    So if I decide to first insert article into our storage table which has Oracle text index to be able to do the correct search .... how fast will this be ????
    will the the search become slower when there are 6mil records ? I know I can use FILTER BY to help Text index to do a better and quicker seach ... and how to optimize index ....but still
    I'm always asking my self..... why insert the article in a table where there are already 6mil articles and execute query when I only need to check data on one single article and. i already know this article ...
    I see two solutions :
    - if there is alternative for NEAR without using Oracle text index then i would insert data into temporary table and execute query on this table..... table would always contain only this one article. maybe one option would be to have one 'temp' table with Oracle text index in which i insert this one article and with help of Oracle text based on this one article do the search , and then maybe on a daily basis clear index ..... or when the article is removed from the table ... but this would mean having two Orcle text indexes, cause we already have Oracle text index on our storage table anyway....
    - another is to use Oracle text index and insert it into our storage table and hope for the best quick results ....
    Maybe I'm exaggerating and query like WHERE id=1234 and CONTAINS(...). will execute faster then I think
    If anyone would have any other suggestion I will be happy to try it ..
    thanks,
    Kris

    Hi,
    this is to my knowledge not possible. It is hard for Oracle to do, think about a table with many rows, every row with that column must be checked. So I think only a single varchar2 is possible. Maybe for you will a function work. It is possible to give a function as second parameter.
    function return_signup
    return varchar2
    is
      l_signup_name signup.signup_name%type;
    begin
      select signup_name
      into l_signup_name
      from signup
      where signup_id = 1
      and rownum = 1
      return l_signup_name;
    exception
      when no_data_found
      then
        l_signup_name := 'abracadabra'; -- hope does not exist
        return l_signup_name;
    end;Now you can use above function in the contains.
    select * from user_history_view users --, signup new_user
    --where new_user.signup_id = 1
    where contains(users.user_name, return_signup)>0;I didn't test the code! Maybe you have to adjust the function for your needs. But it is a idea how this can be done.
    Otherwise you must make the check by normaly check the columns by simple using a join:
    select * from user_history_view users, signup new_user
    where new_user.signup_id = 1
    and users.user_name = new_user.signup_name;Herald ten Dam
    htendam.wordpress.com

  • Name search. Oracle Text?

    Hi. I have a table containing surnames and forenames, many of which are foreign and easy to misspell. I wish to write a search application that will be intelligent and allow for misspellings. Am I right in assuming I need to use Oracle Text for this? And, if so, would it be a Context or Catalog search?
    I have not used Oracle Text before and would appreciate it if answers are detailed or point me in the right direction for further reading.
    Thanks.

    If you are on 10g you may find UTL_MATCH.jaro_winkler_similarity useful:
    Re: SQL Query to find out similar names in two tables

  • Oracle text synchronization

    Hi,
    we are working on a search engine based on Oracle Text and we use an index that is automatically synchronized at regular interval.
    But I've noticed a strange behaviour and wanted to know if someone had an issue to circumvent it.
    Here is the table we declare :
    create table ADSOTEXT(
         OBJID varchar2(16) not null,
         OBJFIELDURLLANG varchar2(16) default 'DEFAULT',
         OBJFIELDURL varchar2(2048),
         OBJFIELDURLCHARSET varchar2(16) default 'UTF8',
         OBJFIELDURLFORMAT varchar2(16),
         BOBJFIELDURL NUMBER(4) default 0
    There, the index creation order :
    begin
         ctx_ddl.create_section_group('axmlgroup', 'XML_SECTION_GROUP');
         ctx_ddl.add_field_section('axmlgroup', 'OBJREM', 'OBJREM',TRUE);
         ctx_ddl.add_field_section('axmlgroup', 'CLASSID', 'CLASSID',TRUE);
         ctx_ddl.add_field_section('axmlgroup', 'OBJID', 'OBJID',TRUE);
         ctx_ddl.add_field_section('axmlgroup', 'OBJREF', 'OBJREF',TRUE);
         ctx_ddl.add_field_section('axmlgroup', 'OBJNAME', 'OBJNAME',TRUE);
         ctx_ddl.add_field_section('axmlgroup', 'EXTRAFIELDS', 'EXTRAFIELDS',TRUE);
    end;
    --30 minutes pour la synchronisation
    drop index ADSOTEXT_XOBJFIELDURL force;
    create index ADSOTEXT_XOBJFIELDURL on ADSOTEXT(OBJFIELDURL) indextype is ctxsys.context
    parameters
    ('datastore ctxsys.file_datastore
    filter ctxsys.inso_filter
    lexer global_lexer
    language column OBJFIELDURLLANG
    charset column OBJFIELDURLCHARSET
    format column OBJFIELDURLFORMAT
    section group axmlgroup
    Wordlist wildcard_pref
    SYNC (EVERY "trunc(sysdate+10/480,''MI'')" )
    The first time we insert a row for a file in the table ADSOTEXT, Oracle will process synchronization of information around 30 minutes later.
    But if we update file information, so we make an update for this file on an existing row of the table,
    Oracle seem to first remove every indexation information relating to that file and process synchronizaton 30 minutes later : this is
    a little bit annoying because we won't be able to find this file through a search for around 30 minutes.
    Is there a way to make those 2 steps made at the same time ?(ie unundexing words and synchronization)
    NB :
    My English is quite poor so there are things that I can't completely understand in the Oracle text documentation :
    I'm reading about the option TRANSACTIONAL while creating Oracle Text indexes and as far as I can understnd, it should solve my problems : I'am right ?
    Quote from Oracle text documentation :
    "Specify that documents can be searched immediately after they are inserted or updated. If a text index is created with TRANSACTIONAL enabled, then, in addition to
    processing the synchronized rowids already in the index, the CONTAINS operator will process unsynchronized rowids as well. (That is, Oracle Text does in-memory indexing of unsynchronized rowids and processes the query against the in-memory index.)"
    Message was edited by:
    perigee_dev2
    Message was edited by:
    perigee_dev2

    The first time we insert a row for a file in the
    table ADSOTEXT, Oracle will process synchronization
    of information around 30 minutes later.
    But if we update file information, so we make an
    update for this file on an existing row of the
    table,
    Oracle seem to first remove every indexation
    information relating to that file and process
    synchronizaton 30 minutes later : this is
    a little bit annoying because we won't be able to
    find this file through a search for around 30
    minutes.Yes it is so. Friend of me have this issue too. I personaly use ctxcat index and build of this index is transactional - after commit.
    Is there a way to make those 2 steps made at the same
    time ?(ie unundexing words and synchronization)How to use shorter interval? Every minute?
    Do you use 10g?
    dap

  • Extracting an oracle text indextype

    oracle version 10.2.0.5
    I am working on an old legacy database that has a custom indextype used by oracle text. I am not sure how to extract it. Export does not get it. I tried using
    dbms_metadata.get_ddl, I get object of type indextype not found in the schema. I am using the correct object and schema name. I found it in DBA_INDEXTYPES.
    I am not sure how to issue a create indextype based on what I found in dba_indextypes
    I cannot use data pump due to a bug that is version/platform/upgrade specific (not looking for help on this).
    I have not used oracle text often and whenever I used it, I used the built in create indextype.

    What does DBA_OBJECTS say about that index?
    :p

Maybe you are looking for

  • Japanese Data cannot be displayed correctly

    Hi, We are using Java 1.2 (upgrading to 1.5), iPlanet_sp5 and oracle 9i database. Suddenly from the 31st of May 2006, the data can not be displayed correctly on the browser. The data is OK in the database and also the oracle reports generated are ok.

  • HT201269 how can i restore my iPad?

    how can i restore my iPad?

  • Rel 3.0 and Oracle

    Debbie, 2.0 of Forte Utilized a specific connection String. Example efudd.MED (WHERE efudd was the specific machine name and MED was the Oracle SID Reference. 3.0 of Forte has changed where they are more "OPEN" and are completely utilizing Oracle. Th

  • Gateway Security parameter

    Hi Team, My EWA report is showing red alert, as the sec_info & reg_info file is containing default entries(P TP=* etc). For a new system we can add the entries to the list easily, but what should be done for an existing system? Can anyone help me wit

  • I need help with my code - arrayoutofboundsexception

    This code looks okay to me. its supposed to accept int inputs from users and store them in an array. I have set the max size of the final array to 5 for test purposes. but surprisingly, i get an arrayindexoutofbounds exception. your help would be mos