You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by Roy Teeuwen <ro...@teeuwen.be> on 2017/01/11 17:18:15 UTC

Escaping % sign in a query

Hey all,

I am trying to do a query where the actual word I am looking for looks like %%myword%%. I have tried the following in XPATH and JCR_SQL2, but it seems that the % sign is in both query languages a wildcard, meaning i will find all the nodes containing myword instead of %%myword%%. How can I escape the % sign in either XPATH or JCR_SQL2?

JCR_SQL2:
	SELECT * FROM [nt:base] AS s WHERE ISDESCENDANTNODE([/myfolder]) and CONTAINS(s.*, '%%myword%%')

XPATH:
	/jcr:root/myfolder//*[jcr:contains(., '%%myword%%')] 

Thanks!
Roy

Re: Escaping % sign in a query

Posted by Clay Ferguson <wc...@gmail.com>.
I would try searching the entire JCR codebase for the word "escape" or for
"%" char, for now, but I bet in under 24hrs one of the better experts than
me answers. It's either a simple solution or else a plain bug in the search
JCR core, but i don't know because i haven't "fixed this" in my own JCR
code yet either.

Best regards,
Clay Ferguson
wclayf@gmail.com


On Wed, Jan 11, 2017 at 2:15 PM, Roy Teeuwen <ro...@teeuwen.be> wrote:

> Yes i did ;), same results
>
> Greets,
> Roy
> > On 11 Jan 2017, at 18:30, Clay Ferguson <wc...@gmail.com> wrote:
> >
> > did you try this?
> >
> > CONTAINS(s.*, '\%\%myword\%\%')
> >
> > Best regards,
> > Clay Ferguson
> > wclayf@gmail.com
> >
> >
> > On Wed, Jan 11, 2017 at 11:18 AM, Roy Teeuwen <ro...@teeuwen.be> wrote:
> >
> >> Hey all,
> >>
> >> I am trying to do a query where the actual word I am looking for looks
> >> like %%myword%%. I have tried the following in XPATH and JCR_SQL2, but
> it
> >> seems that the % sign is in both query languages a wildcard, meaning i
> will
> >> find all the nodes containing myword instead of %%myword%%. How can I
> >> escape the % sign in either XPATH or JCR_SQL2?
> >>
> >> JCR_SQL2:
> >>        SELECT * FROM [nt:base] AS s WHERE ISDESCENDANTNODE([/myfolder])
> >> and CONTAINS(s.*, '%%myword%%')
> >>
> >> XPATH:
> >>        /jcr:root/myfolder//*[jcr:contains(., '%%myword%%')]
> >>
> >> Thanks!
> >> Roy
>
>

Re: Escaping % sign in a query

Posted by Roy Teeuwen <ro...@teeuwen.be>.
Yes i did ;), same results

Greets,
Roy
> On 11 Jan 2017, at 18:30, Clay Ferguson <wc...@gmail.com> wrote:
> 
> did you try this?
> 
> CONTAINS(s.*, '\%\%myword\%\%')
> 
> Best regards,
> Clay Ferguson
> wclayf@gmail.com
> 
> 
> On Wed, Jan 11, 2017 at 11:18 AM, Roy Teeuwen <ro...@teeuwen.be> wrote:
> 
>> Hey all,
>> 
>> I am trying to do a query where the actual word I am looking for looks
>> like %%myword%%. I have tried the following in XPATH and JCR_SQL2, but it
>> seems that the % sign is in both query languages a wildcard, meaning i will
>> find all the nodes containing myword instead of %%myword%%. How can I
>> escape the % sign in either XPATH or JCR_SQL2?
>> 
>> JCR_SQL2:
>>        SELECT * FROM [nt:base] AS s WHERE ISDESCENDANTNODE([/myfolder])
>> and CONTAINS(s.*, '%%myword%%')
>> 
>> XPATH:
>>        /jcr:root/myfolder//*[jcr:contains(., '%%myword%%')]
>> 
>> Thanks!
>> Roy


Re: Escaping % sign in a query

