How to use ft:search() for querying 2 or more phrases?
Hi BaseX Team,
The subject itself is explanatory. I have following query -
ft:search("Articles", ("electromagnetic waves"), map { 'mode':='Phrase'
})/ancestor::Doc
return $xThis query searches for "electromagnetic waves" as a phrase. I want to search another phrase "electromagnetic particles" with the previous phrase.
List only those Articles having both these phrases.
Hi John,
What about using the intersect operator on the two result sets ?
Best regards, Fabrice Etanchaud Questel/Orbit
Quoted text · John Best · 13 lines
De : basex-talk-bounces at mailman.uni-konstanz.de [mailto:basex-talk-bounces at mailman.uni-konstanz.de] De la part de John Best Envoyé : vendredi 28 novembre 2014 10:35 À : basex-talk at mailman.uni-konstanz.de Objet : [basex-talk] How to use ft:search() for querying 2 or more phrases? Hi BaseX Team, The subject itself is explanatory. I have following query - ft:search("Articles", ("electromagnetic waves"), map { 'mode':='Phrase' })/ancestor::Doc return $x This query searches for "electromagnetic waves" as a phrase. I want to search another phrase "electromagnetic particles" with the previous phrase. List only those Articles having both these phrases. -- Have a nice day JBest
Hi John,
You can specify more than one search string with ft:search [2]:
ft:search("Articles",
("electromagnetic waves", "electromagnetic particles")
)/ancestor::DocIn your case, the "phrase" option is not required, because it creates a single string from all of your search strings. Please see [1] for more information on the search modes.
Best, Christian
[1] http://docs.basex.org/wiki/Full-Text_Module#ft:search [2] http://docs.basex.org/wiki/Full-Text#Combining_Results
Quoted text · John Best · 20 lines
On Fri, Nov 28, 2014 at 10:34 AM, John Best <johnbest5673 at gmail.com> wrote: > Hi BaseX Team, > > The subject itself is explanatory. I have following query - > > ft:search("Articles", ("electromagnetic waves"), map { 'mode':='Phrase' > })/ancestor::Doc > return $x > > This query searches for "electromagnetic waves" as a phrase. I want to > search another phrase "electromagnetic particles" with the previous phrase. > > > List only those Articles having both these phrases. > > -- > Have a nice day > JBest > >
Hi Fabrice,
Thanks a lot. How come I forgot this !!!
Now my query will be -
for $x in
ft:search("Articles", ("electromagnetic waves"), map { 'mode':='Phrase'
})/ancestor::Doc
intersect
ft:search("Articles", ("electromagnetic particles"), map { 'mode':='Phrase'
})/ancestor::Doc
return $xAgain thanks a lot :)
Quoted text · Fabrice Etanchaud · 49 lines
On Fri, Nov 28, 2014 at 3:11 PM, Fabrice Etanchaud <fetanchaud at questel.com> wrote: > Hi John, > > > > What about using the intersect operator on the two result sets ? > > > > Best regards, > > Fabrice Etanchaud > > Questel/Orbit > > > > > > *De :* basex-talk-bounces at mailman.uni-konstanz.de [mailto: > basex-talk-bounces at mailman.uni-konstanz.de] *De la part de* John Best > *Envoyé :* vendredi 28 novembre 2014 10:35 > *À :* basex-talk at mailman.uni-konstanz.de > *Objet :* [basex-talk] How to use ft:search() for querying 2 or more > phrases? > > > > Hi BaseX Team, > > The subject itself is explanatory. I have following query - > > ft:search("Articles", ("electromagnetic waves"), map { 'mode':='Phrase' > })/ancestor::Doc > return $x > > This query searches for "electromagnetic waves" as a phrase. I want to > search another phrase "electromagnetic particles" with the previous phrase. > > List only those Articles having both these phrases. > > > -- > > Have a nice day > JBest > >
Well… [2] was supposed to be [1], and [1] should be [2].
Quoted text · Christian Grün · 38 lines
> You can specify more than one search string with ft:search [2]: > > ft:search("Articles", > ("electromagnetic waves", "electromagnetic particles") > )/ancestor::Doc > > In your case, the "phrase" option is not required, because it creates > a single string from all of your search strings. Please see [1] for > more information on the search modes. > > Best, > Christian > > [1] http://docs.basex.org/wiki/Full-Text_Module#ft:search > [2] http://docs.basex.org/wiki/Full-Text#Combining_Results > > > > On Fri, Nov 28, 2014 at 10:34 AM, John Best <johnbest5673 at gmail.com> wrote: >> Hi BaseX Team, >> >> The subject itself is explanatory. I have following query - >> >> ft:search("Articles", ("electromagnetic waves"), map { 'mode':='Phrase' >> })/ancestor::Doc >> return $x >> >> This query searches for "electromagnetic waves" as a phrase. I want to >> search another phrase "electromagnetic particles" with the previous phrase. >> >> >> List only those Articles having both these phrases. >> >> -- >> Have a nice day >> JBest >> >>
Hi Christian,
Thanks for the reply.
Using intersect, results in 5 Articles. Whereas you suggestion with -
ft:search("Articles",
("electromagnetic waves", "electromagnetic particles")
)/ancestor::Docresults in 218 Articles.
Why the difference of 213 ? I am checking some of these additional, do they have both phrases. Will come back again.
Quoted text · Christian Grün · 45 lines
On Fri, Nov 28, 2014 at 3:52 PM, Christian Grün <christian.gruen at gmail.com> wrote: > Hi John, > > You can specify more than one search string with ft:search [2]: > > ft:search("Articles", > ("electromagnetic waves", "electromagnetic particles") > )/ancestor::Doc > > In your case, the "phrase" option is not required, because it creates > a single string from all of your search strings. Please see [1] for > more information on the search modes. > > Best, > Christian > > [1] http://docs.basex.org/wiki/Full-Text_Module#ft:search > [2] http://docs.basex.org/wiki/Full-Text#Combining_Results > > > > On Fri, Nov 28, 2014 at 10:34 AM, John Best <johnbest5673 at gmail.com> > wrote: > > Hi BaseX Team, > > > > The subject itself is explanatory. I have following query - > > > > ft:search("Articles", ("electromagnetic waves"), map { 'mode':='Phrase' > > })/ancestor::Doc > > return $x > > > > This query searches for "electromagnetic waves" as a phrase. I want to > > search another phrase "electromagnetic particles" with the previous > phrase. > > > > > > List only those Articles having both these phrases. > > > > -- > > Have a nice day > > JBest > > > > >
Dear John
Maybe you should add the following option :
map { 'mode':'all' }
because ’any’ is the default.
Best regards, Fabrice
Quoted text · John Best · 50 lines
De : basex-talk-bounces at mailman.uni-konstanz.de [mailto:basex-talk-bounces at mailman.uni-konstanz.de] De la part de John Best Envoyé : vendredi 28 novembre 2014 11:32 À : Christian Grün Cc : BaseX Objet : Re: [basex-talk] How to use ft:search() for querying 2 or more phrases? Hi Christian, Thanks for the reply. Using intersect, results in 5 Articles. Whereas you suggestion with - ft:search("Articles", ("electromagnetic waves", "electromagnetic particles") )/ancestor::Doc results in 218 Articles. Why the difference of 213 ? I am checking some of these additional, do they have both phrases. Will come back again. On Fri, Nov 28, 2014 at 3:52 PM, Christian Grün <christian.gruen at gmail.com<mailto:christian.gruen at gmail.com>> wrote: Hi John, You can specify more than one search string with ft:search [2]: ft:search("Articles", ("electromagnetic waves", "electromagnetic particles") )/ancestor::Doc In your case, the "phrase" option is not required, because it creates a single string from all of your search strings. Please see [1] for more information on the search modes. Best, Christian [1] http://docs.basex.org/wiki/Full-Text_Module#ft:search [2] http://docs.basex.org/wiki/Full-Text#Combining_Results On Fri, Nov 28, 2014 at 10:34 AM, John Best <johnbest5673 at gmail.com<mailto:johnbest5673 at gmail.com>> wrote: > Hi BaseX Team, > > The subject itself is explanatory. I have following query - > > ft:search("Articles", ("electromagnetic waves"), map { 'mode':='Phrase' > })/ancestor::Doc > return $x > > This query searches for "electromagnetic waves" as a phrase. I want to > search another phrase "electromagnetic particles" with the previous phrase. > > > List only those Articles having both these phrases. > > -- > Have a nice day > JBest > > -- Have a nice day JBest
Hi Team,
The first example mentioned here ( http://docs.basex.org/wiki/Full-Text_Module#ft:search ) is -
ft:search("db", ("A", "B"), map {
"mode": "all words",
"distance": {
"max": "5",
"unit": "words"
}
})If I modify this to my requirement it will be - ft:search("db", ("A", "B"), map {"mode": "phrase"})
To me this means that, above will search nodes containing, phrase "A" and "B" both.
So my query then will be -
for $x in ft:search("Articles", ("electromagnetic waves", "electromagnetic
particles"), map { 'mode':='phrase' })/ancestor::Doc
return $xBut when I execute this, I get 0 result, even though, I had 5 articles. Am I wrong ? As suggested by Fabrice, intersect results in 5.
Quoted text · Fabrice Etanchaud · 111 lines
On Fri, Nov 28, 2014 at 4:06 PM, Fabrice Etanchaud <fetanchaud at questel.com> wrote: > Dear John > > > > Maybe you should add the following option : > > > > map { 'mode':'all' } > > > > because ’any’ is the default. > > > > Best regards, > > Fabrice > > > > *De :* basex-talk-bounces at mailman.uni-konstanz.de [mailto: > basex-talk-bounces at mailman.uni-konstanz.de] *De la part de* John Best > *Envoyé :* vendredi 28 novembre 2014 11:32 > *À :* Christian Grün > *Cc :* BaseX > *Objet :* Re: [basex-talk] How to use ft:search() for querying 2 or more > phrases? > > > > Hi Christian, > > Thanks for the reply. > > Using intersect, results in 5 Articles. Whereas you suggestion with - > > ft:search("Articles", > ("electromagnetic waves", "electromagnetic particles") > )/ancestor::Doc > > results in 218 Articles. > > Why the difference of 213 ? > > I am checking some of these additional, do they have both phrases. Will > come back again. > > > > > > On Fri, Nov 28, 2014 at 3:52 PM, Christian Grün <christian.gruen at gmail.com> > wrote: > > Hi John, > > You can specify more than one search string with ft:search [2]: > > ft:search("Articles", > ("electromagnetic waves", "electromagnetic particles") > )/ancestor::Doc > > In your case, the "phrase" option is not required, because it creates > a single string from all of your search strings. Please see [1] for > more information on the search modes. > > Best, > Christian > > [1] http://docs.basex.org/wiki/Full-Text_Module#ft:search > [2] http://docs.basex.org/wiki/Full-Text#Combining_Results > > > > > On Fri, Nov 28, 2014 at 10:34 AM, John Best <johnbest5673 at gmail.com> > wrote: > > Hi BaseX Team, > > > > The subject itself is explanatory. I have following query - > > > > ft:search("Articles", ("electromagnetic waves"), map { 'mode':='Phrase' > > })/ancestor::Doc > > return $x > > > > This query searches for "electromagnetic waves" as a phrase. I want to > > search another phrase "electromagnetic particles" with the previous > phrase. > > > > > > List only those Articles having both these phrases. > > > > -- > > Have a nice day > > JBest > > > > > > > > > -- > > Have a nice day > JBest > >
Hi John,
Sorry, but I'll simply repeat my initial mail:
Quoted text · John Best · 3 lines
>> In your case, the "phrase" option is not required, because it creates >> a single string from all of your search strings. Please see [1] for >> more information on the search modes.
In other words, your query…
Quoted text · John Best · 2 lines
> If I modify this to my requirement it will be - ft:search("db", ("A", "B"), > map {"mode": "phrase"})
…is equivalent to:
ft:search("db", ("A B"))If you believe that the information in our Wiki is not clear enough and could be improved, your feedback is more than welcome (as usual, *any* edits to our Wiki are welcome).
Best, Christian
Quoted text · John Best · 129 lines
> for $x in ft:search("Articles", ("electromagnetic waves", "electromagnetic > particles"), map { 'mode':='phrase' })/ancestor::Doc > return $x > > But when I execute this, I get 0 result, even though, I had 5 articles. Am I > wrong ? > As suggested by Fabrice, intersect results in 5. > > > > On Fri, Nov 28, 2014 at 4:06 PM, Fabrice Etanchaud <fetanchaud at questel.com> > wrote: >> >> Dear John >> >> >> >> Maybe you should add the following option : >> >> >> >> map { 'mode':'all' } >> >> >> >> because ’any’ is the default. >> >> >> >> Best regards, >> >> Fabrice >> >> >> >> De : basex-talk-bounces at mailman.uni-konstanz.de >> [mailto:basex-talk-bounces at mailman.uni-konstanz.de] De la part de John Best >> Envoyé : vendredi 28 novembre 2014 11:32 >> À : Christian Grün >> Cc : BaseX >> Objet : Re: [basex-talk] How to use ft:search() for querying 2 or more >> phrases? >> >> >> >> Hi Christian, >> >> Thanks for the reply. >> >> Using intersect, results in 5 Articles. Whereas you suggestion with - >> >> ft:search("Articles", >> ("electromagnetic waves", "electromagnetic particles") >> )/ancestor::Doc >> >> results in 218 Articles. >> >> Why the difference of 213 ? >> >> I am checking some of these additional, do they have both phrases. Will >> come back again. >> >> >> >> >> >> On Fri, Nov 28, 2014 at 3:52 PM, Christian Grün >> <christian.gruen at gmail.com> wrote: >> >> Hi John, >> >> You can specify more than one search string with ft:search [2]: >> >> ft:search("Articles", >> ("electromagnetic waves", "electromagnetic particles") >> )/ancestor::Doc >> >> In your case, the "phrase" option is not required, because it creates >> a single string from all of your search strings. Please see [1] for >> more information on the search modes. >> >> Best, >> Christian >> >> [1] http://docs.basex.org/wiki/Full-Text_Module#ft:search >> [2] http://docs.basex.org/wiki/Full-Text#Combining_Results >> >> >> >> >> On Fri, Nov 28, 2014 at 10:34 AM, John Best <johnbest5673 at gmail.com> >> wrote: >> > Hi BaseX Team, >> > >> > The subject itself is explanatory. I have following query - >> > >> > ft:search("Articles", ("electromagnetic waves"), map { 'mode':='Phrase' >> > })/ancestor::Doc >> > return $x >> > >> > This query searches for "electromagnetic waves" as a phrase. I want to >> > search another phrase "electromagnetic particles" with the previous >> > phrase. >> > >> > >> > List only those Articles having both these phrases. >> > >> > -- >> > Have a nice day >> > JBest >> > >> > >> >> >> >> >> -- >> >> Have a nice day >> JBest >> > > > > -- > Have a nice day > JBest > >
Written for BaseX 7.9. BaseX may have changed since: please check the current documentation.