2 Replies Latest reply: May 14, 2012 10:10 AM by amin_adatia RSS

    INPATH Query for Repeating Elements

    amin_adatia
      How do we use the XMLPath-like expression to search on repeating elements?

      Given two documents like:

      <!-- document 1 -->
      <label>
           <labeledEntities>
                <labeledEntity>
                     <type>file</type>
                     <label>hers</label>
                </labeledEntity>
                <labeledEntity>
                     <type>directory</type>
                     <label>his</label>
                </labeledEntity>
           </labeledEntities>
      </abel>

      <!-- document 2 -->
      <label>
           <labeledEntities>
                <labeledEntity>
                     <type>directory</type>
                     <label>hers</label>
                </labeledEntity>
                <labeledEntity>
                     <type>file</type>
                     <label>his</label>
                </labeledEntity>
           </labeledEntities>
      </abel>

      We do an INPATH XMLPath query like:

      ( (his) INPATH (//label) AND directory INPATH(//type) ) INPATH (/label/labeledEntities/labeledEntity) > 0

      We get hits for both documents, this is because the "//" is always done at the root of the document, it's not relative to the enclosing INPATH's (see "NESTED INPATH" http://docs.oracle.com/cd/B19306_01/appdev.102/b14259/xdb09sea.htm#CBBGJDGC).

      If we rewrite the select using the "Example 10-23 Nested INPATH Rewritten" from the previously mentioned page as a guide, we get:

      ( (his) INPATH /label/labeledEntities/labeledEntity[type = "directory"]/label ) > 0

      But, we get no hits.
        • 1. Re: INPATH Query for Repeating Elements
          Roger Ford-Oracle
          You are aware that "his" is a stopword? This works...
          drop table ip;
          
          create table ip (text varchar2(2000));
          
          insert into ip values ('
          <label>
            <labeledEntities>
              <labeledEntity>
                <type>file</type>
                <label>hers</label>
              </labeledEntity>
              <labeledEntity>
                <type>directory</type>
                <label>his</label>
              </labeledEntity>
            </labeledEntities>
          </label>
          ');
          
          insert into ip values ('
          <label>
            <labeledEntities>
              <labeledEntity>
                <type>directory</type>
                <label>hers</label>
              </labeledEntity>
              <labeledEntity>
                <type>file</type>
                <label>his</label>
              </labeledEntity>
            </labeledEntities>
          </label>
          ');
          
          exec ctx_ddl.drop_section_group('ipsg')
          exec ctx_ddl.create_section_group('ipsg', 'PATH_SECTION_GROUP')
          
          create index idind on ip(text) indextype is ctxsys.context
          parameters ('section group ipsg stoplist ctxsys.empty_stoplist');
          
          set feedback 1
          
          select * from ip where contains (text, 
          '( (his) INPATH (//label) AND directory INPATH(//type) ) INPATH (/label/labeledEntities/labeledEntity)') > 0;
          
          select * from ip where contains (text, 
          'his INPATH (//label/labeledEntities/labeledEntity[type="directory"]/label) ' ) > 0;