You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by mr...@apache.org on 2004/10/04 12:23:07 UTC
svn commit: rev 51875 - in incubator/jackrabbit/trunk/src: java/org/apache/jackrabbit/core java/org/apache/jackrabbit/core/observation java/org/apache/jackrabbit/core/search java/org/apache/jackrabbit/core/search/lucene test/org/apache/jackrabbit/test test/org/apache/jackrabbit/test/observation test/org/apache/jackrabbit/test/search
Author: mreutegg
Date: Mon Oct 4 03:23:03 2004
New Revision: 51875
Removed:
incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/observation/EventDispatcher.java
Modified:
incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/SearchManager.java
incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/PathQueryNode.java
incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/FieldNames.java
incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/LuceneQueryBuilder.java
incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/NodeIndexer.java
incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/PathFilter.java
incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/PathQuery.java
incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/AbstractTest.java
incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/observation/AbstractObservationTest.java
incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/search/FulltextQueryTest.java
incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/search/SelectClauseTest.java
incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/search/SimpleQueryTest.java
Log:
- Removed interface EventDispatcher. not used anymore.
- Adapted implementation of path handling in search to use regular term queries instead of a filter -> scales better.
- Changed notion of TEST_ROOT in test classes to also include the root slash.
Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/SearchManager.java
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/SearchManager.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/SearchManager.java Mon Oct 4 03:23:03 2004
@@ -67,21 +67,23 @@
nsMappings = new NamespaceMappings(new File(indexPath, "ns_mappings.properties"));
}
- public void addNode(NodeState node, String path) throws IOException {
+ public void addNode(NodeState node, Path path) throws IOException {
// FIXME rather throw RepositoryException?
log.debug("add node to index: " + path);
Document doc = NodeIndexer.createDocument(node, stateProvider, path, nsMappings);
index.addDocument(doc);
}
- public void updateNode(NodeState node, String path) throws IOException {
+ public void updateNode(NodeState node, Path path) throws IOException {
log.debug("update index for node: " + path);
deleteNode(path, node.getUUID());
addNode(node, path);
}
- public void deleteNode(String path, String uuid) throws IOException {
- log.debug("remove node from index: " + path);
+ public void deleteNode(Path path, String uuid) throws IOException {
+ if (log.isDebugEnabled()) {
+ log.debug("remove node from index: " + path.toString());
+ }
index.removeDocument(new Term(FieldNames.UUID, uuid));
}
@@ -157,15 +159,15 @@
path = getIndexlessPath(path);
ItemId id = new NodeId(e.getChildUUID());
- addNode((NodeState) stateProvider.getItemState(id),
- path.toJCRPath(nsMappings));
+ addNode((NodeState) stateProvider.getItemState(id), path);
+
} else if (type == EventType.CHILD_NODE_REMOVED) {
Path path = Path.create(e.getNodePath() + ((e.getNodePath().length() > 1) ? "/" : "") + e.getChildName(),
session.getNamespaceResolver(),
true);
- deleteNode(path.toJCRPath(nsMappings), e.getChildUUID());
+ deleteNode(path, e.getChildUUID());
} else if (type == EventType.PROPERTY_ADDED
|| type == EventType.PROPERTY_CHANGED
@@ -178,8 +180,6 @@
}
} catch (MalformedPathException e) {
log.error("error indexing node.", e);
- } catch (NoPrefixDeclaredException e) {
- log.error("error indexing node.", e);
} catch (ItemStateException e) {
log.error("error indexing node.", e);
} catch (RepositoryException e) {
@@ -194,10 +194,7 @@
Path path = (Path) it.next();
ItemId id = hmgr.resolvePath(path);
path = getIndexlessPath(path);
- updateNode((NodeState) stateProvider.getItemState(id),
- path.toJCRPath(nsMappings));
- } catch (NoPrefixDeclaredException e) {
- log.error("error indexing node.", e);
+ updateNode((NodeState) stateProvider.getItemState(id), path);
} catch (ItemStateException e) {
log.error("error indexing node.", e);
} catch (RepositoryException e) {
@@ -211,9 +208,9 @@
//-----------------------< internal >---------------------------------------
/**
- * Returns a <code>Path</code>, which contains the same sequence of
- * path elements as <code>p</code>, but has cut off any existing indexes
- * on the path elements.
+ * Returns a <code>Path</code>, which contains the same sequence of path
+ * elements as <code>p</code>, but has cut off any existing indexes on the
+ * path elements.
*
* @param p the source path, possibly containing indexed path elements.
* @return a <code>Path</code> without indexed path elements.
Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/PathQueryNode.java
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/PathQueryNode.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/PathQueryNode.java Mon Oct 4 03:23:03 2004
@@ -31,9 +31,9 @@
public static final int TYPE_CHILDREN = 2;
/**
- * Match descendant nodes of path
+ * Match descendant nodes or self of path
*/
- public static final int TYPE_DESCENDANT = 3;
+ public static final int TYPE_DESCENDANT_SELF = 3;
/**
* The base path
@@ -60,12 +60,12 @@
*
* @param parent this parent node of this query node.
* @param path the base path.
- * @param type one of {@link #TYPE_CHILDREN}, {@link #TYPE_DESCENDANT},
+ * @param type one of {@link #TYPE_CHILDREN}, {@link #TYPE_DESCENDANT_SELF},
* {@link #TYPE_EXACT}
*/
public PathQueryNode(QueryNode parent, String path, int type) {
super(parent);
- if (type < TYPE_EXACT || type > TYPE_DESCENDANT) {
+ if (type < TYPE_EXACT || type > TYPE_DESCENDANT_SELF) {
throw new IllegalArgumentException(String.valueOf(type));
}
this.path = path;
@@ -121,8 +121,8 @@
/**
* Returns the type of this <code>PathQueryNode</code>.
*
- * @return one of {@link #TYPE_CHILDREN}, {@link #TYPE_DESCENDANT}, {@link
- * #TYPE_EXACT}
+ * @return one of {@link #TYPE_CHILDREN}, {@link #TYPE_DESCENDANT_SELF},
+ * {@link #TYPE_EXACT}
*/
public int getType() {
return type;
@@ -130,8 +130,8 @@
/**
* Returns <code>true</code> if the path contains an index. E.g. a location
- * step in XPath has a position predicate. If the path does not contain
- * any indexes <code>false</code> is returned.
+ * step in XPath has a position predicate. If the path does not contain any
+ * indexes <code>false</code> is returned.
*
* @return <code>true</code> if the path contains an indexed location step.
*/
@@ -150,7 +150,7 @@
jcrql.append(path);
if (type == TYPE_CHILDREN) {
jcrql.append("/*");
- } else if (type == TYPE_DESCENDANT) {
+ } else if (type == TYPE_DESCENDANT_SELF) {
jcrql.append("//");
}
return jcrql.toString();
Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/FieldNames.java
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/FieldNames.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/FieldNames.java Mon Oct 4 03:23:03 2004
@@ -16,8 +16,8 @@
package org.apache.jackrabbit.core.search.lucene;
/**
- * Defines field names that are used internally to store UUID, Path, etc
- * in the search index.
+ * Defines field names that are used internally to store UUID, Path, etc in the
+ * search index.
*/
public class FieldNames {
@@ -26,4 +26,10 @@
public static final String PATH = "_:Path";
public static final String FULLTEXT = "_:FULLTEXT";
+
+ public static final String ANCESTORS = "_:ANCESTORS";
+
+ public static final String LABEL = "_:LABEL";
+
+ public static final String LEVEL = "_:LEVEL";
}
Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/LuceneQueryBuilder.java
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/LuceneQueryBuilder.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/LuceneQueryBuilder.java Mon Oct 4 03:23:03 2004
@@ -17,6 +17,7 @@
import org.apache.jackrabbit.core.MalformedPathException;
import org.apache.jackrabbit.core.SessionImpl;
+import org.apache.jackrabbit.core.Path;
import org.apache.jackrabbit.core.nodetype.NodeTypeRegistry;
import org.apache.jackrabbit.core.search.*;
import org.apache.log4j.Logger;
@@ -224,15 +225,23 @@
}
public Object visit(PathQueryNode node, Object data) {
- String path = node.getPath();
+ PathQuery pathQuery = null;
try {
- path = nsMappings.translatePropertyName(node.getPath(),
- session.getNamespaceResolver());
+ // FIXME what about relative path?
+ Path p = Path.create(node.getPath(),
+ session.getNamespaceResolver(), false);
+ pathQuery = new PathQuery(p, nsMappings, node.getType());
} catch (MalformedPathException e) {
exceptions.add(e);
}
- PathFilter filter = new PathFilter(path, node.getType());
- return new PathFilterQuery((Query) data, new PackageFilter(filter));
+ if (pathQuery != null && pathQuery.getClauses().length > 0) {
+ BooleanQuery combined = new BooleanQuery();
+ combined.add(pathQuery, true, false);
+ combined.add((Query) data, true, false);
+ return combined;
+ } else {
+ return data;
+ }
}
public Object visit(RelationQueryNode node, Object data) {
Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/NodeIndexer.java
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/NodeIndexer.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/NodeIndexer.java Mon Oct 4 03:23:03 2004
@@ -15,34 +15,41 @@
*/
package org.apache.jackrabbit.core.search.lucene;
-import org.apache.jackrabbit.core.InternalValue;
-import org.apache.jackrabbit.core.Path;
-import org.apache.jackrabbit.core.PropertyId;
-import org.apache.jackrabbit.core.QName;
import org.apache.jackrabbit.core.search.NamespaceMappings;
-import org.apache.jackrabbit.core.state.*;
import org.apache.jackrabbit.core.util.uuid.UUID;
+import org.apache.jackrabbit.core.state.NodeState;
+import org.apache.jackrabbit.core.state.ItemStateProvider;
+import org.apache.jackrabbit.core.state.PropertyState;
+import org.apache.jackrabbit.core.state.NoSuchItemStateException;
+import org.apache.jackrabbit.core.state.ItemStateException;
+import org.apache.jackrabbit.core.PropertyId;
+import org.apache.jackrabbit.core.InternalValue;
+import org.apache.jackrabbit.core.QName;
+import org.apache.jackrabbit.core.Path;
+import org.apache.jackrabbit.core.NoPrefixDeclaredException;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
-import javax.jcr.NamespaceException;
import javax.jcr.PropertyType;
-import java.util.Calendar;
-import java.util.Iterator;
+import javax.jcr.NamespaceException;
+import javax.jcr.PathNotFoundException;
import java.util.List;
+import java.util.Iterator;
+import java.util.Calendar;
/**
+ *
*/
public class NodeIndexer {
private final NodeState node;
private final ItemStateProvider stateProvider;
- private final String path;
+ private final Path path;
private final NamespaceMappings mappings;
private NodeIndexer(NodeState node,
ItemStateProvider stateMgr,
- String path,
+ Path path,
NamespaceMappings mappings) {
this.node = node;
this.stateProvider = stateMgr;
@@ -52,7 +59,7 @@
public static Document createDocument(NodeState node,
ItemStateProvider stateMgr,
- String path,
+ Path path,
NamespaceMappings mappings) {
NodeIndexer indexer = new NodeIndexer(node, stateMgr, path, mappings);
return indexer.createDoc();
@@ -64,8 +71,33 @@
// special fields
// UUID
doc.add(new Field(FieldNames.UUID, node.getUUID(), true, true, false));
- // Path
- doc.add(new Field(FieldNames.PATH, path, true, true, false));
+ try {
+ // Path
+ doc.add(new Field(FieldNames.PATH, path.toJCRPath(mappings), true, true, false));
+ Path p = null;
+ if (path.denotesRoot()) {
+ p = path;
+ } else {
+ p = path.getAncestor(1);
+ }
+ // Ancestors
+ while (!p.denotesRoot()) {
+ doc.add(new Field(FieldNames.ANCESTORS, p.toJCRPath(mappings),
+ false, true, false));
+ p = p.getAncestor(1);
+ }
+ // Label
+ doc.add(new Field(FieldNames.LABEL, path.getNameElement().toJCRName(mappings),
+ false, true, false));
+ // hierarchy level
+ doc.add(new Field(FieldNames.LEVEL, String.valueOf(path.getAncestorCount()),
+ false, true, false));
+ } catch (NoPrefixDeclaredException e) {
+ // will never happen, because this.mappings will dynamically add
+ // unknown uri<->prefix mappings
+ } catch (PathNotFoundException e) {
+ // will never happen because we check for root
+ }
List props = node.getPropertyEntries();
for (Iterator it = props.iterator(); it.hasNext();) {
Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/PathFilter.java
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/PathFilter.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/PathFilter.java Mon Oct 4 03:23:03 2004
@@ -18,6 +18,7 @@
import org.apache.jackrabbit.core.search.PathQueryNode;
/**
+ *
*/
public class PathFilter {
@@ -30,7 +31,7 @@
switch (type) {
case PathQueryNode.TYPE_CHILDREN:
- case PathQueryNode.TYPE_DESCENDANT:
+ case PathQueryNode.TYPE_DESCENDANT_SELF:
if (path.length() > 1) {
this.basePath = path + "/";
} else {
@@ -53,7 +54,7 @@
switch (type) {
case PathQueryNode.TYPE_CHILDREN:
return (path.indexOf('/', basePath.length()) == -1);
- case PathQueryNode.TYPE_DESCENDANT:
+ case PathQueryNode.TYPE_DESCENDANT_SELF:
return path.length() > basePath.length();
case PathQueryNode.TYPE_EXACT:
return path.length() == basePath.length();
Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/PathQuery.java
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/PathQuery.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/PathQuery.java Mon Oct 4 03:23:03 2004
@@ -15,170 +15,145 @@
*/
package org.apache.jackrabbit.core.search.lucene;
+import org.apache.lucene.search.BooleanQuery;
+import org.apache.lucene.search.TermQuery;
+import org.apache.lucene.index.Term;
import org.apache.jackrabbit.core.search.PathQueryNode;
-import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.index.TermDocs;
-import org.apache.lucene.search.*;
-
-import java.io.IOException;
+import org.apache.jackrabbit.core.Path;
+import org.apache.jackrabbit.core.NamespaceResolver;
+import org.apache.jackrabbit.core.NoPrefixDeclaredException;
/**
- *
+ * Implements a query for a path with a match type.
*/
-class PathQuery extends Query {
+class PathQuery extends BooleanQuery {
/**
* The path to query
*/
- private final String path;
+ private final Path path;
+ /**
+ * The path type.
+ * The path <code>type</code> must be one of:
+ * <ul>
+ * <li>{@link org.apache.jackrabbit.core.search.PathQueryNode#TYPE_EXACT}</li>
+ * <li>{@link org.apache.jackrabbit.core.search.PathQueryNode#TYPE_CHILDREN}</li>
+ * <li>{@link org.apache.jackrabbit.core.search.PathQueryNode#TYPE_DESCENDANT_SELF}</li>
+ * </ul>
+ */
private final int type;
private final int index;
+ private final NamespaceResolver nsMappings;
+
/**
* Creates a <code>PathQuery</code> for a <code>path</code> and a path
* <code>type</code>. The query does not care about a specific index.
* <p/>
- * The path <code>type</code> must be one of:
- * <ul>
- * <li>{@link org.apache.jackrabbit.core.search.PathQueryNode#TYPE_EXACT}</li>
+ * The path <code>type</code> must be one of: <ul> <li>{@link
+ * org.apache.jackrabbit.core.search.PathQueryNode#TYPE_EXACT}</li>
* <li>{@link org.apache.jackrabbit.core.search.PathQueryNode#TYPE_CHILDREN}</li>
- * <li>{@link org.apache.jackrabbit.core.search.PathQueryNode#TYPE_DESCENDANT}</li>
+ * <li>{@link org.apache.jackrabbit.core.search.PathQueryNode#TYPE_DESCENDANT_SELF}</li>
* </ul>
*
- * @param path the base path
- * @param type the path type.
+ * @param path the base path
+ * @param resolver namespace resolver to resolve <code>path</code>.
+ * @param type the path type.
* @throws NullPointerException if path is null.
* @throws IllegalArgumentException if type is not one of the defined types
* in {@link org.apache.jackrabbit.core.search.PathQueryNode}.
*/
- PathQuery(String path, int type) {
+ PathQuery(Path path, NamespaceResolver resolver, int type) {
if (path == null) {
throw new NullPointerException("path");
}
- if (type < PathQueryNode.TYPE_EXACT || type > PathQueryNode.TYPE_DESCENDANT) {
+ if (type < PathQueryNode.TYPE_EXACT || type > PathQueryNode.TYPE_DESCENDANT_SELF) {
throw new IllegalArgumentException("type: " + type);
}
this.path = path;
+ this.nsMappings = resolver;
this.type = type;
index = -1;
+ populateQuery();
}
/**
* Creates a <code>PathQuery</code> for a <code>path</code>, a path
* <code>type</code> and a position index for the last location step.
* <p/>
- * The path <code>type</code> must be one of:
- * <ul>
- * <li>{@link org.apache.jackrabbit.core.search.PathQueryNode#TYPE_EXACT}</li>
+ * The path <code>type</code> must be one of: <ul> <li>{@link
+ * org.apache.jackrabbit.core.search.PathQueryNode#TYPE_EXACT}</li>
* <li>{@link org.apache.jackrabbit.core.search.PathQueryNode#TYPE_CHILDREN}</li>
- * <li>{@link org.apache.jackrabbit.core.search.PathQueryNode#TYPE_DESCENDANT}</li>
+ * <li>{@link org.apache.jackrabbit.core.search.PathQueryNode#TYPE_DESCENDANT_SELF}</li>
* </ul>
*
- * @param path the base path
- * @param type the path type.
- * @param index position index of the last location step.
+ * @param path the base path
+ * @param type the path type.
+ * @param index position index of the last location step.
+ * @param resolver namespace resolver to resolve <code>path</code>.
* @throws NullPointerException if path is null.
* @throws IllegalArgumentException if type is not one of the defined types
- * in {@link org.apache.jackrabbit.core.search.PathQueryNode}. Or if
- * <code>index</code> < 1.
+ * in {@link org.apache.jackrabbit.core.search.PathQueryNode}.
+ * Or if <code>index</code> < 1.
*/
- PathQuery(String path, int type, int index) {
+ PathQuery(Path path, NamespaceResolver resolver, int type, int index) {
if (path == null) {
throw new NullPointerException("path");
}
- if (type < PathQueryNode.TYPE_EXACT || type > PathQueryNode.TYPE_DESCENDANT) {
+ if (type < PathQueryNode.TYPE_EXACT || type > PathQueryNode.TYPE_DESCENDANT_SELF) {
throw new IllegalArgumentException("type: " + type);
}
if (index < 1) {
throw new IllegalArgumentException("index: " + index);
}
this.path = path;
+ this.nsMappings = resolver;
this.type = type;
this.index = index;
+ populateQuery();
}
/**
- * Creates a new
- *
- * @param searcher
- * @return
+ * Populates this <code>BooleanQuery</code> with clauses according
+ * to the path and match type.
*/
- protected Weight createWeight(Searcher searcher) {
- return new PathQueryWeight(searcher);
- }
-
- public String toString(String field) {
- return "";
- }
-
- private class PathQueryWeight implements Weight {
-
- private final Searcher searcher;
- private float value;
- private float idf;
- private float queryNorm;
- private float queryWeight;
-
-
- public PathQueryWeight(Searcher searcher) {
- this.searcher = searcher;
- }
-
- public Query getQuery() {
- return PathQuery.this;
- }
-
- public float getValue() {
- return value;
- }
-
- public float sumOfSquaredWeights() throws IOException {
- idf = searcher.getSimilarity().idf(searcher.maxDoc(), searcher.maxDoc()); // compute idf
- queryWeight = idf * getBoost(); // compute query weight
- return queryWeight * queryWeight; // square it
- }
-
- public void normalize(float norm) {
- this.queryNorm = norm;
- queryWeight *= queryNorm; // normalize query weight
- value = queryWeight * idf; // idf for document
- }
-
- public Scorer scorer(IndexReader reader) throws IOException {
- return new PathQueryScorer(this, reader, searcher.getSimilarity());
- }
-
- public Explanation explain(IndexReader reader, int doc) throws IOException {
- throw new UnsupportedOperationException();
- }
- }
-
- private class PathQueryScorer extends Scorer {
-
- private final Weight weight;
-
- private final IndexReader reader;
-
- private final float score;
-
- protected PathQueryScorer(Weight weight,
- IndexReader reader,
- Similarity similarity) {
- super(similarity);
- this.weight = weight;
- this.reader = reader;
- score = similarity.tf(1) * weight.getValue();
- }
-
- public void score(HitCollector hc, int maxDoc) throws IOException {
- TermDocs docs = reader.termDocs();
- //hc.collect();
- }
-
- public Explanation explain(int doc) throws IOException {
- throw new UnsupportedOperationException();
+ private void populateQuery() {
+ try {
+ if (type == PathQueryNode.TYPE_EXACT) {
+ Term t = new Term(FieldNames.PATH, path.toJCRPath(nsMappings));
+ add(new TermQuery(t), true, false);
+ } else if (type == PathQueryNode.TYPE_CHILDREN) {
+ if (path.denotesRoot()) {
+ // get all nodes on level 1
+ add(new TermQuery(new Term(FieldNames.LEVEL, String.valueOf(1))),
+ true, false);
+ } else {
+ Term t = new Term(FieldNames.ANCESTORS,
+ path.toJCRPath(nsMappings));
+ add(new TermQuery(t), true, false);
+ int level = path.getAncestorCount() + 1;
+ add(new TermQuery(new Term(FieldNames.LEVEL, String.valueOf(level))),
+ true, false);
+ }
+ } else {
+ if (path.denotesRoot()) {
+ // no restrictions
+ } else {
+ String jcrPath = path.toJCRPath(nsMappings);
+ // descendant or self
+ Term t = new Term(FieldNames.PATH, jcrPath);
+ // self
+ add(new TermQuery(t), false, false);
+ // or nodes with ancestors = self
+ t = new Term(FieldNames.ANCESTORS, jcrPath);
+ add(new TermQuery(t), false, false);
+ }
+ }
+ } catch (NoPrefixDeclaredException e) {
+ // will never happen, this.nsMappings dynamically adds unknown
+ // uri->prefix mappings
}
}
}
Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/AbstractTest.java
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/AbstractTest.java (original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/AbstractTest.java Mon Oct 4 03:23:03 2004
@@ -22,7 +22,9 @@
*/
public abstract class AbstractTest extends JUnitTest {
- protected static final String TEST_ROOT = "testroot";
+ protected static final String TEST_PATH = "testroot";
+
+ protected static final String TEST_ROOT = "/" + TEST_PATH;
protected static final String JCR_PRIMARY_TYPE = "jcr:primaryType";
@@ -45,12 +47,12 @@
protected void setUp() throws Exception {
superuser = helper.getSuperuserSession();
Node root = superuser.getRootNode();
- if (root.hasNode(TEST_ROOT)) {
+ if (root.hasNode(TEST_PATH)) {
// remove test root
- root.remove(TEST_ROOT);
+ root.remove(TEST_PATH);
root.save();
}
- testRoot = root.addNode(TEST_ROOT, NT_UNSTRUCTURED);
+ testRoot = root.addNode(TEST_PATH, NT_UNSTRUCTURED);
root.save();
}
@@ -59,8 +61,8 @@
// do a 'rollback'
superuser.refresh(false);
Node root = superuser.getRootNode();
- if (root.hasNode(TEST_ROOT)) {
- root.remove(TEST_ROOT);
+ if (root.hasNode(TEST_PATH)) {
+ root.remove(TEST_PATH);
root.save();
}
superuser.logout();
Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/observation/AbstractObservationTest.java
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/observation/AbstractObservationTest.java (original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/observation/AbstractObservationTest.java Mon Oct 4 03:23:03 2004
@@ -192,7 +192,7 @@
paths.add(path);
}
for (int i = 0; i < relPaths.length; i++) {
- String expected = "/" + TEST_ROOT + "/" + relPaths[i];
+ String expected = TEST_ROOT + "/" + relPaths[i];
assertTrue("Path " + expected + " not found in events.",
paths.contains(expected));
}
Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/search/FulltextQueryTest.java
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/search/FulltextQueryTest.java (original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/search/FulltextQueryTest.java Mon Oct 4 03:23:03 2004
@@ -30,7 +30,7 @@
testRoot.save();
- String jcrql = "SELECT * FROM * LOCATION /" + TEST_ROOT + "// TEXTSEARCH \"fox\"";
+ String jcrql = "SELECT * FROM * LOCATION " + TEST_ROOT + "// TEXTSEARCH \"fox\"";
Query q = superuser.getWorkspace().getQueryManager().createQuery(jcrql, Query.JCRQL);
QueryResult result = q.execute();
checkResult(result, 1);
@@ -47,7 +47,7 @@
testRoot.save();
- String jcrql = "SELECT * FROM * LOCATION /" + TEST_ROOT + "// TEXTSEARCH \"fox test\"";
+ String jcrql = "SELECT * FROM * LOCATION " + TEST_ROOT + "// TEXTSEARCH \"fox test\"";
Query q = superuser.getWorkspace().getQueryManager().createQuery(jcrql, Query.JCRQL);
QueryResult result = q.execute();
checkResult(result, 1);
@@ -64,7 +64,7 @@
testRoot.save();
- String jcrql = "SELECT * FROM * LOCATION /" + TEST_ROOT + "// TEXTSEARCH \"text 'fox jumps'\"";
+ String jcrql = "SELECT * FROM * LOCATION " + TEST_ROOT + "// TEXTSEARCH \"text 'fox jumps'\"";
Query q = superuser.getWorkspace().getQueryManager().createQuery(jcrql, Query.JCRQL);
QueryResult result = q.execute();
checkResult(result, 1);
@@ -81,7 +81,7 @@
superuser.getRootNode().save();
- String jcrql = "SELECT * FROM * LOCATION /" + TEST_ROOT + "// TEXTSEARCH \"text 'fox jumps' -other\"";
+ String jcrql = "SELECT * FROM * LOCATION " + TEST_ROOT + "// TEXTSEARCH \"text 'fox jumps' -other\"";
Query q = superuser.getWorkspace().getQueryManager().createQuery(jcrql, Query.JCRQL);
QueryResult result = q.execute();
checkResult(result, 1);
@@ -98,7 +98,7 @@
testRoot.save();
- String jcrql = "SELECT * FROM * LOCATION /" + TEST_ROOT + "// TEXTSEARCH \"'fox jumps' test OR other\"";
+ String jcrql = "SELECT * FROM * LOCATION " + TEST_ROOT + "// TEXTSEARCH \"'fox jumps' test OR other\"";
Query q = superuser.getWorkspace().getQueryManager().createQuery(jcrql, Query.JCRQL);
QueryResult result = q.execute();
checkResult(result, 2);
@@ -115,7 +115,7 @@
testRoot.save();
- String jcrql = "SELECT * FROM * LOCATION /" + TEST_ROOT + "// TEXTSEARCH \"'fox juMps' Test OR otheR\"";
+ String jcrql = "SELECT * FROM * LOCATION " + TEST_ROOT + "// TEXTSEARCH \"'fox juMps' Test OR otheR\"";
Query q = superuser.getWorkspace().getQueryManager().createQuery(jcrql, Query.JCRQL);
QueryResult result = q.execute();
checkResult(result, 2);
Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/search/SelectClauseTest.java
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/search/SelectClauseTest.java (original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/search/SelectClauseTest.java Mon Oct 4 03:23:03 2004
@@ -35,12 +35,12 @@
testRoot.save();
- String jcrql = "SELECT myvalue FROM * LOCATION /" + TEST_ROOT + "//";
+ String jcrql = "SELECT myvalue FROM * LOCATION " + TEST_ROOT + "//";
Query q = superuser.getWorkspace().getQueryManager().createQuery(jcrql, Query.JCRQL);
QueryResult result = q.execute();
checkResult(result, 2);
- jcrql = "SELECT myvalue FROM * LOCATION /" + TEST_ROOT + "// WHERE yourvalue = \"foo\"";
+ jcrql = "SELECT myvalue FROM * LOCATION " + TEST_ROOT + "// WHERE yourvalue = \"foo\"";
q = superuser.getWorkspace().getQueryManager().createQuery(jcrql, Query.JCRQL);
result = q.execute();
checkResult(result, 0);
@@ -62,12 +62,12 @@
testRoot.save();
- String jcrql = "SELECT myvalue FROM * LOCATION /" + TEST_ROOT + "//";
+ String jcrql = "SELECT myvalue FROM * LOCATION " + TEST_ROOT + "//";
Query q = superuser.getWorkspace().getQueryManager().createQuery(jcrql, Query.JCRQL);
QueryResult result = q.execute();
checkResult(result, 2, 2);
- jcrql = "SELECT myvalue FROM * LOCATION /" + TEST_ROOT + "// WHERE yourvalue = \"foo\"";
+ jcrql = "SELECT myvalue FROM * LOCATION " + TEST_ROOT + "// WHERE yourvalue = \"foo\"";
q = superuser.getWorkspace().getQueryManager().createQuery(jcrql, Query.JCRQL);
result = q.execute();
checkResult(result, 0, 0);
@@ -77,7 +77,7 @@
result = q.execute();
checkResult(result, 2, 2);
- jcrql = "SELECT * FROM * LOCATION /" + TEST_ROOT + "// WHERE myvalue LIKE \"*\"";
+ jcrql = "SELECT * FROM * LOCATION " + TEST_ROOT + "// WHERE myvalue LIKE \"*\"";
q = superuser.getWorkspace().getQueryManager().createQuery(jcrql, Query.JCRQL);
result = q.execute();
checkResult(result, 2, 4);
@@ -93,7 +93,7 @@
testRoot.save();
- String jcrql = "SELECT myvalue FROM * LOCATION /" + TEST_ROOT + "/node";
+ String jcrql = "SELECT myvalue FROM * LOCATION " + TEST_ROOT + "/node";
Query q = superuser.getWorkspace().getQueryManager().createQuery(jcrql, Query.JCRQL);
QueryResult result = q.execute();
checkResult(result, 2, 2);
Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/search/SimpleQueryTest.java
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/search/SimpleQueryTest.java (original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/search/SimpleQueryTest.java Mon Oct 4 03:23:03 2004
@@ -32,7 +32,7 @@
testRoot.save();
- String jcrql = "SELECT * FROM * LOCATION /" + TEST_ROOT + "/foo WHERE bla=\"bla\"";
+ String jcrql = "SELECT * FROM * LOCATION " + TEST_ROOT + "/foo WHERE bla=\"bla\"";
Query q = superuser.getWorkspace().getQueryManager().createQuery(jcrql, Query.JCRQL);
QueryResult result = q.execute();
checkResult(result, 1);
@@ -46,7 +46,7 @@
superuser.getRootNode().save();
- String jcrql = "SELECT * FROM nt:bla LOCATION /" + TEST_ROOT + "// WHERE bla=\"bla\"";
+ String jcrql = "SELECT * FROM nt:bla LOCATION " + TEST_ROOT + "// WHERE bla=\"bla\"";
Query q = superuser.getWorkspace().getQueryManager().createQuery(jcrql, Query.JCRQL);
QueryResult result = q.execute();
checkResult(result, 0);
@@ -60,7 +60,7 @@
testRoot.save();
- String jcrql = "SELECT * FROM nt:unstructured LOCATION /" + TEST_ROOT + "// WHERE bla=\"bla\"";
+ String jcrql = "SELECT * FROM nt:unstructured LOCATION " + TEST_ROOT + "// WHERE bla=\"bla\"";
Query q = superuser.getWorkspace().getQueryManager().createQuery(jcrql, Query.JCRQL);
QueryResult result = q.execute();
checkResult(result, 2);
@@ -74,7 +74,7 @@
testRoot.save();
- String jcrql = "SELECT * FROM nt:unstructured LOCATION /" + TEST_ROOT + "//";
+ String jcrql = "SELECT * FROM nt:unstructured LOCATION " + TEST_ROOT + "/*";
Query q = superuser.getWorkspace().getQueryManager().createQuery(jcrql, Query.JCRQL);
QueryResult result = q.execute();
checkResult(result, 2);
@@ -93,12 +93,12 @@
testRoot.save();
- String jcrql = "SELECT * FROM * LOCATION /" + TEST_ROOT + "// WHERE birth > 1976-01-01T00:00:00.000+01:00";
+ String jcrql = "SELECT * FROM * LOCATION " + TEST_ROOT + "// WHERE birth > 1976-01-01T00:00:00.000+01:00";
Query q = superuser.getWorkspace().getQueryManager().createQuery(jcrql, Query.JCRQL);
QueryResult result = q.execute();
checkResult(result, 1);
- jcrql = "SELECT * FROM * LOCATION /" + TEST_ROOT + "// WHERE birth > 1975-01-01T00:00:00.000+01:00";
+ jcrql = "SELECT * FROM * LOCATION " + TEST_ROOT + "// WHERE birth > 1975-01-01T00:00:00.000+01:00";
q = superuser.getWorkspace().getQueryManager().createQuery(jcrql, Query.JCRQL);
result = q.execute();
checkResult(result, 2);
@@ -114,17 +114,17 @@
testRoot.save();
- String jcrql = "SELECT * FROM * LOCATION /" + TEST_ROOT + "// WHERE value > 0.1e-0";
+ String jcrql = "SELECT * FROM * LOCATION " + TEST_ROOT + "// WHERE value > 0.1e-0";
Query q = superuser.getWorkspace().getQueryManager().createQuery(jcrql, Query.JCRQL);
QueryResult result = q.execute();
checkResult(result, 1);
- jcrql = "SELECT * FROM * LOCATION /" + TEST_ROOT + "// WHERE value > -0.1";
+ jcrql = "SELECT * FROM * LOCATION " + TEST_ROOT + "// WHERE value > -0.1";
q = superuser.getWorkspace().getQueryManager().createQuery(jcrql, Query.JCRQL);
result = q.execute();
checkResult(result, 2);
- jcrql = "SELECT * FROM * LOCATION /" + TEST_ROOT + "// WHERE value > -1.5";
+ jcrql = "SELECT * FROM * LOCATION " + TEST_ROOT + "// WHERE value > -1.5";
q = superuser.getWorkspace().getQueryManager().createQuery(jcrql, Query.JCRQL);
result = q.execute();
checkResult(result, 3);
@@ -140,17 +140,17 @@
testRoot.save();
- String jcrql = "SELECT * FROM * LOCATION /" + TEST_ROOT + "// WHERE value > 0";
+ String jcrql = "SELECT * FROM * LOCATION " + TEST_ROOT + "// WHERE value > 0";
Query q = superuser.getWorkspace().getQueryManager().createQuery(jcrql, Query.JCRQL);
QueryResult result = q.execute();
checkResult(result, 1);
- jcrql = "SELECT * FROM * LOCATION /" + TEST_ROOT + "// WHERE value > -1";
+ jcrql = "SELECT * FROM * LOCATION " + TEST_ROOT + "// WHERE value > -1";
q = superuser.getWorkspace().getQueryManager().createQuery(jcrql, Query.JCRQL);
result = q.execute();
checkResult(result, 2);
- jcrql = "SELECT * FROM * LOCATION /" + TEST_ROOT + "// WHERE value > -2";
+ jcrql = "SELECT * FROM * LOCATION " + TEST_ROOT + "// WHERE value > -2";
q = superuser.getWorkspace().getQueryManager().createQuery(jcrql, Query.JCRQL);
result = q.execute();
checkResult(result, 3);
@@ -166,27 +166,27 @@
testRoot.save();
- String jcrql = "SELECT * FROM * LOCATION /" + TEST_ROOT + "// WHERE value LIKE \"ping\"";
+ String jcrql = "SELECT * FROM * LOCATION " + TEST_ROOT + "// WHERE value LIKE \"ping\"";
Query q = superuser.getWorkspace().getQueryManager().createQuery(jcrql, Query.JCRQL);
QueryResult result = q.execute();
checkResult(result, 1);
- jcrql = "SELECT * FROM * LOCATION /" + TEST_ROOT + "// WHERE value LIKE \"?ing\"";
+ jcrql = "SELECT * FROM * LOCATION " + TEST_ROOT + "// WHERE value LIKE \"?ing\"";
q = superuser.getWorkspace().getQueryManager().createQuery(jcrql, Query.JCRQL);
result = q.execute();
checkResult(result, 2);
- jcrql = "SELECT * FROM * LOCATION /" + TEST_ROOT + "// WHERE value LIKE \"*ing\"";
+ jcrql = "SELECT * FROM * LOCATION " + TEST_ROOT + "// WHERE value LIKE \"*ing\"";
q = superuser.getWorkspace().getQueryManager().createQuery(jcrql, Query.JCRQL);
result = q.execute();
checkResult(result, 3);
- jcrql = "SELECT * FROM * LOCATION /" + TEST_ROOT + "// WHERE value LIKE \"_ing\"";
+ jcrql = "SELECT * FROM * LOCATION " + TEST_ROOT + "// WHERE value LIKE \"_ing\"";
q = superuser.getWorkspace().getQueryManager().createQuery(jcrql, Query.JCRQL);
result = q.execute();
checkResult(result, 2);
- jcrql = "SELECT * FROM * LOCATION /" + TEST_ROOT + "// WHERE value LIKE \"%ing\"";
+ jcrql = "SELECT * FROM * LOCATION " + TEST_ROOT + "// WHERE value LIKE \"%ing\"";
q = superuser.getWorkspace().getQueryManager().createQuery(jcrql, Query.JCRQL);
result = q.execute();
checkResult(result, 3);
@@ -202,27 +202,27 @@
testRoot.save();
- String jcrql = "SELECT * FROM * LOCATION /" + TEST_ROOT + "// WHERE value LIKE \"ping\"";
+ String jcrql = "SELECT * FROM * LOCATION " + TEST_ROOT + "// WHERE value LIKE \"ping\"";
Query q = superuser.getWorkspace().getQueryManager().createQuery(jcrql, Query.JCRQL);
QueryResult result = q.execute();
checkResult(result, 1);
- jcrql = "SELECT * FROM * LOCATION /" + TEST_ROOT + "// WHERE value LIKE \"p?ng\"";
+ jcrql = "SELECT * FROM * LOCATION " + TEST_ROOT + "// WHERE value LIKE \"p?ng\"";
q = superuser.getWorkspace().getQueryManager().createQuery(jcrql, Query.JCRQL);
result = q.execute();
checkResult(result, 2);
- jcrql = "SELECT * FROM * LOCATION /" + TEST_ROOT + "// WHERE value LIKE \"p*ng\"";
+ jcrql = "SELECT * FROM * LOCATION " + TEST_ROOT + "// WHERE value LIKE \"p*ng\"";
q = superuser.getWorkspace().getQueryManager().createQuery(jcrql, Query.JCRQL);
result = q.execute();
checkResult(result, 3);
- jcrql = "SELECT * FROM * LOCATION /" + TEST_ROOT + "// WHERE value LIKE \"p_ng\"";
+ jcrql = "SELECT * FROM * LOCATION " + TEST_ROOT + "// WHERE value LIKE \"p_ng\"";
q = superuser.getWorkspace().getQueryManager().createQuery(jcrql, Query.JCRQL);
result = q.execute();
checkResult(result, 2);
- jcrql = "SELECT * FROM * LOCATION /" + TEST_ROOT + "// WHERE value LIKE \"p%ng\"";
+ jcrql = "SELECT * FROM * LOCATION " + TEST_ROOT + "// WHERE value LIKE \"p%ng\"";
q = superuser.getWorkspace().getQueryManager().createQuery(jcrql, Query.JCRQL);
result = q.execute();
checkResult(result, 3);
@@ -238,27 +238,27 @@
testRoot.save();
- String jcrql = "SELECT * FROM * LOCATION /" + TEST_ROOT + "// WHERE value LIKE \"bli\"";
+ String jcrql = "SELECT * FROM * LOCATION " + TEST_ROOT + "// WHERE value LIKE \"bli\"";
Query q = superuser.getWorkspace().getQueryManager().createQuery(jcrql, Query.JCRQL);
QueryResult result = q.execute();
checkResult(result, 1);
- jcrql = "SELECT * FROM * LOCATION /" + TEST_ROOT + "// WHERE value LIKE \"bl?\"";
+ jcrql = "SELECT * FROM * LOCATION " + TEST_ROOT + "// WHERE value LIKE \"bl?\"";
q = superuser.getWorkspace().getQueryManager().createQuery(jcrql, Query.JCRQL);
result = q.execute();
checkResult(result, 2);
- jcrql = "SELECT * FROM * LOCATION /" + TEST_ROOT + "// WHERE value LIKE \"bl*\"";
+ jcrql = "SELECT * FROM * LOCATION " + TEST_ROOT + "// WHERE value LIKE \"bl*\"";
q = superuser.getWorkspace().getQueryManager().createQuery(jcrql, Query.JCRQL);
result = q.execute();
checkResult(result, 3);
- jcrql = "SELECT * FROM * LOCATION /" + TEST_ROOT + "// WHERE value LIKE \"bl_\"";
+ jcrql = "SELECT * FROM * LOCATION " + TEST_ROOT + "// WHERE value LIKE \"bl_\"";
q = superuser.getWorkspace().getQueryManager().createQuery(jcrql, Query.JCRQL);
result = q.execute();
checkResult(result, 2);
- jcrql = "SELECT * FROM * LOCATION /" + TEST_ROOT + "// WHERE value LIKE \"bl%\"";
+ jcrql = "SELECT * FROM * LOCATION " + TEST_ROOT + "// WHERE value LIKE \"bl%\"";
q = superuser.getWorkspace().getQueryManager().createQuery(jcrql, Query.JCRQL);
result = q.execute();
checkResult(result, 3);
@@ -276,22 +276,22 @@
testRoot.save();
- String jcrql = "SELECT * FROM * LOCATION /" + TEST_ROOT + "// WHERE value LIKE \"foo\\?bar\""; // matches node3
+ String jcrql = "SELECT * FROM * LOCATION " + TEST_ROOT + "// WHERE value LIKE \"foo\\?bar\""; // matches node3
Query q = superuser.getWorkspace().getQueryManager().createQuery(jcrql, Query.JCRQL);
QueryResult result = q.execute();
checkResult(result, 1);
- jcrql = "SELECT * FROM * LOCATION /" + TEST_ROOT + "// WHERE value LIKE \"foo?bar\""; // matches node3 and node4
+ jcrql = "SELECT * FROM * LOCATION " + TEST_ROOT + "// WHERE value LIKE \"foo?bar\""; // matches node3 and node4
q = superuser.getWorkspace().getQueryManager().createQuery(jcrql, Query.JCRQL);
result = q.execute();
checkResult(result, 2);
- jcrql = "SELECT * FROM * LOCATION /" + TEST_ROOT + "// WHERE value LIKE \"foo*bar\""; // matches all nodes
+ jcrql = "SELECT * FROM * LOCATION " + TEST_ROOT + "// WHERE value LIKE \"foo*bar\""; // matches all nodes
q = superuser.getWorkspace().getQueryManager().createQuery(jcrql, Query.JCRQL);
result = q.execute();
checkResult(result, 4);
- jcrql = "SELECT * FROM * LOCATION /" + TEST_ROOT + "// WHERE value LIKE \"foo\\\\\\?bar\""; // matches node1
+ jcrql = "SELECT * FROM * LOCATION " + TEST_ROOT + "// WHERE value LIKE \"foo\\\\\\?bar\""; // matches node1
q = superuser.getWorkspace().getQueryManager().createQuery(jcrql, Query.JCRQL);
result = q.execute();
checkResult(result, 1);
@@ -308,7 +308,7 @@
testRoot.save();
- String jcrql = "SELECT * FROM * LOCATION /" + TEST_ROOT + "// WHERE value <> \"bar\"";
+ String jcrql = "SELECT * FROM * LOCATION " + TEST_ROOT + "// WHERE value <> \"bar\"";
Query q = superuser.getWorkspace().getQueryManager().createQuery(jcrql, Query.JCRQL);
QueryResult result = q.execute();
checkResult(result, 2);