Posted by Clay Ferguson <wc...@gmail.com>.
did you try this?

CONTAINS(s.*, '\%\%myword\%\%')

Best regards,
Clay Ferguson
wclayf@gmail.com


On Wed, Jan 11, 2017 at 11:18 AM, Roy Teeuwen <ro...@teeuwen.be> wrote:

> Hey all,
>
> I am trying to do a query where the actual word I am looking for looks
> like %%myword%%. I have tried the following in XPATH and JCR_SQL2, but it
> seems that the % sign is in both query languages a wildcard, meaning i will
> find all the nodes containing myword instead of %%myword%%. How can I
> escape the % sign in either XPATH or JCR_SQL2?
>
> JCR_SQL2:
>         SELECT * FROM [nt:base] AS s WHERE ISDESCENDANTNODE([/myfolder])
> and CONTAINS(s.*, '%%myword%%')
>
> XPATH:
>         /jcr:root/myfolder//*[jcr:contains(., '%%myword%%')]
>
> Thanks!
> Roy

Re: Escaping % sign in a query

Posted by Thomas Mueller <mu...@adobe.com>.
Hi,

> do you think the % character is already parsed out when it is put in the
>index?

Yes.

> 
>Or is the % character inside the fulltext index.

I think there is a way to configure the fulltext index to include those
characters, but I'm not an expert for that. I would check
indexOriginalTerm at
http://jackrabbit.apache.org/oak/docs/query/lucene.html
(https://lucene.apache.org/core/4_4_0/analyzers-common/org/apache/lucene/an
alysis/miscellaneous/WordDelimiterFilter.html - PRESERVE_ORIGINAL).

Regards,
Thomas


Re: Escaping % sign in a query

Posted by Roy Teeuwen <ro...@teeuwen.be>.
Hey Thomas,

That seems to work indeed :), but regretfully it has to be full text search, I don't know the property name beforehand.. 

Just to make sure I fully understand why it doesn't work with full text searching, do you think the % character is already parsed out when it is put in the index? 
Or is the % character inside the fulltext index.

Greets,
Roy
> On 12 Jan 2017, at 14:08, Thomas Mueller <mu...@adobe.com> wrote:
> 
> Hi,
> 
> If you know the property where this word can appear, you could use
> "like([property], '%\%\%myword\%\%%')". For "like", '%' is a wildcard
> (same as for SQL), so you must not escape the first and last character.
> But because you want to search for '%', you need to escape all other cases.
> 
> Regards,
> Thomas
> 
> 
> 
> 
> On 12/01/17 12:36, "Roy Teeuwen" <ro...@teeuwen.be> wrote:
> 
>> Hey Thomas,
>> 
>> Thanks for the info!
>> 
>> I am using Jackrabbit Oak. (version 1.2.17). The thing is that  I would
>> like to prefer to not find all the nodes that contain myword but not
>> %%myword%%, seeing as myword could for example be 'site', and this would
>> return too many results, I only want the results that really contain
>> '%%site%%', not just 'site'
>> 
>> I have tried the \ escape character, unfortunately both returning the
>> same result as without escape character
>> 
>> 	/jcr:root/myfolder//*[jcr:contains(., '\%\%myword\%\%')]
>> 	SELECT * FROM [nt:base] AS s WHERE ISDESCENDANTNODE([/myfolder]) and
>> CONTAINS(s.*, '\%\%myword\%\%')
>> 
>> Do you see any other option without having to use
>> /jcr:root/myfolder//*[jcr:contains(., 'myword')] and  iterate all the
>> results in java to check for %%myword%%?
>> 
>> Thanks!
>> Roy
>> 
>>> On 12 Jan 2017, at 11:52, Thomas Mueller <mu...@adobe.com> wrote:
>>> 
>>> Hi,
>>> 
>>> For jcr:contains, the escape character is '\'. Maybe the problem is that
>>> the fulltext index is not configured to index special characters such
>>> as %
>>> (it depends on the configuration; see "analyzed"). I would try this:
>>> 
>>>   /jcr:root/myfolder//*[jcr:contains(., 'myword')]
>>> 
>>> 
>>> There might be also a difference between Jackrabbit 2.x and Jackrabbit
>>> Oak. Which one (and which version) do you use?
>>> 
>>> Regards,
>>> Thomas
>>> 
>>> 
>>> 
>>> On 11/01/17 18:18, "Roy Teeuwen" <ro...@teeuwen.be> wrote:
>>> 
>>>> Hey all,
>>>> 
>>>> I am trying to do a query where the actual word I am looking for looks
>>>> like %%myword%%. I have tried the following in XPATH and JCR_SQL2, but
>>>> it
>>>> seems that the % sign is in both query languages a wildcard, meaning i
>>>> will find all the nodes containing myword instead of %%myword%%. How
>>>> can
>>>> I escape the % sign in either XPATH or JCR_SQL2?
>>>> 
>>>> JCR_SQL2:
>>>> 	SELECT * FROM [nt:base] AS s WHERE ISDESCENDANTNODE([/myfolder]) and
>>>> CONTAINS(s.*, '%%myword%%')
>>>> 
>>>> XPATH:
>>>> 	/jcr:root/myfolder//*[jcr:contains(., '%%myword%%')]
>>>> 
>>>> Thanks!
>>>> Roy
>>> 
>> 
> 


