cancel
Showing results for 
Search instead for 
Did you mean: 

XPath category queries + ancestor axis

dbevacqua
Champ in-the-making
Champ in-the-making
Hi

(Apologies in advance - I think this is going to be a long one…)

I'm trying to write a generic search interface that allows users to query the repo for nodes of a particular type, specifying criteria about the attributes and categories of ancestors and descendants. I've come up against a few issues and I wonder if you could point me in the right direction. I'm new to XPath so this may all be perfectly obvious…

A typical kind of query is:


"give me all nodes of type A that have a descendant of type B in category x and an ancestor of type C in category y"

Ideally I would do this in the Lucene language, but I can only use TYPE: to specify the type of node I want returned (i.e. there seems no way to make the required statements about types B and C). element() and subtypeOf() do not appear to be supported in the Lucene search. So I think I need to use XPath.

So, question 1: how do I do category queries using XPath?

These are simple enough to do in the Lucene language, and very quick. I can't seem to reproduce such queries in XPath though. I've tried things like:


//*[@myNamespace:myCategory='workspace://SpacesStore/414c42b3-2226-11db-86ce-1f31bf652f1c']

and


//*[@myNamespace:myCategory='414c42b3-2226-11db-86ce-1f31bf652f1c']

both with and without single quotes.

where myCategory is a single-valued property of type d:category and 414c42b3-2226-11db-86ce-1f31bf652f1c is the guid of a category node.

What am I doing wrong? do I need to deref() the property? do I need to use a different delimiter, or some function?


Once I've solved that, there's the slightly knottier problem of specifying criteria about ancestors. So:

Question 2: Would it be feasible for me to implement the ancestor:: axis in the XPath search? Any pointers? Jaxen seems to support it. Was it not implemented for performance reasons or something more fundamental?


If I can't do these kinds of queries as XPaths, I guess I could combine the results of a number of Lucene searches. So for the original query, I would break it down into:


all ancestors of                  <– just analyse the nodes returned by Lucene?
   (all nodes of type B in category x)  <– Lucene query
with type B
   
intersection

all descendants of                   
   (all nodes of type C in category y) <– Lucene query
with type A    


Bit of a kludge though.

Hope this makes some kind of sense and (even more) that you can help!

Many thanks in advance.

Dominic
2 REPLIES 2

dbevacqua
Champ in-the-making
Champ in-the-making
sorry just noticed a typo in the last bit of the above. Should read


all ancestors of                  <– just analyse the nodes returned by Lucene?
   (all nodes of type B in category x)  <– Lucene query
with type A
  
intersection

all descendants of                  
   (all nodes of type C in category y) <– Lucene query
with type A 

andy
Champ on-the-rise
Champ on-the-rise
Hi

You are right, you can not use lucene for this.
We do not do joins or support predicates at the moment.

You should be able to use the ancestor:: axis in XPATH queries - using the default Jaxen implementation.

The XPATH category stuff should have a property that contains the nodeRef of the linked category. Your example should work. There may be an issue with multivalued properties in XPATH searches. I will have a look at this when time allows. Also remember that categories are in a tree so you would have to check for membership of a category and all its sub categories. This si where the lucene stuff will win.

Your suggestion is probably the best way at the moment.

Regards

Andy