jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ChadDavis <chadmichaelda...@gmail.com>
Subject Jackrabbit 2.0.0 Query Issues
Date Tue, 23 Feb 2010 23:14:25 GMT
I'm unable to correctly execute the following search logic.  I have a
folder node with documents and folders in it.  I would like to search
the folder's contents, but I would NOT like the search to enter the
child folders.  Assume the following folder structure:


With this in mind, I'm trying to build a search query that hits
everything in the target folder, but not in the target folders' child
folders.  I'm using the JCR-JQOM API to build my query.   I'll
describe my query building logic, then show my code.

1) Build a source that is a selector of all nt:base nodes in the repo
2) build a fullTextSearch constraint with my query string
3) build a DescendantNode constraint that limits my hits to descedants
of my target folder
4) build a AND constraint of these first two

Note: this works just fine so far

5) build a DescendentNode constraint for the first of the children
folders of the target folder
6) build a NOT constraint from the descendant constraint in step 5
7) build an AND constraint of this NOT and the AND from step 4

This also works fine.  Here's  the problem area.

8) build a DescendantNode constraint for the second of the children
folders of the target folder
9) build a NOT constraint from the desc. constraint from step 8
10) build an AND constraint of this NOT and the AND from step 7

This doesn't work.  Interestingly, it seems like you just can't add
AND's to the tree; the second child folder NOT'd and AND'd to the
original query, doesn't work.  Maybe I'm misunderstanding how to
achieve this.  Here's my code:

//Select all nt:base
Source allDocsSelector = qomFactory.selector("nt:base", "allDocs");
		
//Build the fullTextSearchConstraint AND'd with the target folder
Constraint fullTextSearchConstraint =
buildFullTextSearchConstraint(session, queryString, qomFactory);
Constraint targetFolderConstraint = buildRootFolderConstraint(session,
targetFolder, qomFactory);
And textQueryANDTargetFolderConstraint = qomFactory.and(
fullTextSearchConstraint, targetFolderConstraint );

//Build NOT descendant constraints to keep the search out of child folders
		
//NOT descendant of "folderOne", one of the child folders of the target folder
String path = "/BIP/1/1/folderOne/";
Constraint descendantOfFolderOne = qomFactory.descendantNode("allDocs", path );
Not notDescendantOfFolderOne = qomFactory.not(descendantOfFolderOne);
And targetedFullTextANDNotFolderOne =
qomFactory.and(textQueryANDTargetFolderConstraint,
notDescendantOfFolderOne );
		

String apath = "/BIP/1/1/folderTwo/";
Constraint descendantOfFolderTwo = qomFactory.descendantNode("allDocs", apath );
Not notDescendantOfFolderTwo = qomFactory.not(descendantOfFolderTwo);
And targetedFullTextANDNotFolderOneANDNotFolderTwo =
qomFactory.and(targetedFullTextANDNotFolderOne,
notDescendantOfFolderTwo );

QueryObjectModel queryObjectModel = qomFactory.createQuery(
allDocsSelector, targetedFullTextANDNotFolderOneANDNotFolderTwo, null,
null);
QueryResult results = queryObjectModel.execute();



Any ideas?

Mime
View raw message