Re: Escaping % sign in a query

Posted by Thomas Mueller <mu...@adobe.com>.
Hi,

If you know the property where this word can appear, you could use
"like([property], '%\%\%myword\%\%%')". For "like", '%' is a wildcard
(same as for SQL), so you must not escape the first and last character.
But because you want to search for '%', you need to escape all other cases.

Regards,
Thomas




On 12/01/17 12:36, "Roy Teeuwen" <ro...@teeuwen.be> wrote:

>Hey Thomas,
>
>Thanks for the info!
>
>I am using Jackrabbit Oak. (version 1.2.17). The thing is that  I would
>like to prefer to not find all the nodes that contain myword but not
>%%myword%%, seeing as myword could for example be 'site', and this would
>return too many results, I only want the results that really contain
>'%%site%%', not just 'site'
>
>I have tried the \ escape character, unfortunately both returning the
>same result as without escape character
>
>	/jcr:root/myfolder//*[jcr:contains(., '\%\%myword\%\%')]
>	SELECT * FROM [nt:base] AS s WHERE ISDESCENDANTNODE([/myfolder]) and
>CONTAINS(s.*, '\%\%myword\%\%')
>
>Do you see any other option without having to use
>/jcr:root/myfolder//*[jcr:contains(., 'myword')] and  iterate all the
>results in java to check for %%myword%%?
>
>Thanks!
>Roy
>
>> On 12 Jan 2017, at 11:52, Thomas Mueller <mu...@adobe.com> wrote:
>> 
>> Hi,
>> 
>> For jcr:contains, the escape character is '\'. Maybe the problem is that
>> the fulltext index is not configured to index special characters such
>>as %
>> (it depends on the configuration; see "analyzed"). I would try this:
>> 
>>    /jcr:root/myfolder//*[jcr:contains(., 'myword')]
>> 
>> 
>> There might be also a difference between Jackrabbit 2.x and Jackrabbit
>> Oak. Which one (and which version) do you use?
>> 
>> Regards,
>> Thomas
>> 
>> 
>> 
>> On 11/01/17 18:18, "Roy Teeuwen" <ro...@teeuwen.be> wrote:
>> 
>>> Hey all,
>>> 
>>> I am trying to do a query where the actual word I am looking for looks
>>> like %%myword%%. I have tried the following in XPATH and JCR_SQL2, but
>>>it
>>> seems that the % sign is in both query languages a wildcard, meaning i
>>> will find all the nodes containing myword instead of %%myword%%. How
>>>can
>>> I escape the % sign in either XPATH or JCR_SQL2?
>>> 
>>> JCR_SQL2:
>>> 	SELECT * FROM [nt:base] AS s WHERE ISDESCENDANTNODE([/myfolder]) and
>>> CONTAINS(s.*, '%%myword%%')
>>> 
>>> XPATH:
>>> 	/jcr:root/myfolder//*[jcr:contains(., '%%myword%%')]
>>> 
>>> Thanks!
>>> Roy
>> 
>


