You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by Amir Mistric <am...@nemours.org> on 2007/06/19 02:46:37 UTC

XPath difference in queries

Hi

I am a bit new to Xpath in Jackrabbit but can someone tell me what is the difference between these 3 queries:

Q1: //*[@jcr:primaryType='mgnl:content']//*[jcr:contains(.,'term1') and jcr:contains(., 'term2')]

Q2: //*[@jcr:primaryType='mgnl:content' and jcr:contains(.,'term1') and jcr:contains(.,'term2')]

Q3: //element(*,nt:base)[@jcr:primaryType='mgnl:content' and jcr:contains(.,'term1') and jcr:contains(.,'term2')]


Basically all I want is to extract all the nodes of primary type "mgnl:content" and then to search them for the query terms which are ANDed.


Any help is appreciated

Regards
Amir

Re: XPath difference in queries

Posted by Marcel Reutegger <ma...@gmx.net>.
Amir Mistric wrote:
> Q1: //*[@jcr:primaryType='mgnl:content']//*[jcr:contains(.,'term1') and jcr:contains(., 'term2')]

returns all node that contain 'term1' and 'term2' in one of its properties and 
are a descendant of a node with primary type mgnl:content.

> Q2: //*[@jcr:primaryType='mgnl:content' and jcr:contains(.,'term1') and jcr:contains(.,'term2')]

returns all node with a primary type mgnl:content that contain 'term1' and 
'term2' in one of its properties

> Q3: //element(*,nt:base)[@jcr:primaryType='mgnl:content' and jcr:contains(.,'term1') and jcr:contains(.,'term2')]

same as Q2

> Basically all I want is to extract all the nodes of primary type "mgnl:content" and then to search them for the query terms which are ANDed.

that's:

//*[@jcr:primaryType = 'mgnl:content' and jcr:contains(., 'term1 term2')]

or if you are also interested in nodes, which are sub types of mgnl:content:

//element(*, mgnl:content)[jcr:contains(., 'term1 term2')]

regards
  marcel

Re: XPath difference in queries

Posted by Marcel Reutegger <ma...@gmx.net>.
Amir Mistric wrote:
> So If someone enters in a form field a query string "rock AND roll OR disco
> -techno" I cannot just use it in jcr:contains - I have to tokenize the string
> and use multiple jcr:contains.

I'm sorry, that was a misunderstanding.

you *can* pass your example query string as is to the jcr:contains function.

I just wanted to point out that a sole jcr:contains function is not a valid 
xpath statement.

regards
  marcel

RE: XPath difference in queries

Posted by Amir Mistric <am...@nemours.org>.
So If someone enters in a form field a query string "rock AND roll OR disco -techno" 
I cannot just use it in jcr:contains - I have to tokenize the string and use multiple jcr:contains.
SO instead of:

jcr:contains(.,'rock AND roll OR disco -techno')

I have to do:

jcr:contains(.,'rock') and jcr:contains(.,'roll') or jcr:contains(.,'disco') and not jcr:contains(.,'techno')

Is that correct?
If, so are there any utilities that would take a natural query and produce a valid xpath?


Thanks
 
Amir
 

> -----Original Message-----
> From: Marcel Reutegger [mailto:marcel.reutegger@gmx.net] 
> Sent: Wednesday, June 20, 2007 10:01 AM
> To: users@jackrabbit.apache.org
> Subject: Re: XPath difference in queries
> 
> Amir Mistric wrote:
> > Does this mean if I have a form in which user is entering 
> search query 
> > I don't have to "build" (tokenize, validate, reconstruct, etc, etc) 
> > the XPAth query... I can just pass in something like
> > 
> > jcr:contains(.,'rock AND roll OR disco -techno') and it will work?
> 
> no, that doesn't work you have to create a valid XPath statement.
> 
> > Would I have to take care of the last point (escape special 
> chars) or 
> > is that done automatically?
> 
> you have to do that manually.
> 
> regards
>   marcel
> 

Re: XPath difference in queries

Posted by Marcel Reutegger <ma...@gmx.net>.
Amir Mistric wrote:
> Does this mean if I have a form in which user is entering search query I
> don't have to "build" (tokenize, validate, reconstruct, etc, etc) the XPAth
> query... I can just pass in something like
> 
> jcr:contains(.,'rock AND roll OR disco -techno') and it will work?

no, that doesn't work you have to create a valid XPath statement.

> Would I have to take care of the last point (escape special chars) or is that
> done automatically?

you have to do that manually.

regards
  marcel

RE: XPath difference in queries

Posted by Amir Mistric <am...@nemours.org>.
Now that I am reading the specifications I see following for jcr:contains() function :

--- begin quote ---
At minimum, all implementations must support the simple search-engine syntax defined by exp in the EBNF above. This syntax is based on the syntax of search engines like Google.
The semantics of the simple search expression are as follows:
• Terms separated by whitespace are implicitly ANDed together.
• Terms may also be ORed with explicit use of the OR keyword.
• AND has higher precedence than OR.
• Terms may be excluded by prefixing with a – (minus sign) character. This means that the result set must not contain the excluded term.
• A term may be either a single word or a phrase delimited by double quotes (").
• The entire text search expression (searchexp in the EBNF, above) must be delimited by single quotes (').
• Within the searchexp literal instances of single quote (“'”), double quote (“"”) and hyphen (“-”) must be escaped with a backslash (“\”). Backslash itself must therefore also be escaped, ending up as double backslash (“\\”).
--- end quote ---

Does this mean if I have a form in which user is entering search query I don't have to "build" (tokenize, validate, reconstruct, etc, etc) the XPAth query...
I can just pass in something like

jcr:contains(.,'rock AND roll OR disco -techno') and it will work? 

Would I have to take care of the last point (escape special chars) or is that done automatically? 


Thanks
 
Amir
 

> -----Original Message-----
> From: Amir Mistric [mailto:amistric@nemours.org] 
> Sent: Monday, June 18, 2007 8:47 PM
> To: users@jackrabbit.apache.org
> Subject: XPath difference in queries
> 
> Hi
> 
> I am a bit new to Xpath in Jackrabbit but can someone tell me 
> what is the difference between these 3 queries:
> 
> Q1: 
> //*[@jcr:primaryType='mgnl:content']//*[jcr:contains(.,'term1'
) and jcr:contains(., 'term2')]
> 
> Q2: //*[@jcr:primaryType='mgnl:content' and 
> jcr:contains(.,'term1') and jcr:contains(.,'term2')]
> 
> Q3: //element(*,nt:base)[@jcr:primaryType='mgnl:content' and 
> jcr:contains(.,'term1') and jcr:contains(.,'term2')]
> 
> 
> Basically all I want is to extract all the nodes of primary 
> type "mgnl:content" and then to search them for the query 
> terms which are ANDed.
> 
> 
> Any help is appreciated
> 
> Regards
> Amir
>