Is it right query using ft:search ?

Tuesday, 19 November 2013 · 4 messages · last reply 20 Nov 2013
JB
John Best19 Nov 2013 09:08 #
Hi Team, Below is my XML Structure -
<Docs>
 <Doc>
    <DocTitle C="1"></DocTitle>
    <MainDesc></MainDesc>
    <FullDesc></FullDesc>
 </Doc>
 <Doc>
    <DocTitle C="2"></DocTitle>
    <MainDesc></MainDesc>
    <FullDesc></FullDesc>
 </Doc>
............
............

</Docs>
I have to search the Full Text DB of above documents with 3 different options - 1. Complete Document 2. Only in MainDesc (Main Description) 3. Only in FullDesc (Full Description) Below is the query, using ft:search, for the first options, mentioned above
for $x in ft:search("docMaster", ("emf","waves"), map{'mode':='all
words'})/ancestor::*:Doc
return $x/DocTitle/text()
Now, this is for the 2nd options, i.e; for MainDesc -
for $x in ft:search("docMaster", ("emf","waves"), map{'mode':='all
words'})/ancestor::*:Doc/MainDesc
return $x/DocTitle/text()
Is it right ? I am little bit confused..
-- Have a nice day JBest
DK
Dirk Kirsten19 Nov 2013 11:03 #
Hello John, I guess your second query isn't really doing what you intend it to do. Actually, it will yield the same output as your first query (the child step /MainDesc will only have the effect that fragments without MainDesc as a child will be filtered out). I guess the following query should work (at least if I understood correctly what you are trying to achieve):
for $x in ft:search("docMaster", ("emf","waves"), map{'mode':='all
words'})/parent::*:MainDesc/parent::*:Doc
return $x/DocTitle/text()
Thereby, you using the parent step you assure that the found text node was actually inside a MainDesc node. Please also note that there is a difference between an ancestor step and a parent step and as you seem to know your structure it might be easier and faster to simply use parent. Cheers, Dirk
Quoted text · John Best · 53 lines
On 19/11/13 09:08, John Best wrote: > Hi Team, > > Below is my XML Structure - > > <Docs> > <Doc> > <DocTitle C="1"></DocTitle> > <MainDesc></MainDesc> > <FullDesc></FullDesc> > </Doc> > <Doc> > <DocTitle C="2"></DocTitle> > <MainDesc></MainDesc> > <FullDesc></FullDesc> > </Doc> > ............ > ............ > > </Docs> > > > I have to search the Full Text DB of above documents > with 3 different options - > > 1. Complete Document > > 2. Only in MainDesc (Main Description) > > 3. Only in FullDesc (Full Description) > > > Below is the query, using ft:search, for the first options, mentioned above > > for $x in ft:search("docMaster", ("emf","waves"), map{'mode':='all > words'})/ancestor::*:Doc > return $x/DocTitle/text() > > Now, this is for the 2nd options, i.e; for MainDesc - > > for $x in ft:search("docMaster", ("emf","waves"), map{'mode':='all > words'})/ancestor::*:Doc/MainDesc > return $x/DocTitle/text() > > Is it right ? I am little bit confused.. > > > > _______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >
-- Dirk Kirsten, BaseX GmbH, http://basex.org |-- Firmensitz: Blarerstrasse 56, 78462 Konstanz |-- Registergericht Freiburg, HRB: 708285, Geschäftsführer: | Dr. Christian Grün, Dr. Alexander Holupirek, Michael Seiferle `-- Phone: 0049 7531 28 28 676, Fax: 0049 7531 20 05 22
JB
John Best20 Nov 2013 06:11 #
Hi Dirk, Thanks for your reply.. What will be the query for the following structure - I tried your yesterday's query it achieved the result as required. My structure was not exactly the same as mentioned yesterday. I thought, I would modify it as per my structure. But, I was not successful. Below is my complete structure. I want to search the MainDesc, which have 2 child nodes viz; shortDesc and longDesc.
<Docs>
<Doc>
   <DocTitle C="1"></DocTitle>
   <MainDesc>
      <shortDesc></shortDesc>
      <longDesc>
             some text
            <B>to make the word(s) bold Optional</B> some text
            <I>to make the word(s) italic Optional</I> some text
            <U>to have an underline Optional</U> some text
             some text
      </longDesc>
    </MainDesc>
    <FullDesc></FullDesc>
</Doc>
</Docs>
------------------------------------------------------------------------- Hello John, I guess your second query isn't really doing what you intend it to do. Actually, it will yield the same output as your first query (the child step /MainDesc will only have the effect that fragments without MainDesc as a child will be filtered out). I guess the following query should work (at least if I understood correctly what you are trying to achieve): for $x in ft:search("docMaster", ("emf","waves"), map{'mode':='all words'})/parent::*:MainDesc/ parent::*:Doc return $x/DocTitle/text() Thereby, you using the parent step you assure that the found text node was actually inside a MainDesc node. Please also note that there is a difference between an ancestor step and a parent step and as you seem to know your structure it might be easier and faster to simply use parent. Cheers, Dirk
-- Have a nice day JBest
DK
Dirk Kirsten20 Nov 2013 07:06 #
Hi John, the query should be basically be the same, but with the now given structure you should rather use ancestor instead of parent, as the structure is not exactly known and where search hits might occur. So it should be:
for $x in ft:search("docMaster", ("emf","waves"), map{'mode':='all
words'})/ancestor::*:MainDesc/parent::*:Doc
return $x/DocTitle/text()
Please be also aware of the restrictions if you are searching within mixed content, e.g. when searching for "text" and "to" it will not return any match for this data. See https://docs.basex.org/wiki/Full-Text#Mixed_Content for more information. Cheers, Dirk
Quoted text · John Best · 69 lines
On 20/11/13 06:11, John Best wrote: > Hi Dirk, > > Thanks for your reply.. > What will be the query for the following structure - > > I tried your yesterday's query it achieved the result as required. My > structure > was not exactly the same as mentioned yesterday. I thought, I would modify > it as per my structure. But, I was not successful. Below is my complete > structure. > > I want to search the MainDesc, which have 2 child nodes viz; shortDesc and > longDesc. > > > <Docs> > <Doc> > <DocTitle C="1"></DocTitle> > <MainDesc> > <shortDesc></shortDesc> > <longDesc> > some text > <B>to make the word(s) bold Optional</B> some text > <I>to make the word(s) italic Optional</I> some text > <U>to have an underline Optional</U> some text > some text > </longDesc> > </MainDesc> > <FullDesc></FullDesc> > </Doc> > </Docs> > > > > ------------------------------------------------------------------------- > > > Hello John, > > I guess your second query isn't really doing what you intend it to do. > Actually, it will yield the same output as your first query (the child > step /MainDesc will only have the effect that fragments without MainDesc > as a child will be filtered out). I guess the following query should > work (at least if I understood correctly what you are trying to achieve): > > for $x in ft:search("docMaster", ("emf","waves"), map{'mode':='all > words'})/parent::*:MainDesc/ > parent::*:Doc > return $x/DocTitle/text() > > Thereby, you using the parent step you assure that the found text node > was actually inside a MainDesc node. > > Please also note that there is a difference between an ancestor step and > a parent step and as you seem to know your structure it might be easier > and faster to simply use parent. > > Cheers, > Dirk > > > > > _______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >
-- Dirk Kirsten, BaseX GmbH, http://basex.org |-- Firmensitz: Blarerstrasse 56, 78462 Konstanz |-- Registergericht Freiburg, HRB: 708285, Geschäftsführer: | Dr. Christian Grün, Dr. Alexander Holupirek, Michael Seiferle `-- Phone: 0049 7531 28 28 676, Fax: 0049 7531 20 05 22

⚡Generated with XQuery