Skip to Main Content

Database Software

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Usage of Lexer attribut COMPOSITE

chris227Sep 5 2019 — edited Sep 10 2019

Hi,

I wonder how the effects of using the lexer attribut COMPOSITE can be applied.

Testcase

drop table test_lexer

/

create table test_lexer (txt varchar2(30))

/

insert into test_lexer values('nordbahnhof')

/

begin

   ctx_ddl.create_preference   ('test_lexer', 'BASIC_LEXER');

   ctx_ddl.set_attribute       ('test_lexer', 'COMPOSITE','GERMAN');

   ctx_ddl.create_preference   ('test_wordlist', 'BASIC_WORDLIST');

   ctx_ddl.set_attribute       ('test_wordlist', 'stemmer','GERMAN');

end;

/

CREATE INDEX idx_test_lexer on test_lexer(txt)

INDEXTYPE IS ctxsys.context PARAMETERS

('lexer test_lexer')

/

select token_text from dr$idx_test_lexer$i

/

select * from test_lexer

where contains (txt, 'nordbahnhof' ) > 0

/

select * from test_lexer

where contains (txt, 'bahnhof' ) > 0

/

select * from test_lexer

where contains (txt, 'nord' ) > 0

/

select * from test_lexer

where contains (txt, 'nord%' ) > 0

/

select * from test_lexer

where contains (txt, '%bahnhof' ) > 0

/

begin

   ctx_ddl.drop_preference   ('test_lexer');

   ctx_ddl.drop_preference   ('test_wordlist');

end;

/

drop table test_lexer

/

Output

>drop table test_lexer

  2  /

drop table test_lexer

           *

ERROR at line 1:

ORA-00942: table or view does not exist

>create table test_lexer (txt varchar2(30))

  2  /

Table created.

>insert into test_lexer values('nordbahnhof')

  2  /

1 row created.

>begin

  2     ctx_ddl.create_preference   ('test_lexer', 'BASIC_LEXER');

  3     ctx_ddl.set_attribute       ('test_lexer', 'COMPOSITE','GERMAN');

  4

  5     ctx_ddl.create_preference   ('test_wordlist', 'BASIC_WORDLIST');

  6     ctx_ddl.set_attribute       ('test_wordlist', 'stemmer','GERMAN');

  7  end;

  8  /

PL/SQL procedure successfully completed.

>CREATE INDEX idx_test_lexer on test_lexer(txt)

  2   INDEXTYPE IS ctxsys.context PARAMETERS

  3   ('lexer test_lexer')

  4  /

Index created.

>select token_text from dr$idx_test_lexer$i

  2  /

TOKEN_TEXT

----------------------------------------------------------------

BAHNHOF

NORD

NORDBAHNHOF

>select * from test_lexer

  2  where contains (txt, 'nordbahnhof' ) > 0

  3  /

TXT

------------------------------

nordbahnhof

>select * from test_lexer

  2  where contains (txt, 'bahnhof' ) > 0

  3  /

no rows selected

>select * from test_lexer

  2  where contains (txt, 'nord' ) > 0

  3  /

no rows selected

>select * from test_lexer

  2  where contains (txt, 'nord%' ) > 0

  3  /

TXT

------------------------------

nordbahnhof

>select * from test_lexer

  2  where contains (txt, '%bahnhof' ) > 0

  3  /

TXT

------------------------------

nordbahnhof

>begin

  2     ctx_ddl.drop_preference   ('test_lexer');

  3     ctx_ddl.drop_preference   ('test_wordlist');

  4  end;

  5  /

PL/SQL procedure successfully completed.

>drop table test_lexer

  2  /

Table dropped.

Since nord and bahnhof are indexed as separate tokens i would expect to get the row without the usage of wildcards.

However i cant get it work.

What am i missing?

Thanks and regards

Chris

This post has been answered by Roger Ford-Oracle on Sep 10 2019
Jump to Answer
Comments
Post Details
Added on Sep 5 2019
2 comments
205 views