Author: ito
Date: Thu May 12 11:34:27 2011
New Revision: 1102246
URL: http://svn.apache.org/viewvc?rev=1102246&view=rev
Log:
CLEREZZA-501: facetted search possibility implemented
Added:
incubator/clerezza/issues/CLEREZZA-501/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/CountFacetCollector.java
incubator/clerezza/issues/CLEREZZA-501/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/FacetCollector.java
Modified:
incubator/clerezza/issues/CLEREZZA-501/platform.cris/src/main/java/org/apache/clerezza/platform/cris/IndexService.java
incubator/clerezza/issues/CLEREZZA-501/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/GenericCondition.java
incubator/clerezza/issues/CLEREZZA-501/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/GraphIndexer.java
incubator/clerezza/issues/CLEREZZA-501/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/PropertyHolder.java
incubator/clerezza/issues/CLEREZZA-501/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/ResourceFinder.java
incubator/clerezza/issues/CLEREZZA-501/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/VirtualProperty.java
incubator/clerezza/issues/CLEREZZA-501/rdf.cris/core/src/test/java/org/apache/clerezza/rdf/cris/GraphIndexerTest.java
Modified:
incubator/clerezza/issues/CLEREZZA-501/platform.cris/src/main/java/org/apache/clerezza/platform/cris/IndexService.java
URL:
http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-501/platform.cris/src/main/java/org/apache/clerezza/platform/cris/IndexService.java?rev=1102246&r1=1102245&r2=1102246&view=diff
==============================================================================
---
incubator/clerezza/issues/CLEREZZA-501/platform.cris/src/main/java/org/apache/clerezza/platform/cris/IndexService.java
(original)
+++
incubator/clerezza/issues/CLEREZZA-501/platform.cris/src/main/java/org/apache/clerezza/platform/cris/IndexService.java
Thu May 12 11:34:27 2011
@@ -1,18 +1,20 @@
/*
- * Copyright 2011 tio.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * under the License.
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
package org.apache.clerezza.platform.cris;
@@ -28,6 +30,7 @@ import org.apache.clerezza.rdf.core.acce
import org.apache.clerezza.rdf.core.access.NoSuchEntityException;
import org.apache.clerezza.rdf.core.access.TcManager;
import org.apache.clerezza.rdf.cris.Condition;
+import org.apache.clerezza.rdf.cris.FacetCollector;
import org.apache.clerezza.rdf.cris.GraphIndexer;
import org.apache.clerezza.rdf.cris.IndexDefinitionManager;
import org.apache.clerezza.rdf.cris.ResourceFinder;
@@ -90,6 +93,15 @@ public class IndexService extends Resour
graphIndexer = null;
}
+
+ @Override
+ public List<NonLiteral> findResources(List<Condition> conditions,
FacetCollector... facetCollectors) {
+ try {
+ return graphIndexer.findResources(conditions,
facetCollectors);
+ } catch (ParseException ex) {
+ throw new RuntimeException(ex.getMessage());
+ }
+ }
@Override
public List<NonLiteral> findResources(List<Condition> conditions) {
@@ -107,9 +119,28 @@ public class IndexService extends Resour
} catch (ParseException ex) {
throw new RuntimeException(ex.getMessage());
}
-
}
-
+
+ @Override
+ public List<NonLiteral> findResources(UriRef uriRef, String pattern,
+ boolean escapePattern) {
+ try {
+ return graphIndexer.findResources(uriRef, pattern,
escapePattern);
+ } catch (ParseException ex) {
+ throw new RuntimeException(ex.getMessage());
+ }
+ }
+
+ @Override
+ public List<NonLiteral> findResources(UriRef uriRef, String pattern,
+ boolean escapePattern, FacetCollector... facetCollectors) {
+ try {
+ return graphIndexer.findResources(uriRef, pattern,
escapePattern, facetCollectors);
+ } catch (ParseException ex) {
+ throw new RuntimeException(ex.getMessage());
+ }
+ }
+
@Override
public void reCreateIndex() {
graphIndexer.reCreateIndex();
Added:
incubator/clerezza/issues/CLEREZZA-501/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/CountFacetCollector.java
URL:
http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-501/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/CountFacetCollector.java?rev=1102246&view=auto
==============================================================================
---
incubator/clerezza/issues/CLEREZZA-501/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/CountFacetCollector.java
(added)
+++
incubator/clerezza/issues/CLEREZZA-501/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/CountFacetCollector.java
Thu May 12 11:34:27 2011
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.clerezza.rdf.cris;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * A FacetCollector that counts members of a facet.
+ *
+ * @author daniel
+ */
+public class CountFacetCollector implements FacetCollector<Integer> {
+ final private Map<VirtualProperty, Map<String, Integer>> facetMap;
+
+ /**
+ * Creates a new CountFacetCollector that collects facet data over the
+ * supplied Properties.
+ *
+ * @param properties VirtualProperties over which facet data is
collected.
+ */
+ public CountFacetCollector(Collection<VirtualProperty> properties) {
+ this();
+ for(VirtualProperty property : properties) {
+ facetMap.put(property, new HashMap<String, Integer>());
+ }
+ }
+
+ /**
+ * Default Constructor.
+ */
+ public CountFacetCollector() {
+ facetMap = new HashMap<VirtualProperty, Map<String, Integer>>();
+ }
+
+ @Override
+ public void addFacetProperty(VirtualProperty property) {
+ facetMap.put(property, new HashMap<String, Integer>());
+ }
+
+ @Override
+ public Map<VirtualProperty, Map<String, Integer>> getFacetMap() {
+ return facetMap;
+ }
+
+ @Override
+ public void addFacetValue(VirtualProperty field, String value) {
+ Map<String, Integer> propertyMap = facetMap.get(field);
+ Integer old = propertyMap.get(value);
+ propertyMap.put(value, old == null ? 1 : old + 1);
+ }
+
+ @Override
+ public Map<String, Integer> getFacets(VirtualProperty property) {
+ return facetMap.get(property);
+ }
+
+ @Override
+ public Integer getFacetValue(VirtualProperty property, String facet) {
+ return facetMap.get(property).get(facet);
+ }
+}
Added:
incubator/clerezza/issues/CLEREZZA-501/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/FacetCollector.java
URL:
http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-501/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/FacetCollector.java?rev=1102246&view=auto
==============================================================================
---
incubator/clerezza/issues/CLEREZZA-501/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/FacetCollector.java
(added)
+++
incubator/clerezza/issues/CLEREZZA-501/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/FacetCollector.java
Thu May 12 11:34:27 2011
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.clerezza.rdf.cris;
+
+import java.util.Map;
+
+/**
+ * This class is a container that defines facets that should be collected and
+ * stores them. It can be used for faceted search in CRIS.
+ *
+ * @author daniel
+ */
+public interface FacetCollector<T> {
+
+ /**
+ * Add a property over which facets are collected.
+ *
+ * Example: FOAF:firstName --> Resulting facets may be "John", "Adam",
etc.
+ *
+ * @param property A virtual property over which facets are
collected.
+ */
+ public void addFacetProperty(VirtualProperty property);
+
+ /**
+ * This method adds a new data to the facet map.
+ *
+ * @param property The property.
+ * @param value The value of the property as returned by Lucene.
+ */
+ public void addFacetValue(VirtualProperty property, String value);
+
+ /**
+ * Returns the collected data.
+ *
+ * @return The collected data.
+ */
+ public Map<VirtualProperty, Map<String, T>> getFacetMap();
+
+ /**
+ * Returns all facets for the given property.
+ *
+ * @param property the property.
+ * @return A map with facets and facet values.
+ */
+ public Map<String, T> getFacets(VirtualProperty property);
+
+ /**
+ * Returns a facet value.
+ *
+ * @param property The property.
+ * @param facet The facet.
+ * @return The facet value.
+ */
+ public T getFacetValue(VirtualProperty property, String facet);
+}
Modified:
incubator/clerezza/issues/CLEREZZA-501/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/GenericCondition.java
URL:
http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-501/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/GenericCondition.java?rev=1102246&r1=1102245&r2=1102246&view=diff
==============================================================================
---
incubator/clerezza/issues/CLEREZZA-501/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/GenericCondition.java
(original)
+++
incubator/clerezza/issues/CLEREZZA-501/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/GenericCondition.java
Thu May 12 11:34:27 2011
@@ -44,16 +44,34 @@ public class GenericCondition extends Co
/**
* Creates a new GenericCondition.
+ *
+ * Special characters in the query string are not escaped.
*
* @param properties the properties to search for.
* @param searchQuery the search string (pattern).
*/
public GenericCondition(Collection<VirtualProperty> properties, String
searchQuery) {
+ this(properties, searchQuery, false);
+ }
+
+ /**
+ * Creates a new GenericCondition.
+ *
+ * @param properties the properties to search for.
+ * @param searchQuery the search string (pattern).
+ * @param escapeQuery whether to escape special characters in the
query string or not.
+ */
+ public GenericCondition(Collection<VirtualProperty> properties, String
searchQuery, boolean escapeQuery) {
fields = new String[properties.size()];
Iterator<VirtualProperty> it = properties.iterator();
for(int i = 0; i < properties.size(); ++i) {
fields[i] = it.next().stringKey;
}
+
+ if(escapeQuery) {
+ searchQuery = QueryParser.escape(searchQuery);
+ System.out.println("ESCAPED: " + searchQuery);
+ }
this.searchQuery = searchQuery;
this.queryParser = new MultiFieldQueryParser(Version.LUCENE_30,
Modified:
incubator/clerezza/issues/CLEREZZA-501/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/GraphIndexer.java
URL:
http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-501/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/GraphIndexer.java?rev=1102246&r1=1102245&r2=1102246&view=diff
==============================================================================
---
incubator/clerezza/issues/CLEREZZA-501/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/GraphIndexer.java
(original)
+++
incubator/clerezza/issues/CLEREZZA-501/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/GraphIndexer.java
Thu May 12 11:34:27 2011
@@ -510,9 +510,13 @@ public class GraphIndexer extends Resour
}
@Override
- public List<NonLiteral> findResources(List<Condition> conditions)
+ public List<NonLiteral> findResources(List<Condition> conditions,
FacetCollector... facetCollectors)
throws ParseException {
+ if(facetCollectors == null) {
+ facetCollectors = new FacetCollector[0];
+ }
+
BooleanQuery booleanQuery = new BooleanQuery();
for (Condition c : conditions) {
booleanQuery.add(c.query(), BooleanClause.Occur.MUST);
@@ -540,11 +544,13 @@ public class GraphIndexer extends Resour
ScoreDoc[] hits = collector.topDocs().scoreDocs;
List<NonLiteral> result = new ArrayList<NonLiteral>();
+
for (ScoreDoc hit : hits) {
int docId = hit.doc;
Document d;
try {
d = searcher.doc(docId);
+ collectFacets(facetCollectors, d);
result.add(getResource(d));
} catch (CorruptIndexException ex) {
} catch (IOException ex) {
@@ -558,14 +564,6 @@ public class GraphIndexer extends Resour
return new UriRef(d.get(URI_FIELD_NAME));
}
- @Override
- public List<NonLiteral> findResources(UriRef property, String pattern)
- throws ParseException {
- List<Condition> list = new ArrayList<Condition>();
- list.add(new WildcardCondition(new PropertyHolder(property),
pattern));
- return findResources(list);
- }
-
protected void indexResource(Resource resource, IndexWriter writer) {
if (resource instanceof UriRef) {
try {
@@ -576,11 +574,26 @@ public class GraphIndexer extends Resour
indexAnonymousResource(resource);
}
}
+
+ private void collectFacets(FacetCollector[] facetCollectors, Document
d) {
+ if(facetCollectors.length > 0) {
+ for(FacetCollector facetCollector : facetCollectors) {
+ Map<VirtualProperty, Map<String, Object>>
facetMap =
+ facetCollector.getFacetMap();
+ for(VirtualProperty property :
facetMap.keySet()) {
+ String[] values =
d.getValues(property.getStringKey());
+ if(values.length > 0) {
+
facetCollector.addFacetValue(property, values[0]);
+ }
+ }
+ }
+ }
+ }
private void indexNamedResource(UriRef uriRef, IndexWriter writer)
throws IOException {
//val searcher = new IndexSearcher(index, true);
- //IndexSearcher searcher = luceneTools.getIndexSearcher();
+// IndexSearcher searcher = luceneTools.getIndexSearcher();
Term term = new Term(URI_FIELD_NAME, uriRef.getUnicodeString());
writer.deleteDocuments(term);
//the reindexing might be caused by the removal of a type
statement
Modified:
incubator/clerezza/issues/CLEREZZA-501/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/PropertyHolder.java
URL:
http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-501/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/PropertyHolder.java?rev=1102246&r1=1102245&r2=1102246&view=diff
==============================================================================
---
incubator/clerezza/issues/CLEREZZA-501/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/PropertyHolder.java
(original)
+++
incubator/clerezza/issues/CLEREZZA-501/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/PropertyHolder.java
Thu May 12 11:34:27 2011
@@ -28,8 +28,6 @@ import org.apache.clerezza.rdf.core.Lite
import org.apache.clerezza.rdf.core.Resource;
import org.apache.clerezza.rdf.core.UriRef;
import org.apache.clerezza.rdf.utils.GraphNode;
-import org.apache.clerezza.utils.UriException;
-import org.apache.clerezza.utils.UriUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -59,11 +57,7 @@ public class PropertyHolder extends Virt
if(resource instanceof Literal) {
list.add(((Literal)resource).getLexicalForm());
} else if(resource instanceof UriRef) {
- try {
-
list.add(UriUtil.encodeAll(((UriRef) resource).getUnicodeString()));
- } catch (UriException ex) {
- logger.error("Could not encode
UriRef: " + ex.getMessage());
- }
+ list.add(((UriRef)
resource).getUnicodeString());
}
}
} finally {
Modified:
incubator/clerezza/issues/CLEREZZA-501/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/ResourceFinder.java
URL:
http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-501/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/ResourceFinder.java?rev=1102246&r1=1102245&r2=1102246&view=diff
==============================================================================
---
incubator/clerezza/issues/CLEREZZA-501/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/ResourceFinder.java
(original)
+++
incubator/clerezza/issues/CLEREZZA-501/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/ResourceFinder.java
Thu May 12 11:34:27 2011
@@ -23,10 +23,8 @@ import java.util.ArrayList;
import java.util.List;
import org.apache.clerezza.rdf.core.NonLiteral;
import org.apache.clerezza.rdf.core.UriRef;
-import org.apache.lucene.index.Term;
import org.apache.lucene.queryParser.ParseException;
-import org.apache.lucene.search.Query;
-import org.apache.lucene.search.WildcardQuery;
+import org.apache.lucene.queryParser.QueryParser;
/**
*
* @author tio
@@ -46,22 +44,137 @@ import org.apache.lucene.search.Wildcard
/**
- * find resources matching the specified condition
+ * Find resources using conditions.
+ *
+ * @param conditions
+ * a list of conditions to construct a query from.
+ * @return
+ * a list of resources that match the query.
+ *
+ * @throws ParseException when the resulting query is illegal.
*/
- public abstract List<NonLiteral> findResources(List<Condition>
conditions) throws ParseException;
+ public List<NonLiteral> findResources(List<Condition> conditions)
+ throws ParseException {
+ return findResources(conditions, new FacetCollector[0]);
+ }
+
+ /**
+ * Find resources using conditions and collect facets.
+ *
+ * @param conditions
+ * a list of conditions to construct a query from.
+ * @param facetCollectors
+ * facet collectors to apply to the query result.
+ * @return
+ * a list of resources that match the query.
+ *
+ * @throws ParseException when the resulting query is illegal.
+ */
+ public abstract List<NonLiteral> findResources(List<Condition>
conditions,
+ FacetCollector... facetCollectors) throws
ParseException;
/**
- * Find resource with a properties whose value matches a pattern
+ * Find resource with given property whose value matches a pattern.
+ *
+ * @param property The property to which to apply the pattern.
+ * @param pattern The pattern from which to construct a query.
+ * @return a list of resources that match the query.
+ *
+ * @throws ParseException when the resulting query is illegal.
+ */
+ public List<NonLiteral> findResources(UriRef property, String pattern)
+ throws ParseException {
+ return findResources(property, pattern, false);
+ }
+
+ /**
+ * Find resource with given property whose value matches a pattern.
+ *
+ * @param property The property to which to apply the pattern.
+ * @param pattern The pattern from which to construct a query.
+ * @param escapePattern whether to escape reserved characters in the
pattern
+ * @return list of resources that match the query.
+ *
+ * @throws ParseException when the resulting query is illegal.
+ */
+ public List<NonLiteral> findResources(UriRef property, String pattern,
boolean escapePattern)
+ throws ParseException {
+ return findResources(property, pattern, escapePattern, new
FacetCollector[0]);
+ }
+
+ /**
+ * Find resource with given property whose value matches a pattern and
collect facets.
+ *
+ * @param property The property to which to apply the pattern.
+ * @param pattern The pattern from which to construct a query.
+ * @param escapePattern whether to escape reserved characters in the
pattern
+ * @param facetCollectors facet collectors to apply to the query result.
+ * @return a list of resources that match the query.
+ *
+ * @throws ParseException when the resulting query is illegal.
+ */
+ public List<NonLiteral> findResources(UriRef property, String pattern,
+ boolean escapePattern, FacetCollector...
facetCollectors)
+ throws ParseException {
+
+ List<Condition> list = new ArrayList<Condition>();
+ if(escapePattern) {
+ pattern = QueryParser.escape(pattern);
+ }
+ list.add(new WildcardCondition(new PropertyHolder(property),
pattern));
+ return findResources(list, facetCollectors);
+ }
+
+ /**
+ * Find resource with given VirtualProperty whose value matches a
pattern.
+ *
+ * @param property The property to which to apply the pattern.
+ * @param pattern The pattern from which to construct a query.
+ * @return a list of resources that match the query.
+ *
+ * @throws ParseException when the resulting query is illegal.
*/
- public abstract List<NonLiteral> findResources(UriRef property, String
pattern) throws ParseException ;
+ public List<NonLiteral> findResources(VirtualProperty property, String
pattern)
+ throws ParseException {
+ return findResources(property, pattern, false);
+ }
- public List<NonLiteral> findResources(VirtualProperty property,String
pattern) throws ParseException {
- //TODO?
- Query query = new WildcardQuery(new Term(property.stringKey,
pattern));
+ /**
+ * Find resource with given VirtualProperty whose value matches a
pattern.
+ *
+ * @param property The property to which to apply the pattern.
+ * @param pattern The pattern from which to construct a query.
+ * @param escapePattern whether to escape reserved characters in the
pattern
+ * @return a list of resources that match the query.
+ *
+ * @throws ParseException when the resulting query is illegal.
+ */
+ public List<NonLiteral> findResources(VirtualProperty property, String
pattern,
+ boolean escapePattern) throws ParseException {
+
+ return findResources(property, pattern, escapePattern, new
FacetCollector[0]);
+ }
+
+ /**
+ * Find resource with given VirtualProperty whose value matches a
pattern and collect facets.
+ *
+ * @param property The property to which to apply the pattern.
+ * @param pattern The pattern from which to construct a query.
+ * @param escapePattern whether to escape reserved characters in the
pattern
+ * @param facetCollectors facet collectors to apply to the query
result.
+ * @return a list of resources that match the query.
+ *
+ * @throws ParseException when the resulting query is illegal.
+ */
+ public List<NonLiteral> findResources(VirtualProperty property, String
pattern,
+ boolean escapePattern, FacetCollector...
facetCollectors)
+ throws ParseException {
+
List<Condition> list = new ArrayList<Condition>();
+ if(escapePattern) {
+ pattern = QueryParser.escape(pattern);
+ }
list.add(new WildcardCondition(property, pattern));
- return findResources(list);
+ return findResources(list, facetCollectors);
}
-
-
}
Modified:
incubator/clerezza/issues/CLEREZZA-501/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/VirtualProperty.java
URL:
http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-501/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/VirtualProperty.java?rev=1102246&r1=1102245&r2=1102246&view=diff
==============================================================================
---
incubator/clerezza/issues/CLEREZZA-501/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/VirtualProperty.java
(original)
+++
incubator/clerezza/issues/CLEREZZA-501/rdf.cris/core/src/main/java/org/apache/clerezza/rdf/cris/VirtualProperty.java
Thu May 12 11:34:27 2011
@@ -76,4 +76,25 @@ public abstract class VirtualProperty {
return Util.sha1(builder.toString());
}
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == null) {
+ return false;
+ }
+ if (!(obj instanceof VirtualProperty)) {
+ return false;
+ }
+ final VirtualProperty other = (VirtualProperty) obj;
+ if (!stringKey.equals(other.stringKey)) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ return stringKey.hashCode();
+ }
+
+
}
Modified:
incubator/clerezza/issues/CLEREZZA-501/rdf.cris/core/src/test/java/org/apache/clerezza/rdf/cris/GraphIndexerTest.java
URL:
http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-501/rdf.cris/core/src/test/java/org/apache/clerezza/rdf/cris/GraphIndexerTest.java?rev=1102246&r1=1102245&r2=1102246&view=diff
==============================================================================
---
incubator/clerezza/issues/CLEREZZA-501/rdf.cris/core/src/test/java/org/apache/clerezza/rdf/cris/GraphIndexerTest.java
(original)
+++
incubator/clerezza/issues/CLEREZZA-501/rdf.cris/core/src/test/java/org/apache/clerezza/rdf/cris/GraphIndexerTest.java
Thu May 12 11:34:27 2011
@@ -16,11 +16,8 @@
*/
package org.apache.clerezza.rdf.cris;
-import java.net.URL;
import java.util.ArrayList;
import java.util.List;
-import java.util.logging.Level;
-import java.util.logging.Logger;
import org.apache.clerezza.rdf.cris.ontologies.CRIS;
import org.apache.clerezza.rdf.core.*;
import org.apache.clerezza.rdf.core.impl.*;
@@ -28,8 +25,6 @@ import org.apache.clerezza.rdf.utils.*;
import org.apache.clerezza.rdf.ontologies.FOAF;
import org.apache.clerezza.rdf.ontologies.RDF;
import org.apache.clerezza.rdf.ontologies.RDFS;
-import org.apache.clerezza.utils.UriException;
-import org.apache.clerezza.utils.UriUtil;
import org.apache.lucene.queryParser.ParseException;
import org.wymiwyg.commons.util.Util;
import org.junit.*;
@@ -108,18 +103,17 @@ public class GraphIndexerTest {
List<NonLiteral> results;
//TODO
Thread.sleep(1000);
-
- try {
- String encodedUri =
UriUtil.encodeAll("p://myhomepage/foo?query=bla&bla=te");
- results = service.findResources(FOAF.homepage, "*" +
encodedUri + "*");
- Assert.assertEquals(1, results.size());
- } catch (UriException ex) {
- }
+ results = service.findResources(FOAF.homepage,
"*tp://myhomepage/foo?query=bla*");
+ Assert.assertEquals(1, results.size());
+
+ results = service.findResources(FOAF.homepage,
"http://myhomepage/foo?query=bla&bla=test");
+ Assert.assertEquals(1, results.size());
+
}
- @Test
+ /*@Test
public void findResources() throws ParseException, InterruptedException
{
List<NonLiteral> results;
//TODO
@@ -358,5 +352,5 @@ public class GraphIndexerTest {
} catch (ParseException ex) {
} catch (InterruptedException ex) {
}
- }
+ }*/
}