I'm also using XPath for several reasons (at the time I started
working with search, using XPath would solve issues I had with result
sorting and case sensitivity (or lack thereof).
A few examples beyond what Harold provided :
A jcr query using XPath can look like :
- Searching for a paragraph (item type : content Node in magnolia)
containing the word "test"
//[EMAIL PROTECTED]:primaryType='mgnl:contentNode'][jcr:contains(.,'test')]
- You can add ordering simply by appending
order by @date descending
If your paragraph has a node called date that is sortable.
- A query to find any paragraph that has a "date" data node would
look like
//[EMAIL PROTECTED]
-Instead of searching through the whole tree (//*), you could specify
a path to start from (/step1/step2/*)
Etc... XPath is a powerfull language, simple enough for usual things.
The requests I just typed can be used on the dms or the website,
without modifications. You don't have to worry about querying lucene
separately from the rest.
To execute a query simple use the queryManager, for example like this :
Query q = MgnlContext.getQueryManager
(ContentRepository.WEBSITE).createQuery(queryString, "xpath");
QueryResult result = q.execute();
And then, you could, for example,
Iterator matchingItemsIterator = result.getContent().iterator();
In the getQueryManager.createquery part, instead of using
ContentRepository.Website, you can use "dms" or "website" or any
repository you might have (users, roles, config...). You can of
course switch to sql.
The code has been typed without checking on my part, there might be
typos, but hopefully, it should give you a good start.
Hope this helps,
Guillaume.
Le 20 mars 07 à 10:07, Harold CAPITAINE a écrit :
Hi Dieter,
I usually use queries in xpath to search on a tree, which seems
more appropriate.
To search on a magnolia property of a node you can do like this:
//path/to/the/node/[EMAIL PROTECTED]:TheProperty='TheValue']
Just for a node:
//path/to/the/node
To know the type of node that you search, use the jcr query tool in
admininterface.
HTH
CAPITAINE Harold
dieter a écrit :
Hi, I would like to implement an advanced search in magnolia and i
assume
that would involve querying using the underlying jackrabbit or
lucene api.
Now obviously the data is not sored in the same manner as in
magnolia, and I
have seen from the dev-search example how to query using
jackrabbit " SELECT
* FROM nt:base where jcr:path like '/%' and title like '%' " .
This is great
for title, but how do i go about searching on other custom
attributes in
lucene or in jackrabbit?
Thanks
----------------------------------------------------------------
for list details see
http://www.magnolia.info/en/developer.html
----------------------------------------------------------------
----------------------------------------------------------------
for list details see
http://www.magnolia.info/en/developer.html
----------------------------------------------------------------