Re: Escaping % sign in a query

Posted by Roy Teeuwen <ro...@teeuwen.be>.
Hey Thomas,

Thanks for the info!

I am using Jackrabbit Oak. (version 1.2.17). The thing is that  I would like to prefer to not find all the nodes that contain myword but not %%myword%%, seeing as myword could for example be 'site', and this would return too many results, I only want the results that really contain '%%site%%', not just 'site'

I have tried the \ escape character, unfortunately both returning the same result as without escape character

	/jcr:root/myfolder//*[jcr:contains(., '\%\%myword\%\%')] 
	SELECT * FROM [nt:base] AS s WHERE ISDESCENDANTNODE([/myfolder]) and CONTAINS(s.*, '\%\%myword\%\%')

Do you see any other option without having to use /jcr:root/myfolder//*[jcr:contains(., 'myword')] and  iterate all the results in java to check for %%myword%%?

Thanks!
Roy

> On 12 Jan 2017, at 11:52, Thomas Mueller <mu...@adobe.com> wrote:
> 
> Hi,
> 
> For jcr:contains, the escape character is '\'. Maybe the problem is that
> the fulltext index is not configured to index special characters such as %
> (it depends on the configuration; see "analyzed"). I would try this:
> 
>    /jcr:root/myfolder//*[jcr:contains(., 'myword')]
> 
> 
> There might be also a difference between Jackrabbit 2.x and Jackrabbit
> Oak. Which one (and which version) do you use?
> 
> Regards,
> Thomas
> 
> 
> 
> On 11/01/17 18:18, "Roy Teeuwen" <ro...@teeuwen.be> wrote:
> 
>> Hey all,
>> 
>> I am trying to do a query where the actual word I am looking for looks
>> like %%myword%%. I have tried the following in XPATH and JCR_SQL2, but it
>> seems that the % sign is in both query languages a wildcard, meaning i
>> will find all the nodes containing myword instead of %%myword%%. How can
>> I escape the % sign in either XPATH or JCR_SQL2?
>> 
>> JCR_SQL2:
>> 	SELECT * FROM [nt:base] AS s WHERE ISDESCENDANTNODE([/myfolder]) and
>> CONTAINS(s.*, '%%myword%%')
>> 
>> XPATH:
>> 	/jcr:root/myfolder//*[jcr:contains(., '%%myword%%')]
>> 
>> Thanks!
>> Roy
> 


Re: Escaping % sign in a query

Posted by Thomas Mueller <mu...@adobe.com>.
Hi,

For jcr:contains, the escape character is '\'. Maybe the problem is that
the fulltext index is not configured to index special characters such as %
(it depends on the configuration; see "analyzed"). I would try this:

    /jcr:root/myfolder//*[jcr:contains(., 'myword')]


There might be also a difference between Jackrabbit 2.x and Jackrabbit
Oak. Which one (and which version) do you use?

Regards,
Thomas



On 11/01/17 18:18, "Roy Teeuwen" <ro...@teeuwen.be> wrote:

>Hey all,
>
>I am trying to do a query where the actual word I am looking for looks
>like %%myword%%. I have tried the following in XPATH and JCR_SQL2, but it
>seems that the % sign is in both query languages a wildcard, meaning i
>will find all the nodes containing myword instead of %%myword%%. How can
>I escape the % sign in either XPATH or JCR_SQL2?
>
>JCR_SQL2:
>	SELECT * FROM [nt:base] AS s WHERE ISDESCENDANTNODE([/myfolder]) and
>CONTAINS(s.*, '%%myword%%')
>
>XPATH:
>	/jcr:root/myfolder//*[jcr:contains(., '%%myword%%')]
>
>Thanks!
>Roy