You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by rw...@apache.org on 2012/10/17 15:38:51 UTC
svn commit: r1399247 - in /stanbol/trunk/contenthub: ldpath/ search/featured/
search/featured/src/main/java/org/apache/stanbol/contenthub/search/featured/
search/related/ search/solr/
search/solr/src/main/java/org/apache/stanbol/contenthub/search/solr/...
Author: rwesten
Date: Wed Oct 17 13:38:50 2012
New Revision: 1399247
URL: http://svn.apache.org/viewvc?rev=1399247&view=rev
Log:
STANBOL-774 related POM adaptions for the contenthub modules;
STANBOL-773 moved SolrQueryUtils to the servicesapi module to avoid dependencies to the contenthub.search.solr module (the old is still present but deprecated)
Added:
stanbol/trunk/contenthub/servicesapi/src/main/java/org/apache/stanbol/contenthub/servicesapi/search/solr/SolrQueryUtil.java (with props)
Modified:
stanbol/trunk/contenthub/ldpath/pom.xml
stanbol/trunk/contenthub/search/featured/pom.xml
stanbol/trunk/contenthub/search/featured/src/main/java/org/apache/stanbol/contenthub/search/featured/FeaturedSearchImpl.java
stanbol/trunk/contenthub/search/related/pom.xml
stanbol/trunk/contenthub/search/solr/pom.xml
stanbol/trunk/contenthub/search/solr/src/main/java/org/apache/stanbol/contenthub/search/solr/SolrSearchImpl.java
stanbol/trunk/contenthub/search/solr/src/main/java/org/apache/stanbol/contenthub/search/solr/util/SolrQueryUtil.java
stanbol/trunk/contenthub/servicesapi/pom.xml
stanbol/trunk/contenthub/store/clerezza/pom.xml
stanbol/trunk/contenthub/store/inmemory/pom.xml
stanbol/trunk/contenthub/store/inmemory/src/main/java/org/apache/stanbol/contenthub/store/inmemory/InMemoryStore.java
stanbol/trunk/contenthub/store/solr/pom.xml
stanbol/trunk/contenthub/store/solr/src/main/java/org/apache/stanbol/contenthub/store/solr/SolrContentItemImpl.java
stanbol/trunk/contenthub/web/pom.xml
Modified: stanbol/trunk/contenthub/ldpath/pom.xml
URL: http://svn.apache.org/viewvc/stanbol/trunk/contenthub/ldpath/pom.xml?rev=1399247&r1=1399246&r2=1399247&view=diff
==============================================================================
--- stanbol/trunk/contenthub/ldpath/pom.xml (original)
+++ stanbol/trunk/contenthub/ldpath/pom.xml Wed Oct 17 13:38:50 2012
@@ -40,6 +40,21 @@
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Import-Package>
+ org.apache.stanbol.contenthub.servicesapi.ldpath; provide:=true,
+ *
+ </Import-Package>
+ <Export-Package>
+ </Export-Package>
+ <Private-Package>
+ org.apache.stanbol.contenthub.ldpath.solr,
+ </Private-Package>
+ <Embed-Dependency>
+ </Embed-Dependency>
+ </instructions>
+ </configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
Modified: stanbol/trunk/contenthub/search/featured/pom.xml
URL: http://svn.apache.org/viewvc/stanbol/trunk/contenthub/search/featured/pom.xml?rev=1399247&r1=1399246&r2=1399247&view=diff
==============================================================================
--- stanbol/trunk/contenthub/search/featured/pom.xml (original)
+++ stanbol/trunk/contenthub/search/featured/pom.xml Wed Oct 17 13:38:50 2012
@@ -35,6 +35,20 @@
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Import-Package>
+ org.apache.stanbol.contenthub.servicesapi.search.featured; provide:=true,
+ *
+ </Import-Package>
+ <Export-Package>
+ org.apache.stanbol.contenthub.search.featured,
+ org.apache.stanbol.contenthub.search.featured.util
+ </Export-Package>
+ <Embed-Dependency>
+ </Embed-Dependency>
+ </instructions>
+ </configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
@@ -54,11 +68,11 @@
<artifactId>org.apache.stanbol.contenthub.store.solr</artifactId>
<version>0.9.0-incubating</version>
</dependency>
- <dependency>
+ <!-- dependency>
<groupId>org.apache.stanbol</groupId>
<artifactId>org.apache.stanbol.contenthub.search.solr</artifactId>
<version>0.10.0-SNAPSHOT</version>
- </dependency>
+ </dependency -->
<dependency>
<groupId>org.apache.felix</groupId>
Modified: stanbol/trunk/contenthub/search/featured/src/main/java/org/apache/stanbol/contenthub/search/featured/FeaturedSearchImpl.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/contenthub/search/featured/src/main/java/org/apache/stanbol/contenthub/search/featured/FeaturedSearchImpl.java?rev=1399247&r1=1399246&r2=1399247&view=diff
==============================================================================
--- stanbol/trunk/contenthub/search/featured/src/main/java/org/apache/stanbol/contenthub/search/featured/FeaturedSearchImpl.java (original)
+++ stanbol/trunk/contenthub/search/featured/src/main/java/org/apache/stanbol/contenthub/search/featured/FeaturedSearchImpl.java Wed Oct 17 13:38:50 2012
@@ -45,7 +45,6 @@ import org.apache.solr.common.params.Sol
import org.apache.solr.common.util.NamedList;
import org.apache.stanbol.commons.solr.managed.ManagedSolrServer;
import org.apache.stanbol.contenthub.search.featured.util.SolrContentItemConverter;
-import org.apache.stanbol.contenthub.search.solr.util.SolrQueryUtil;
import org.apache.stanbol.contenthub.servicesapi.search.SearchException;
import org.apache.stanbol.contenthub.servicesapi.search.featured.ConstrainedDocumentSet;
import org.apache.stanbol.contenthub.servicesapi.search.featured.Constraint;
@@ -55,6 +54,7 @@ import org.apache.stanbol.contenthub.ser
import org.apache.stanbol.contenthub.servicesapi.search.featured.SearchResult;
import org.apache.stanbol.contenthub.servicesapi.search.related.RelatedKeyword;
import org.apache.stanbol.contenthub.servicesapi.search.related.RelatedKeywordSearchManager;
+import org.apache.stanbol.contenthub.servicesapi.search.solr.SolrQueryUtil;
import org.apache.stanbol.contenthub.servicesapi.search.solr.SolrSearch;
import org.apache.stanbol.contenthub.servicesapi.store.StoreException;
import org.apache.stanbol.contenthub.servicesapi.store.vocabulary.SolrVocabulary.SolrFieldName;
Modified: stanbol/trunk/contenthub/search/related/pom.xml
URL: http://svn.apache.org/viewvc/stanbol/trunk/contenthub/search/related/pom.xml?rev=1399247&r1=1399246&r2=1399247&view=diff
==============================================================================
--- stanbol/trunk/contenthub/search/related/pom.xml (original)
+++ stanbol/trunk/contenthub/search/related/pom.xml Wed Oct 17 13:38:50 2012
@@ -36,6 +36,24 @@
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Import-Package>
+ org.apache.stanbol.contenthub.servicesapi.search.related; provide:=true,
+ org.apache.stanbol.contenthub.servicesapi.search.featured; provide:=true,
+ *
+ </Import-Package>
+ <Export-Package>
+ </Export-Package>
+ <Private-Package>
+ org.apache.stanbol.contenthub.search.related,
+ org.apache.stanbol.contenthub.search.related.ontologyresource,
+ org.apache.stanbol.contenthub.search.related.referencedsite
+ </Private-Package>
+ <Embed-Dependency>
+ </Embed-Dependency>
+ </instructions>
+ </configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
Modified: stanbol/trunk/contenthub/search/solr/pom.xml
URL: http://svn.apache.org/viewvc/stanbol/trunk/contenthub/search/solr/pom.xml?rev=1399247&r1=1399246&r2=1399247&view=diff
==============================================================================
--- stanbol/trunk/contenthub/search/solr/pom.xml (original)
+++ stanbol/trunk/contenthub/search/solr/pom.xml Wed Oct 17 13:38:50 2012
@@ -35,6 +35,20 @@
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Import-Package>
+ org.apache.stanbol.contenthub.servicesapi.search.solr; provide:=true,
+ *
+ </Import-Package>
+ <Export-Package>
+ org.apache.stanbol.contenthub.search.solr,
+ org.apache.stanbol.contenthub.search.solr.util
+ </Export-Package>
+ <Embed-Dependency>
+ </Embed-Dependency>
+ </instructions>
+ </configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
Modified: stanbol/trunk/contenthub/search/solr/src/main/java/org/apache/stanbol/contenthub/search/solr/SolrSearchImpl.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/contenthub/search/solr/src/main/java/org/apache/stanbol/contenthub/search/solr/SolrSearchImpl.java?rev=1399247&r1=1399246&r2=1399247&view=diff
==============================================================================
--- stanbol/trunk/contenthub/search/solr/src/main/java/org/apache/stanbol/contenthub/search/solr/SolrSearchImpl.java (original)
+++ stanbol/trunk/contenthub/search/solr/src/main/java/org/apache/stanbol/contenthub/search/solr/SolrSearchImpl.java Wed Oct 17 13:38:50 2012
@@ -28,8 +28,8 @@ import org.apache.solr.client.solrj.Solr
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.params.SolrParams;
import org.apache.stanbol.commons.solr.managed.ManagedSolrServer;
-import org.apache.stanbol.contenthub.search.solr.util.SolrQueryUtil;
import org.apache.stanbol.contenthub.servicesapi.search.SearchException;
+import org.apache.stanbol.contenthub.servicesapi.search.solr.SolrQueryUtil;
import org.apache.stanbol.contenthub.servicesapi.search.solr.SolrSearch;
import org.apache.stanbol.contenthub.servicesapi.store.StoreException;
import org.apache.stanbol.contenthub.store.solr.manager.SolrCoreManager;
Modified: stanbol/trunk/contenthub/search/solr/src/main/java/org/apache/stanbol/contenthub/search/solr/util/SolrQueryUtil.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/contenthub/search/solr/src/main/java/org/apache/stanbol/contenthub/search/solr/util/SolrQueryUtil.java?rev=1399247&r1=1399246&r2=1399247&view=diff
==============================================================================
--- stanbol/trunk/contenthub/search/solr/src/main/java/org/apache/stanbol/contenthub/search/solr/util/SolrQueryUtil.java (original)
+++ stanbol/trunk/contenthub/search/solr/src/main/java/org/apache/stanbol/contenthub/search/solr/util/SolrQueryUtil.java Wed Oct 17 13:38:50 2012
@@ -43,8 +43,10 @@ import org.slf4j.LoggerFactory;
/**
*
* @author anil.pacaci
- *
+ * @deprecated This class was moved to
+ * {@link org.apache.stanbol.contenthub.servicesapi.search.solr.SolrQueryUtil}
*/
+@Deprecated
public class SolrQueryUtil {
private final static Logger log = LoggerFactory.getLogger(SolrQueryUtil.class);
@@ -60,6 +62,7 @@ public class SolrQueryUtil {
public final static List<Character> queryDelimiters = Arrays.asList(' ', ',');
+ @Deprecated
private static String removeFacetConstraints(String query) {
int delimiteri = query.indexOf(facetDelimiter);
while (delimiteri > -1) {
@@ -87,6 +90,7 @@ public class SolrQueryUtil {
return query;
}
+ @Deprecated
private static String removeSpecialCharacter(String query, char ch) {
int starti = query.indexOf(ch);
while (starti > -1) {
@@ -99,6 +103,7 @@ public class SolrQueryUtil {
return query;
}
+ @Deprecated
private static String removeSpecialCharacters(String query) {
query = query.replaceAll("[+|\\-&!\\(\\)\\{\\}\\[\\]\\*\\?\\\\]", "");
query = removeSpecialCharacter(query, '^');
@@ -106,6 +111,7 @@ public class SolrQueryUtil {
return query;
}
+ @Deprecated
public static String extractQueryTermFromSolrQuery(SolrParams solrQuery) {
String queryFull = solrQuery instanceof SolrQuery ? ((SolrQuery) solrQuery).getQuery() : solrQuery
.get(CommonParams.Q);
@@ -125,6 +131,7 @@ public class SolrQueryUtil {
* @param allAvailableFacetNames
* list of facets
*/
+ @Deprecated
public static <T> void setFacetFields(SolrQuery solrQuery, List<T> allAvailableFacetNames) {
solrQuery.setFields("*", SCORE_FIELD);
solrQuery.setFacet(true);
@@ -162,6 +169,7 @@ public class SolrQueryUtil {
* @throws SolrServerException
* @throws IOException
*/
+ @Deprecated
public static SolrQuery prepareSolrQuery(SolrServer solrServer, String queryTerm) throws SolrServerException,
IOException {
SolrQuery solrQuery = new SolrQuery();
@@ -177,6 +185,7 @@ public class SolrQueryUtil {
* {@link String} query term to be represented as a {@link SolrQuery}
* @return {@link SolrQuery} wrapping the given <code>queryTerm</code>
*/
+ @Deprecated
public static SolrQuery prepareSolrQuery(String queryTerm) {
SolrQuery solrQuery = new SolrQuery();
solrQuery.setQuery(queryTerm);
@@ -196,6 +205,7 @@ public class SolrQueryUtil {
* additional constraints to be applied in the {@link SolrQuery}.
* @return {@link SolrQuery} constructed by using the given parameters
*/
+ @Deprecated
public static SolrQuery prepareSolrQuery(String queryTerm,
List<FacetResult> allAvailableFacets,
Map<String,List<Object>> constraints) {
@@ -222,6 +232,7 @@ public class SolrQueryUtil {
return query;
}
+ @Deprecated
private static String getFacetFieldType(String fieldName, List<FacetResult> allAvailableFacets) {
for (FacetResult fr : allAvailableFacets) {
if (fieldName.equals(fr.getFacetField().getName())) {
@@ -231,6 +242,7 @@ public class SolrQueryUtil {
return "";
}
+ @Deprecated
public static List<String> getAllFacetNames(SolrServer solrServer) throws SolrServerException,
IOException {
List<String> facetNames = new ArrayList<String>();
@@ -241,6 +253,7 @@ public class SolrQueryUtil {
return facetNames;
}
+ @Deprecated
public static NamedList<Object> getAllFacetFields(SolrServer solrServer) throws SolrServerException,
IOException {
LukeRequest qr = new LukeRequest();
@@ -266,6 +279,7 @@ public class SolrQueryUtil {
* @param solrQuery
* {@link SolrQuery} to be updated with the given <code>constraints</code>
*/
+ @Deprecated
public static void addConstraintsToSolrQuery(Set<Constraint> constraints, SolrQuery solrQuery) {
if (constraints != null) {
for (Constraint constraint : constraints) {
Modified: stanbol/trunk/contenthub/servicesapi/pom.xml
URL: http://svn.apache.org/viewvc/stanbol/trunk/contenthub/servicesapi/pom.xml?rev=1399247&r1=1399246&r2=1399247&view=diff
==============================================================================
--- stanbol/trunk/contenthub/servicesapi/pom.xml (original)
+++ stanbol/trunk/contenthub/servicesapi/pom.xml Wed Oct 17 13:38:50 2012
@@ -34,6 +34,16 @@
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Export-Package>
+ org.apache.stanbol.contenthub.servicesapi;version=${project.version},
+ org.apache.stanbol.contenthub.servicesapi.*;version=${project.version}
+ </Export-Package>
+ <Embed-Dependency>
+ </Embed-Dependency>
+ </instructions>
+ </configuration>
</plugin>
</plugins>
</build>
Added: stanbol/trunk/contenthub/servicesapi/src/main/java/org/apache/stanbol/contenthub/servicesapi/search/solr/SolrQueryUtil.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/contenthub/servicesapi/src/main/java/org/apache/stanbol/contenthub/servicesapi/search/solr/SolrQueryUtil.java?rev=1399247&view=auto
==============================================================================
--- stanbol/trunk/contenthub/servicesapi/src/main/java/org/apache/stanbol/contenthub/servicesapi/search/solr/SolrQueryUtil.java (added)
+++ stanbol/trunk/contenthub/servicesapi/src/main/java/org/apache/stanbol/contenthub/servicesapi/search/solr/SolrQueryUtil.java Wed Oct 17 13:38:50 2012
@@ -0,0 +1,276 @@
+/*
+ * 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.stanbol.contenthub.servicesapi.search.solr;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+import org.apache.solr.client.solrj.SolrQuery;
+import org.apache.solr.client.solrj.SolrServer;
+import org.apache.solr.client.solrj.SolrServerException;
+import org.apache.solr.client.solrj.request.LukeRequest;
+import org.apache.solr.client.solrj.util.ClientUtils;
+import org.apache.solr.common.params.CommonParams;
+import org.apache.solr.common.params.SolrParams;
+import org.apache.solr.common.util.NamedList;
+import org.apache.stanbol.contenthub.servicesapi.search.featured.Constraint;
+import org.apache.stanbol.contenthub.servicesapi.search.featured.Facet;
+import org.apache.stanbol.contenthub.servicesapi.search.featured.FacetResult;
+import org.apache.stanbol.contenthub.servicesapi.store.vocabulary.SolrVocabulary;
+import org.apache.stanbol.contenthub.servicesapi.store.vocabulary.SolrVocabulary.SolrFieldName;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ *
+ * @author anil.pacaci
+ *
+ */
+public class SolrQueryUtil {
+
+ private final static Logger log = LoggerFactory.getLogger(SolrQueryUtil.class);
+
+ public static final String CONTENT_FIELD = "content_t";
+ public static final String ID_FIELD = "id";
+ public static final String SCORE_FIELD = "score";
+
+ public final static String and = "AND";
+ public final static String or = "OR";
+ public final static String facetDelimiter = ":";
+ public final static char quotation = '"';
+
+ public final static List<Character> queryDelimiters = Arrays.asList(' ', ',');
+
+ private static String removeFacetConstraints(String query) {
+ int delimiteri = query.indexOf(facetDelimiter);
+ while (delimiteri > -1) {
+ int starti = delimiteri;
+ for (starti = delimiteri; starti >= 0 && !queryDelimiters.contains(query.charAt(starti)); starti--)
+ ;
+ ++starti;
+
+ int endi = delimiteri + 1;
+ if (endi < query.length()) {
+ if (query.charAt(endi) == quotation) {
+ ++endi;
+ for (; endi < query.length() && query.charAt(endi) != quotation; endi++)
+ ;
+ ++endi;
+ } else {
+ for (; endi < query.length() && !queryDelimiters.contains(query.charAt(endi)); endi++)
+ ;
+ }
+ }
+ query = query.substring(0, starti) + (endi >= query.length() ? "" : query.substring(endi));
+ delimiteri = query.indexOf(facetDelimiter);
+ }
+ query = query.replaceAll(and + '|' + or + '|' + and.toLowerCase() + '|' + or.toLowerCase(), "");
+ return query;
+ }
+
+ private static String removeSpecialCharacter(String query, char ch) {
+ int starti = query.indexOf(ch);
+ while (starti > -1) {
+ int endi = -1;
+ for (endi = starti; endi < query.length() && !queryDelimiters.contains(query.charAt(endi)); endi++)
+ ;
+ query = query.substring(0, starti) + (endi >= query.length() ? "" : query.substring(endi));
+ starti = query.indexOf(ch);
+ }
+ return query;
+ }
+
+ private static String removeSpecialCharacters(String query) {
+ query = query.replaceAll("[+|\\-&!\\(\\)\\{\\}\\[\\]\\*\\?\\\\]", "");
+ query = removeSpecialCharacter(query, '^');
+ query = removeSpecialCharacter(query, '~');
+ return query;
+ }
+
+ public static String extractQueryTermFromSolrQuery(SolrParams solrQuery) {
+ String queryFull = solrQuery instanceof SolrQuery ? ((SolrQuery) solrQuery).getQuery() : solrQuery
+ .get(CommonParams.Q);
+ queryFull = removeSpecialCharacters(queryFull);
+ queryFull = removeFacetConstraints(queryFull);
+ return queryFull.trim();
+ }
+
+ /**
+ * This methods adds a facet field the given <code>solrQuery</code> for each facet passed in
+ * <code>allAvailableFacetNames</code>. This provides obtaining information about specified facets such as
+ * possible facet values, number documents of documents matching with certain values of facets, etc in the
+ * search results.
+ *
+ * @param solrQuery
+ * {@link SolrQuery} to be extended with facet fields
+ * @param allAvailableFacetNames
+ * list of facets
+ */
+ public static <T> void setFacetFields(SolrQuery solrQuery, List<T> allAvailableFacetNames) {
+ solrQuery.setFields("*", SCORE_FIELD);
+ solrQuery.setFacet(true);
+ solrQuery.setFacetMinCount(1);
+ if (allAvailableFacetNames != null) {
+ for (T facet : allAvailableFacetNames) {
+ String facetName;
+ if (facet instanceof String) {
+ facetName = (String) facet;
+ } else if (facet instanceof FacetResult) {
+ facetName = ((FacetResult) facet).getFacetField().getName();
+ } else {
+ facetName = facet.toString();
+ }
+ if (SolrFieldName.CREATIONDATE.toString().equals(facetName)
+ || (!SolrFieldName.isNameReserved(facetName) && !SolrVocabulary.isNameExcluded(facetName))) {
+ solrQuery.addFacetField(facetName);
+ }
+ }
+ }
+ }
+
+ /**
+ * This method create a {@link SolrQuery} using the given parameters. <code>queryTerm</code> is the main
+ * query of the solr query to be created. <code>solrServer</code> is used fetch possible facet fields of
+ * the underlying Solr schema. Obtained facet names are attached to the query to obtain the corresponding
+ * facet information such as possible facet values, number documents of documents matching with certain
+ * values of facets, etc in the search results.
+ *
+ * @param solrServer
+ * Solr server to obtain corresponding facet names
+ * @param queryTerm
+ * main query term to be used in {@link SolrQuery#setQuery(String)}
+ * @return {@link SolrQuery} constructed by using the given parameters
+ * @throws SolrServerException
+ * @throws IOException
+ */
+ public static SolrQuery prepareSolrQuery(SolrServer solrServer, String queryTerm) throws SolrServerException,
+ IOException {
+ SolrQuery solrQuery = new SolrQuery();
+ solrQuery.setQuery(queryTerm);
+ setFacetFields(solrQuery, getAllFacetNames(solrServer));
+ return solrQuery;
+ }
+
+ /**
+ * This method simply wraps the given <code>queryTerm</code> in a {@link SolrQuery} instance.
+ *
+ * @param queryTerm
+ * {@link String} query term to be represented as a {@link SolrQuery}
+ * @return {@link SolrQuery} wrapping the given <code>queryTerm</code>
+ */
+ public static SolrQuery prepareSolrQuery(String queryTerm) {
+ SolrQuery solrQuery = new SolrQuery();
+ solrQuery.setQuery(queryTerm);
+ return solrQuery;
+ }
+
+ /**
+ * This method creates a {@link SolrQuery} with the given parameters. It sets the <code>queryTerm</code>
+ * as the main query and for each constraint passed in the <code>constraints</code> a filter query is
+ * added to the solr query.
+ *
+ * @param queryTerm
+ * main query to be used in {@link SolrQuery#setQuery(String)}
+ * @param allAvailableFacets
+ * {@link FacetResult}s passed in this list are used to check types of the facets.
+ * @param constraints
+ * additional constraints to be applied in the {@link SolrQuery}.
+ * @return {@link SolrQuery} constructed by using the given parameters
+ */
+ public static SolrQuery prepareSolrQuery(String queryTerm,
+ List<FacetResult> allAvailableFacets,
+ Map<String,List<Object>> constraints) {
+ SolrQuery query = new SolrQuery();
+ query.setQuery(queryTerm);
+ if (constraints != null) {
+ try {
+ for (Entry<String,List<Object>> entry : constraints.entrySet()) {
+ String fieldName = ClientUtils.escapeQueryChars(entry.getKey());
+ String type = getFacetFieldType(fieldName, allAvailableFacets);
+ for (Object value : entry.getValue()) {
+ if (SolrVocabulary.isRangeType(type)) {
+ query.addFilterQuery(fieldName + facetDelimiter + (String) value);
+ } else {
+ query.addFilterQuery(fieldName + facetDelimiter + quotation
+ + ClientUtils.escapeQueryChars((String) value) + quotation);
+ }
+ }
+ }
+ } catch (Exception e) {
+ log.warn("Facet constraints could not be added to Query", e);
+ }
+ }
+ return query;
+ }
+
+ private static String getFacetFieldType(String fieldName, List<FacetResult> allAvailableFacets) {
+ for (FacetResult fr : allAvailableFacets) {
+ if (fieldName.equals(fr.getFacetField().getName())) {
+ return fr.getType();
+ }
+ }
+ return "";
+ }
+
+ public static List<String> getAllFacetNames(SolrServer solrServer) throws SolrServerException,
+ IOException {
+ List<String> facetNames = new ArrayList<String>();
+ NamedList<Object> fieldsList = getAllFacetFields(solrServer);
+ for (int i = 0; i < fieldsList.size(); i++) {
+ facetNames.add(fieldsList.getName(i));
+ }
+ return facetNames;
+ }
+
+ public static NamedList<Object> getAllFacetFields(SolrServer solrServer) throws SolrServerException,
+ IOException {
+ LukeRequest qr = new LukeRequest();
+ NamedList<Object> qresp = solrServer.request(qr);
+ Object fields = qresp.get("fields");
+ if (fields instanceof NamedList<?>) {
+ @SuppressWarnings("unchecked")
+ NamedList<Object> fieldsList = (NamedList<Object>) fields;
+ return fieldsList;
+ } else {
+ throw new IllegalStateException(
+ "Fields container is not a NamedList, so there is no facet information available");
+ }
+ }
+
+ /**
+ * This method parses the {@link Set} of {@link Constraint} and update the {@link SolrQuery} with
+ * corresponding field queries. Name of the field is obtained from associated {@link Facet} of a
+ * constraint and the value is obtained from the constraint itself.
+ *
+ * @param constraints
+ * {@link Set} of {@link Constraint}s to be transformed into the given <code>solrQuery</code>
+ * @param solrQuery
+ * {@link SolrQuery} to be updated with the given <code>constraints</code>
+ */
+ public static void addConstraintsToSolrQuery(Set<Constraint> constraints, SolrQuery solrQuery) {
+ if (constraints != null) {
+ for (Constraint constraint : constraints) {
+ solrQuery.addFilterQuery(constraint.getFacet().getLabel(null) + ":" + constraint.getValue());
+ }
+ }
+ }
+}
Propchange: stanbol/trunk/contenthub/servicesapi/src/main/java/org/apache/stanbol/contenthub/servicesapi/search/solr/SolrQueryUtil.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: stanbol/trunk/contenthub/store/clerezza/pom.xml
URL: http://svn.apache.org/viewvc/stanbol/trunk/contenthub/store/clerezza/pom.xml?rev=1399247&r1=1399246&r2=1399247&view=diff
==============================================================================
--- stanbol/trunk/contenthub/store/clerezza/pom.xml (original)
+++ stanbol/trunk/contenthub/store/clerezza/pom.xml Wed Oct 17 13:38:50 2012
@@ -41,8 +41,14 @@
the 0.0.0 version -->
<Import-Package>
javax.ws.rs.*; version="[0,2)",
+ org.apache.stanbol.enhancer.servicesapi; provide:=true,
+ org.apache.stanbol.enhancer.servicesapi.impl; provide:=true,
+ org.apache.stanbol.contenthub.servicesapi.store; provide:=true,
*
</Import-Package>
+ <Private-Package>
+ org.apache.stanbol.contenthub.store.clerezza
+ </Private-Package>
</instructions>
</configuration>
</plugin>
Modified: stanbol/trunk/contenthub/store/inmemory/pom.xml
URL: http://svn.apache.org/viewvc/stanbol/trunk/contenthub/store/inmemory/pom.xml?rev=1399247&r1=1399246&r2=1399247&view=diff
==============================================================================
--- stanbol/trunk/contenthub/store/inmemory/pom.xml (original)
+++ stanbol/trunk/contenthub/store/inmemory/pom.xml Wed Oct 17 13:38:50 2012
@@ -35,6 +35,21 @@
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Import-Package>
+ org.apache.stanbol.contenthub.servicesapi.store; provide:=true,
+ *
+ </Import-Package>
+ <Export-Package>
+ </Export-Package>
+ <Private-Package>
+ org.apache.stanbol.contenthub.store.inmemory
+ </Private-Package>
+ <Embed-Dependency>
+ </Embed-Dependency>
+ </instructions>
+ </configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
Modified: stanbol/trunk/contenthub/store/inmemory/src/main/java/org/apache/stanbol/contenthub/store/inmemory/InMemoryStore.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/contenthub/store/inmemory/src/main/java/org/apache/stanbol/contenthub/store/inmemory/InMemoryStore.java?rev=1399247&r1=1399246&r2=1399247&view=diff
==============================================================================
--- stanbol/trunk/contenthub/store/inmemory/src/main/java/org/apache/stanbol/contenthub/store/inmemory/InMemoryStore.java (original)
+++ stanbol/trunk/contenthub/store/inmemory/src/main/java/org/apache/stanbol/contenthub/store/inmemory/InMemoryStore.java Wed Oct 17 13:38:50 2012
@@ -26,7 +26,6 @@ import org.apache.clerezza.rdf.core.Trip
import org.apache.clerezza.rdf.core.UriRef;
import org.apache.clerezza.rdf.core.access.NoSuchEntityException;
import org.apache.clerezza.rdf.core.access.WeightedTcProvider;
-import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
Modified: stanbol/trunk/contenthub/store/solr/pom.xml
URL: http://svn.apache.org/viewvc/stanbol/trunk/contenthub/store/solr/pom.xml?rev=1399247&r1=1399246&r2=1399247&view=diff
==============================================================================
--- stanbol/trunk/contenthub/store/solr/pom.xml (original)
+++ stanbol/trunk/contenthub/store/solr/pom.xml Wed Oct 17 13:38:50 2012
@@ -37,6 +37,19 @@
<extensions>true</extensions>
<configuration>
<instructions>
+ <Import-Package>
+ org.apache.stanbol.enhancer.servicesapi; provide:=true,
+ org.apache.stanbol.enhancer.servicesapi.impl; provide:=true,
+ org.apache.stanbol.contenthub.servicesapi.store.solr; provide:=true,
+ *
+ </Import-Package>
+ <Export-Package>
+ org.apache.stanbol.contenthub.store.solr.manager;version=${project.version},
+ org.apache.stanbol.contenthub.store.solr.util;version=${project.version}
+ </Export-Package>
+ <Private-Package>
+ org.apache.stanbol.contenthub.store.solr
+ </Private-Package>
<!-- We need to provide the default SolrYard indexConfigurations
to the DataFileProvider infrastructure -->
<Data-Files>
Modified: stanbol/trunk/contenthub/store/solr/src/main/java/org/apache/stanbol/contenthub/store/solr/SolrContentItemImpl.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/contenthub/store/solr/src/main/java/org/apache/stanbol/contenthub/store/solr/SolrContentItemImpl.java?rev=1399247&r1=1399246&r2=1399247&view=diff
==============================================================================
--- stanbol/trunk/contenthub/store/solr/src/main/java/org/apache/stanbol/contenthub/store/solr/SolrContentItemImpl.java (original)
+++ stanbol/trunk/contenthub/store/solr/src/main/java/org/apache/stanbol/contenthub/store/solr/SolrContentItemImpl.java Wed Oct 17 13:38:50 2012
@@ -25,7 +25,6 @@ import java.util.Map;
import org.apache.clerezza.rdf.core.MGraph;
import org.apache.clerezza.rdf.core.UriRef;
-import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
import org.apache.stanbol.commons.indexedgraph.IndexedMGraph;
import org.apache.stanbol.contenthub.servicesapi.store.solr.SolrContentItem;
import org.apache.stanbol.contenthub.store.solr.util.ContentItemIDOrganizer;
Modified: stanbol/trunk/contenthub/web/pom.xml
URL: http://svn.apache.org/viewvc/stanbol/trunk/contenthub/web/pom.xml?rev=1399247&r1=1399246&r2=1399247&view=diff
==============================================================================
--- stanbol/trunk/contenthub/web/pom.xml (original)
+++ stanbol/trunk/contenthub/web/pom.xml Wed Oct 17 13:38:50 2012
@@ -55,8 +55,12 @@
<instructions>
<Import-Package>
javax.ws.rs.*; version="[0,2)",
+ org.apache.stanbol.commons.web.base; provide:=true,
*
</Import-Package>
+ <Export-Package>
+ org.apache.stanbol.contenthub.web.*;version=${project.version},
+ </Export-Package>
</instructions>
</configuration>
</plugin>
@@ -102,18 +106,18 @@
<dependency>
<groupId>org.apache.stanbol</groupId>
<artifactId>org.apache.stanbol.contenthub.servicesapi</artifactId>
- <version>0.9.0-incubating</version>
+ <version>0.10.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.stanbol</groupId>
<artifactId>org.apache.stanbol.contenthub.store.solr</artifactId>
<version>0.9.0-incubating</version>
</dependency>
- <dependency>
+ <!-- dependency>
<groupId>org.apache.stanbol</groupId>
<artifactId>org.apache.stanbol.contenthub.search.solr</artifactId>
<version>0.10.0-SNAPSHOT</version>
- </dependency>
+ </dependency -->
<dependency>
<groupId>org.apache.stanbol</groupId>
<artifactId>org.apache.stanbol.contenthub.search.featured</artifactId>