Forum Stats

  • 3,824,755 Users
  • 2,260,414 Discussions
  • 7,896,306 Comments

Discussions

Make this string searchable: <!--

pcpaasche
pcpaasche Member Posts: 100 Blue Ribbon
edited Jan 29, 2018 9:08PM in Text

My environment:

Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production

PL/SQL Release 12.1.0.2.0 - Production

CORE 12.1.0.2.0 Production

TNS for Linux: Version 12.1.0.2.0 - Production

NLSRTL Version 12.1.0.2.0 - Production

Question:

I would like to make this string searchable by Oracle Text: <!--

That string represent the start of a comment in C# and I would like to find such strings using Oracle Text.

How can I do that?

Fyi, we have already Oracle Text up and running and we are using it with great success. However, the string in this question is currently not possible to find.

Please let me know if you need more information.

Answers

  • Barbara Boehmer
    Barbara Boehmer Member Posts: 4,625 Gold Trophy
    edited Jan 29, 2018 9:08PM

    Please see the demonstration with comments below.

    [email protected]_12.1.0.2.0> -- environment:
    [email protected]_12.1.0.2.0> select banner from v$version
      2  /

    BANNER
    --------------------------------------------------------------------------------
    Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
    PL/SQL Release 12.1.0.2.0 - Production
    CORE 12.1.0.2.0 Production
    TNS for 64-bit Windows: Version 12.1.0.2.0 - Production
    NLSRTL Version 12.1.0.2.0 - Production

    5 rows selected.

    [email protected]_12.1.0.2.0> -- table and data for demonstration:
    [email protected]_12.1.0.2.0> create table test_tab (test_col varchar2(30))
      2  /

    Table created.

    [email protected]_12.1.0.2.0> insert all
      2  into test_tab (test_col) values ('<!--whatever')
      3  into test_tab (test_col) values ('whatever<!--')
      4  into test_tab (test_col) values ('<!-- whatever')
      5  into test_tab (test_col) values ('whatever <!--')
      6  into test_tab (test_col) values ('whatever')
      7  select * from dual
      8  /

    5 rows created.

    [email protected]_12.1.0.2.0> -- lexer with < and ! and - as printjoins:
    [email protected]_12.1.0.2.0> begin
      2    ctx_ddl.create_preference ('test_lex', 'basic_lexer');
      3    ctx_ddl.set_attribute ('test_lex', 'printjoins', '<!-');
      4  end;
      5  /

    PL/SQL procedure successfully completed.

    [email protected]_12.1.0.2.0> -- index that uses the lexer in the parameters:
    [email protected]_12.1.0.2.0> create index test_idx on test_tab (test_col) indextype is ctxsys.context
      2    parameters ('lexer test_lex')
      3  /

    Index created.

    [email protected]_12.1.0.2.0> -- tokens resulting from index creation:
    [email protected]_12.1.0.2.0> select token_text from dr$test_idx$i
      2  /

    TOKEN_TEXT
    ----------------------------------------------------------------
    <!--
    <!--WHATEVER
    WHATEVER
    WHATEVER<!--

    4 rows selected.

    [email protected]_12.1.0.2.0> -- search for <!-- using \ to escape special characters where <!-- stands alone:
    [email protected]_12.1.0.2.0> select * from test_tab where contains (test_col, '\<\!\-\-') > 0
      2  /

    TEST_COL
    ------------------------------
    <!-- whatever
    whatever <!--

    2 rows selected.

    [email protected]_12.1.0.2.0> -- search for <!-- using wildcards where <!-- stands alone or as part of a token:
    [email protected]_12.1.0.2.0> select * from test_tab where contains (test_col, '%\<\!\-\-%') > 0
      2  /

    TEST_COL
    ------------------------------
    <!--whatever
    whatever<!--
    <!-- whatever
    whatever <!--

    4 rows selected.

This discussion has been closed.