You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by su...@apache.org on 2012/07/19 16:06:33 UTC
svn commit: r1363343 [3/4] - in
/incubator/stanbol/branches/contenthub-two-layered-structure/contenthub: ./
bundlelist/src/main/bundles/ index/ index/src/main/java/org/
index/src/main/java/org/apache/ index/src/main/java/org/apache/stanbol/
index/src/m...
Copied: incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/servicesapi/src/main/java/org/apache/stanbol/contenthub/servicesapi/index/IndexManagementException.java (from r1352861, incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/servicesapi/src/main/java/org/apache/stanbol/contenthub/servicesapi/index/ldpath/LDPathException.java)
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/servicesapi/src/main/java/org/apache/stanbol/contenthub/servicesapi/index/IndexManagementException.java?p2=incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/servicesapi/src/main/java/org/apache/stanbol/contenthub/servicesapi/index/IndexManagementException.java&p1=incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/servicesapi/src/main/java/org/apache/stanbol/contenthub/servicesapi/index/ldpath/LDPathException.java&r1=1352861&r2=1363343&rev=1363343&view=diff
==============================================================================
--- incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/servicesapi/src/main/java/org/apache/stanbol/contenthub/servicesapi/index/ldpath/LDPathException.java (original)
+++ incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/servicesapi/src/main/java/org/apache/stanbol/contenthub/servicesapi/index/IndexManagementException.java Thu Jul 19 14:06:30 2012
@@ -14,31 +14,32 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.stanbol.contenthub.servicesapi.index.ldpath;
+package org.apache.stanbol.contenthub.servicesapi.index;
import org.apache.stanbol.contenthub.servicesapi.exception.ContenthubException;
/**
- * Exception to be thrown in LDPath related operations of Contenthub.
+ * Exception to be thrown in unexpected situations which occur during index management issues such as index
+ * creation, retrieval, deletion, etc.
*
- * @author anil.sinaci
+ * @author suat
*
*/
-public class LDPathException extends ContenthubException {
+public class IndexManagementException extends ContenthubException {
private static final long serialVersionUID = 4755524861924506181L;
/**
* @param msg
*/
- public LDPathException(String msg) {
+ public IndexManagementException(String msg) {
super(msg);
}
/**
* @param cause
*/
- public LDPathException(Throwable cause) {
+ public IndexManagementException(Throwable cause) {
super(cause);
}
@@ -46,7 +47,7 @@ public class LDPathException extends Con
* @param msg
* @param cause
*/
- public LDPathException(String msg, Throwable cause) {
+ public IndexManagementException(String msg, Throwable cause) {
super(msg, cause);
}
Modified: incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/servicesapi/src/main/java/org/apache/stanbol/contenthub/servicesapi/index/IndexState.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/servicesapi/src/main/java/org/apache/stanbol/contenthub/servicesapi/index/IndexState.java?rev=1363343&r1=1363342&r2=1363343&view=diff
==============================================================================
--- incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/servicesapi/src/main/java/org/apache/stanbol/contenthub/servicesapi/index/IndexState.java (original)
+++ incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/servicesapi/src/main/java/org/apache/stanbol/contenthub/servicesapi/index/IndexState.java Thu Jul 19 14:06:30 2012
@@ -1,18 +1,40 @@
package org.apache.stanbol.contenthub.servicesapi.index;
+/**
+ * This enumeration defines the possible states for a {@link SemanticIndex}.
+ */
public enum IndexState {
+ /**
+ * The index was defined, the configuration is ok, but the contents are not yet indexed and the indexing
+ * has not yet started. (Intended to be used as default state after creations)
+ */
UNINIT,
+ /**
+ * The indexing of content items is currently in progress. This indicates that the index is currently NOT
+ * active.
+ */
INDEXING,
+ /**
+ * The semantic index is available and in sync
+ */
ACTIVE,
+ /**
+ * The (re)-indexing of content times is currently in progress. This indicates that the configuration of
+ * the semantic index was changed in a way that requires to rebuild the whole semantic index. This still
+ * requires the index to be active - meaning the searches can be performed normally - but recent
+ * updates/changes to ContentItems might not be reflected. This also indicates that the index will be
+ * replaced by a different version (maybe with changed fields) in the near future.
+ */
REINDEXING;
-
+
private static final String prefix = "http://stanbol.apache.org/ontology/contenthub#indexState_";
-
+
public String getUri() {
- return prefix+name().toLowerCase();
- }
+ return prefix + name().toLowerCase();
+ }
+
@Override
public String toString() {
- return getUri();
+ return getUri();
}
}
Modified: incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/servicesapi/src/main/java/org/apache/stanbol/contenthub/servicesapi/index/SemanticIndex.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/servicesapi/src/main/java/org/apache/stanbol/contenthub/servicesapi/index/SemanticIndex.java?rev=1363343&r1=1363342&r2=1363343&view=diff
==============================================================================
--- incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/servicesapi/src/main/java/org/apache/stanbol/contenthub/servicesapi/index/SemanticIndex.java (original)
+++ incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/servicesapi/src/main/java/org/apache/stanbol/contenthub/servicesapi/index/SemanticIndex.java Thu Jul 19 14:06:30 2012
@@ -4,104 +4,140 @@ import java.util.List;
import java.util.Map;
import org.apache.clerezza.rdf.core.UriRef;
-import org.apache.felix.scr.annotations.Component;
import org.apache.stanbol.contenthub.servicesapi.store.ChangeSet;
import org.apache.stanbol.enhancer.servicesapi.ContentItem;
import org.osgi.framework.Constants;
import org.osgi.framework.ServiceReference;
public interface SemanticIndex {
-
- String PARAMETER_NAME = "stanbol.contenthub.index.name";
- String PARAMETER_DESCRIPTION = "stanbol.contenthub.index.description";
-
- /**
- * The name of the Semantic Index. The same as configured by the
- * {@link #PARAMETER_NAME} property in the OSGI component configuration
- * @return the name;
- */
+ /**
+ * Name property for a SemanticIndex
+ */
+ public static final String PROP_NAME = "Semantic-Index-Name";
+
+ /**
+ * Description property for a SemanticIndex
+ */
+ public static final String PROP_DESCRIPTION = "Semantic-Index-Description";
+
+ /**
+ * Revision property for a Semantic Index. With this property, the last persisted revision of a Semantic
+ * Index is indicated.
+ */
+ public static final String PROP_REVISION = "Semantic-Index-Revision";
+
+ /**
+ * State property for a Semantic Index
+ */
+ public static final String PROP_STATE = "Semantic-Index-State";
+
+ /**
+ * The name of the Semantic Index. The same as configured by the {@link #PROP_NAME} property in the OSGI
+ * component configuration
+ *
+ * @return the name;
+ */
String getName();
-
- /**
- * The description for the Semantic Index. The same as configured by the
- * {@link #PARAMETER_DESCRIPTION} property in the OSGI component configuration
- * @return the name;
- */
+
+ /**
+ * The description for the Semantic Index. The same as configured by the {@link #PROP_DESCRIPTION}
+ * property in the OSGI component configuration
+ *
+ * @return the name;
+ */
String getDescription();
+
+ /**
+ * The state of the semantic index
+ */
+ IndexState getState();
+
/**
* Indexes the parsed ContentItem
- * @param ci the contentItem
+ *
+ * @param ci
+ * the contentItem
* @return <code>true</true> if the ConentItem was included in the index.
- * <code>false</code> if the ContentItem was ignored (e.g. filtered based
- * on the indexing rules).
- * @throws IndexException On any error while accessing the semantic index
+ * <code>false</code> if the ContentItem was ignored (e.g. filtered based on the indexing rules).
+ * @throws IndexException
+ * On any error while accessing the semantic index
*/
boolean index(ContentItem ci) throws IndexException;
+
/**
- * Removes the {@link ContentItem} with the parsed {@link UriRef} from
- * this index. If the no content item with the parsed uri is
- * present in this index the call can be ignored.
- * @param ciURI the uri of the content item to remove
- * @throws IndexException On any error while accessing the semantic index
+ * Removes the {@link ContentItem} with the parsed {@link UriRef} from this index. If the no content item
+ * with the parsed uri is present in this index the call can be ignored.
+ *
+ * @param ciURI
+ * the uri of the content item to remove
+ * @throws IndexException
+ * On any error while accessing the semantic index
*/
void remove(UriRef ciURI) throws IndexException;
+
/**
- * Persists all changes to the index and sets the revision to the parsed
- * value if the operation succeeds.
+ * Persists all changes to the index and sets the revision to the parsed value if the operation succeeds.
* <p>
- * TODO: The {@link ChangeSet} interface does NOT provide revisions for
- * each changed ContentItem but only for the whole Set. So this means that
- * this method can only be called after indexing the whole {@link ChangeSet}.
- * This might be OK, but needs further investigation (rwesten)
+ * TODO: The {@link ChangeSet} interface does NOT provide revisions for each changed ContentItem but only
+ * for the whole Set. So this means that this method can only be called after indexing the whole
+ * {@link ChangeSet}. This might be OK, but needs further investigation (rwesten)
*
- * @param revision the revision
- * @throws IndexException On any error while accessing the semantic index
+ * @param revision
+ * the revision
+ * @throws IndexException
+ * On any error while accessing the semantic index
*/
void persist(long revision) throws IndexException;
+
/**
* Getter for the current revision of this SemanticIndex
+ *
* @return the revision number or {@link Long#MIN_VALUE} if none.
*/
long getRevision();
+
/**
- * Getter for the list of fields supported by this semantic index. This
- * information is optional. Implementations that does not support this
- * can indicate that by returning <code>null</code>.
+ * Getter for the list of fields supported by this semantic index. This information is optional.
+ * Implementations that does not support this can indicate that by returning <code>null</code>.
+ *
* @return the list of filed names or <code>null</code> if not available
+ * @throws IndexException
*/
- List<String> getFieldsNames();
+ List<String> getFieldsNames() throws IndexException;
+
/**
- * Getter for the properties describing a specific field supported by
- * this index. Names can be retrieved by using {@link #getFieldsNames()}.
- * This information is optional. Implementations that do not support this
- * can indicate this by returning <code>null</code>.<p>
- * The keys of the returned map represent the properties. Values the
- * actual configuration of the property.
- * @param name the field name
+ * Getter for the properties describing a specific field supported by this index. Names can be retrieved
+ * by using {@link #getFieldsNames()}. This information is optional. Implementations that do not support
+ * this can indicate this by returning <code>null</code>.
+ * <p>
+ * The keys of the returned map represent the properties. Values the actual configuration of the property.
+ *
+ * @param name
+ * the field name
* @return the field properties or <code>null</code> if not available.
+ * @throws IndexException
*/
- Map<String,Object> getFieldProperties(String name);
-
+ Map<String,Object> getFieldProperties(String name) throws IndexException;
+
/**
- * Getter for the RESTful search interfaces supported by this semantic index.
- * The keys represent the types of the RESTful Interfaces. See
- * the {@link EndpointType} enumeration for knows keys. The
- * value is the URL of that service relative to to the Stanbol
- * base URI
+ * Getter for the RESTful search interfaces supported by this semantic index. The keys represent the types
+ * of the RESTful Interfaces. See the {@link EndpointType} enumeration for knows keys. The value is the
+ * URL of that service relative to to the Stanbol base URI
+ *
* @return the RESTful search interfaces supported by this semantic index.
*/
- Map<String, String> getRESTSearchEndpoints();
+ Map<EndpointType,String> getRESTSearchEndpoints();
+
/**
- * Getter for the Java search APIs supported by this semantic index.
- * The keys are the java interfaces and values are OSGI
- * {@link ServiceReference}s. This also means that instead of
- * using this method such components can be accesses by using a
- * filter on <ul>
- * <li>{@link #PARAMETER_NAME} = {@link #getName()}
+ * Getter for the Java search APIs supported by this semantic index. The keys are the java interfaces and
+ * values are OSGI {@link ServiceReference}s. This also means that instead of using this method such
+ * components can be accesses by using a filter on
+ * <ul>
+ * <li>{@link #PROP_NAME} = {@link #getName()}
* <li> {@link Constants#OBJECTCLASS} = {@link Class#getName()}
* </ul>
- * @return the Java search APIs supported by this semantic index.
- * Also registered as OSGI services.
+ *
+ * @return the Java search APIs supported by this semantic index. Also registered as OSGI services.
*/
- Map<Class<?>, ServiceReference> getSearchEndPoints();
+ Map<Class<?>,ServiceReference> getSearchEndPoints();
}
Modified: incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/servicesapi/src/main/java/org/apache/stanbol/contenthub/servicesapi/index/SemanticIndexManager.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/servicesapi/src/main/java/org/apache/stanbol/contenthub/servicesapi/index/SemanticIndexManager.java?rev=1363343&r1=1363342&r2=1363343&view=diff
==============================================================================
--- incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/servicesapi/src/main/java/org/apache/stanbol/contenthub/servicesapi/index/SemanticIndexManager.java (original)
+++ incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/servicesapi/src/main/java/org/apache/stanbol/contenthub/servicesapi/index/SemanticIndexManager.java Thu Jul 19 14:06:30 2012
@@ -16,46 +16,84 @@
*/
package org.apache.stanbol.contenthub.servicesapi.index;
-import java.io.Reader;
-import java.util.Collection;
import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import org.apache.stanbol.contenthub.servicesapi.index.ldpath.LDPathException;
-import org.apache.stanbol.contenthub.servicesapi.index.ldpath.LDPathProgramCollection;
-
-import at.newmedialab.ldpath.model.programs.Program;
+import org.osgi.framework.Constants;
+/**
+ * Provides methods to access to managed {@link SemanticIndex}es by different means such name,
+ * {@link EndpointType} or both.
+ *
+ */
public interface SemanticIndexManager {
- SemanticIndex getIndex(String name);
-
- List<SemanticIndex> getIndexes(String name);
-
- SemanticIndex getIndex(EndpointType endpointType);
-
- List<SemanticIndex> getIndexes(EndpointType endpointType);
-
- SemanticIndex getIndex(String name, EndpointType endpointType);
-
- List<SemanticIndex> getIndexes(String name, EndpointType endpointType);
-
- String getProgramByName(String programName);
-
- Program<Object> getParsedProgramByName(String programName);
-
- void deleteProgram(String programName);
-
- boolean isManagedProgram(String programName);
-
- void submitProgram(String programName, String ldPathProgram)
- throws LDPathException;
-
- void submitProgram(String programName, Reader ldPathProgramReader)
- throws LDPathException;
-
- LDPathProgramCollection retrieveAllPrograms();
-
- Map<String, Collection<?>> executeProgram(String programName,
- Set<String> contexts) throws LDPathException;
+ /**
+ * Retrieves the {@link SemanticIndex} instance with the given name and having highest
+ * {@link Constants#SERVICE_RANKING} value.
+ *
+ * @param name
+ * Name of the {@link SemanticIndex} to be retrieved
+ * @return the {@link SemanticIndex} instance with the given name if there is any, otherwise {@code null}
+ * @throws IndexManagementException
+ */
+ SemanticIndex getIndex(String name) throws IndexManagementException;
+
+ /**
+ * Retrieves the {@link SemanticIndex} instances with the given name.
+ *
+ * @param name
+ * Name of the {@link SemanticIndex}es to be retrieved
+ * @return the {@link SemanticIndex}es with the given name if there is any, otherwise an empty list
+ * @throws IndexManagementException
+ */
+ List<SemanticIndex> getIndexes(String name) throws IndexManagementException;
+
+ /**
+ * Retrieves the {@link SemanticIndex} instance with the given {@link EndpointType} and having highest
+ * {@link Constants#SERVICE_RANKING} value.
+ *
+ * @param endpointType
+ * REST {@link EndpointType} of the {@link SemanticIndex} to be retrieved
+ * @return the {@link SemanticIndex} instance with the given {@link EndpointType} if there is any,
+ * otherwise {@code null}
+ * @throws IndexManagementException
+ */
+ SemanticIndex getIndex(EndpointType endpointType) throws IndexManagementException;
+
+ /**
+ * Retrieves the {@link SemanticIndex}es with the given {@link EndpointType}.
+ *
+ * @param endpointType
+ * REST {@link EndpointType} of the {@link SemanticIndex}es to be retrieved
+ * @return the {@link SemanticIndex}es instances with the given {@link EndpointType} if there is any,
+ * otherwise an empty list
+ * @throws IndexManagementException
+ */
+ List<SemanticIndex> getIndexes(EndpointType endpointType) throws IndexManagementException;
+
+ /**
+ * Retrieves the {@link SemanticIndex} instance with the given name, {@link EndpointType} and highest
+ * {@link Constants#SERVICE_RANKING} value.
+ *
+ * @param name
+ * Name of the {@link SemanticIndex}es to be retrieved
+ * @param endpointType
+ * REST {@link EndpointType} of the {@link SemanticIndex} to be retrieved
+ * @return the {@link SemanticIndex} instance with the given name, {@link EndpointType} if there is any,
+ * otherwise {@code null}
+ * @throws IndexManagementException
+ */
+ SemanticIndex getIndex(String name, EndpointType endpointType) throws IndexManagementException;
+
+ /**
+ * Retrieves the {@link SemanticIndex}es instance with the given name and {@link EndpointType}.
+ *
+ * @param name
+ * Name of the {@link SemanticIndex}es to be retrieved
+ * @param endpointType
+ * REST {@link EndpointType} of the {@link SemanticIndex} to be retrieved
+ * @return the {@link SemanticIndex} instance with the given name and {@link EndpointType} if there is
+ * any, otherwise an empty list
+ * @throws IndexManagementException
+ */
+ List<SemanticIndex> getIndexes(String name, EndpointType endpointType) throws IndexManagementException;
}
Modified: incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/servicesapi/src/main/java/org/apache/stanbol/contenthub/servicesapi/index/search/featured/FeaturedSearch.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/servicesapi/src/main/java/org/apache/stanbol/contenthub/servicesapi/index/search/featured/FeaturedSearch.java?rev=1363343&r1=1363342&r2=1363343&view=diff
==============================================================================
--- incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/servicesapi/src/main/java/org/apache/stanbol/contenthub/servicesapi/index/search/featured/FeaturedSearch.java (original)
+++ incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/servicesapi/src/main/java/org/apache/stanbol/contenthub/servicesapi/index/search/featured/FeaturedSearch.java Thu Jul 19 14:06:30 2012
@@ -19,6 +19,7 @@ package org.apache.stanbol.contenthub.se
import java.util.List;
import org.apache.solr.common.params.SolrParams;
+import org.apache.stanbol.contenthub.servicesapi.index.IndexManagementException;
import org.apache.stanbol.contenthub.servicesapi.index.search.SearchException;
import org.apache.stanbol.contenthub.servicesapi.index.search.related.RelatedKeywordSearch;
import org.apache.stanbol.contenthub.servicesapi.index.search.solr.SolrSearch;
@@ -38,23 +39,6 @@ public interface FeaturedSearch {
/**
* This method returns a {@link SearchResult} as a unified search response. The response contains content
- * items retrieved from the default index of Contenthub for the given <code>queryTerm</code>. It also
- * consists of related keywords which are obtained from the available {@link RelatedKeywordSearch}
- * instances. To obtain related keywords, the given query term is tokenized with
- * {@link #tokenizeEntities(String)}. And then, related keyword searchers are queried for all the query
- * tokens. Furthermore, the {@link SearchResult} includes Solr facets that are obtained for the obtained
- * content items.
- *
- * @param queryTerm
- * Query term for which the unified response will be obtained
- * @return {@link SearchResult} for the given query term. For details of the response see
- * {@link SearchResult}.
- * @throws SearchException
- */
- SearchResult search(String queryTerm) throws SearchException;
-
- /**
- * This method returns a {@link SearchResult} as a unified search response. The response contains content
* items retrieved from the index, which is accessed using the given <code>indexName</code>, of Contenthub
* for the given <code>queryTerm</code>. This name corresponds to a Solr Core name within Contenthub. It
* also consists of related keywords that are obtained from the available {@link RelatedKeywordSearch}
@@ -69,8 +53,8 @@ public interface FeaturedSearch {
* @param ontologyURI
* URI of an ontology in which related keywords will be searched
* @param indexName
- * LDPath program name (name of the Solr core/index) which is used to obtained the
- * corresponding Solr core which will be searched for the given query term
+ * Name of the Solr core/index which is used to obtained the corresponding Solr core which will
+ * be searched for the given query term
* @return {@link SearchResult} for the given query term. For details of the response see
* {@link SearchResult}.
* @throws SearchException
@@ -79,35 +63,22 @@ public interface FeaturedSearch {
/**
* This methods returns a {@link SearchResult} as a unified search response. The response contains content
- * items retrieved from the default index of Contenthub after executing the given <code>solrQuery</code>.
- * It also consists of related keywords that are obtained from the available {@link RelatedKeywordSearch}
- * instances. To obtain related keywords, first the meaningful query terms are extracted from the Solr
- * query and then they are tokenized with {@link #tokenizeEntities(String)}. And then, related keyword
- * searchers are queried for all the query tokens. Furthermore, the {@link SearchResult} includes Solr
- * facets that are obtained for the obtained content items.
- *
- * @param solrQuery
- * for which the search results will be obtained
- * @return a unified response in a {@link SearchResult} containing actual content items, related keywords
- * and facets for the obtained content items.
- * @throws SearchException
- */
- SearchResult search(SolrParams solrQuery) throws SearchException;
-
- /**
- * This methods returns a {@link SearchResult} as a unified search response. The response contains content
- * items retrieved from the index, which is accessed using the given <code>indexName</code>, of
- * Contenthub for the given <code>queryTerm</code>. This name corresponds to a Solr Core name within
- * Contenthub. It also consists of related keywords that are obtained from the available
- * {@link RelatedKeywordSearch} instances. This method also takes an ontology URI. Using the URI, actual
- * ontology is obtained and it is used as related keyword source. To obtain related keywords, first the
- * meaningful query terms are extracted from the Solr query and then they are tokenized with
- * {@link #tokenizeEntities(String)}. And then, related keyword searchers are queried for all the query
- * tokens. Furthermore, the {@link SearchResult} includes Solr facets that are obtained for the obtained
- * content items.
+ * items retrieved from the index, which is accessed using the given <code>indexName</code>, of Contenthub
+ * for the given <code>queryTerm</code>. This name corresponds to a Solr Core name within Contenthub. It
+ * also consists of related keywords that are obtained from the available {@link RelatedKeywordSearch}
+ * instances. This method also takes an ontology URI. Using the URI, actual ontology is obtained and it is
+ * used as related keyword source. To obtain related keywords, first the meaningful query terms are
+ * extracted from the Solr query and then they are tokenized with {@link #tokenizeEntities(String)}. And
+ * then, related keyword searchers are queried for all the query tokens. Furthermore, the
+ * {@link SearchResult} includes Solr facets that are obtained for the obtained content items.
*
* @param solrQuery
* for which the search results will be obtained
+ * @param ontologyURI
+ * URI of an ontology in which related keywords will be searched
+ * @param indexName
+ * Name of the Solr core/index which is used to obtained the corresponding Solr core which will
+ * be searched for the given solrQuery
* @return a unified response in a {@link SearchResult} containing actual content items, related keywords
* and facets for the obtained content items.
* @throws SearchException
@@ -115,14 +86,6 @@ public interface FeaturedSearch {
SearchResult search(SolrParams solrQuery, String ontologyURI, String indexName) throws SearchException;
/**
- * This method obtains the available field names of the default index of Contenthub.
- *
- * @return {@link List} of field names related index
- * @throws SearchException
- */
- List<FacetResult> getAllFacetResults() throws SearchException;
-
- /**
* This method obtains the available field names of the index, corresponding to the given
* <code>indexName</code> of Contenthub. This name corresponds to a Solr Core name within Contenthub.
*
@@ -130,6 +93,7 @@ public interface FeaturedSearch {
* Name of the index for which the field names will be obtained.
* @return {@link List} of field names related index
* @throws SearchException
+ * @throws IndexManagementException
*/
List<FacetResult> getAllFacetResults(String indexName) throws SearchException;
Modified: incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/servicesapi/src/main/java/org/apache/stanbol/contenthub/servicesapi/index/search/featured/SearchResult.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/servicesapi/src/main/java/org/apache/stanbol/contenthub/servicesapi/index/search/featured/SearchResult.java?rev=1363343&r1=1363342&r2=1363343&view=diff
==============================================================================
--- incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/servicesapi/src/main/java/org/apache/stanbol/contenthub/servicesapi/index/search/featured/SearchResult.java (original)
+++ incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/servicesapi/src/main/java/org/apache/stanbol/contenthub/servicesapi/index/search/featured/SearchResult.java Thu Jul 19 14:06:30 2012
@@ -44,7 +44,7 @@ public interface SearchResult {
*
* @return {@link List} of {@link DocumentResult} encapsulated in this search result
*/
- List<DocumentResult> getDocuments();
+ List<String> getDocuments();
/**
* Returns the facets generated as a result of the search operations. Each search result has its own
@@ -69,7 +69,7 @@ public interface SearchResult {
*
* @param documentResults
*/
- void setDocuments(List<DocumentResult> documentResults);
+ void setDocuments(List<String> documentResults);
/**
* Setter for the facets list
Modified: incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/servicesapi/src/main/java/org/apache/stanbol/contenthub/servicesapi/index/search/solr/SolrSearch.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/servicesapi/src/main/java/org/apache/stanbol/contenthub/servicesapi/index/search/solr/SolrSearch.java?rev=1363343&r1=1363342&r2=1363343&view=diff
==============================================================================
--- incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/servicesapi/src/main/java/org/apache/stanbol/contenthub/servicesapi/index/search/solr/SolrSearch.java (original)
+++ incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/servicesapi/src/main/java/org/apache/stanbol/contenthub/servicesapi/index/search/solr/SolrSearch.java Thu Jul 19 14:06:30 2012
@@ -33,23 +33,13 @@ import org.apache.stanbol.contenthub.ser
public interface SolrSearch {
/**
- * Queries the default Solr core of Contenthub with the given <code>queryTerm</code>.
- *
- * @param queryTerm
- * Query term to be searched
- * @return the {@link QueryResponse} as is obtained from Solr.
- * @throws SearchException
- */
- QueryResponse search(String queryTerm) throws SearchException;
-
- /**
* Queries the Solr core corresponding to the given <code>ldProgramName</code> of Contenthub with the
* given <code>queryTerm</code>.
*
* @param queryTerm
* Query term to be searched
* @param indexName
- * LDPath program name (Solr core/index name) to obtain the corresponding Solr core to be
+ * Index(Solr core) name to obtain the corresponding Solr core to be
* searched
* @return the {@link QueryResponse} as is obtained from Solr.
* @throws SearchException
@@ -57,16 +47,6 @@ public interface SolrSearch {
QueryResponse search(String queryTerm, String indexName) throws SearchException;
/**
- * Executes the given <code>solrQuery</code> on the default Solr core of Contenthub.
- *
- * @param solrQuery
- * {@link SolrParams} to be executed
- * @return the {@link QueryResponse} as is obtained from Solr.
- * @throws SearchException
- */
- QueryResponse search(SolrParams solrQuery) throws SearchException;
-
- /**
* Executes the given <code>solrQuery</code> on the Solr core corresponding to the given
* <code>ldProgramName</code> of Contenthub.
*
Modified: incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/servicesapi/src/main/java/org/apache/stanbol/contenthub/servicesapi/store/ChangeSet.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/servicesapi/src/main/java/org/apache/stanbol/contenthub/servicesapi/store/ChangeSet.java?rev=1363343&r1=1363342&r2=1363343&view=diff
==============================================================================
--- incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/servicesapi/src/main/java/org/apache/stanbol/contenthub/servicesapi/store/ChangeSet.java (original)
+++ incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/servicesapi/src/main/java/org/apache/stanbol/contenthub/servicesapi/store/ChangeSet.java Thu Jul 19 14:06:30 2012
@@ -15,10 +15,9 @@ import org.apache.clerezza.rdf.core.UriR
* SemanticIndex index; //the index to apply the changes
* long revision = Long.MIN_VALUE; //start from scratch
* int batchSize = 1000;
- * int offset = 0;
* ChangeSet cs;
* do {
- * cs = store.changes(revision, offset, batchSize);
+ * cs = store.changes(revision, batchSize);
* for(UriRef changed : cs.changed()){
* ContentItem ci = store.get(changed);
* if(ci == null){
@@ -27,7 +26,6 @@ import org.apache.clerezza.rdf.core.UriR
* index.index(ci);
* }
* }
- * offset+=cs.changed().size();
* while(!cs.changed().isEmpty());
* index.persist(cs.fromRevision());
* </pre></code>
Modified: incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/servicesapi/src/main/java/org/apache/stanbol/contenthub/servicesapi/store/vocabulary/SolrVocabulary.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/servicesapi/src/main/java/org/apache/stanbol/contenthub/servicesapi/store/vocabulary/SolrVocabulary.java?rev=1363343&r1=1363342&r2=1363343&view=diff
==============================================================================
--- incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/servicesapi/src/main/java/org/apache/stanbol/contenthub/servicesapi/store/vocabulary/SolrVocabulary.java (original)
+++ incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/servicesapi/src/main/java/org/apache/stanbol/contenthub/servicesapi/store/vocabulary/SolrVocabulary.java Thu Jul 19 14:06:30 2012
@@ -30,7 +30,7 @@ import java.util.List;
*/
public class SolrVocabulary {
- public static final String STANBOLRESERVED_PREFIX = "stanbolreserved_";
+ public static final String STANBOLRESERVED_PREFIX = "contenthubreserved_";
public enum SolrFieldName {
@@ -55,6 +55,16 @@ public class SolrVocabulary {
ID(STANBOLRESERVED_PREFIX + "id"),
/**
+ * Revision of index
+ */
+ REVISION(STANBOLRESERVED_PREFIX + "revision"),
+
+ /**
+ * ID field of revision document to be kept in solr
+ */
+ REVISIONID(STANBOLRESERVED_PREFIX + "contenthub_ldpath_semantic_index_revision_id"),
+
+ /**
* Name of the field which holds the title of the content.
*/
TITLE(STANBOLRESERVED_PREFIX + "title"),
Modified: incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/store/file/src/main/java/org/apache/stanbol/contenthub/store/file/FileStore.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/store/file/src/main/java/org/apache/stanbol/contenthub/store/file/FileStore.java?rev=1363343&r1=1363342&r2=1363343&view=diff
==============================================================================
--- incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/store/file/src/main/java/org/apache/stanbol/contenthub/store/file/FileStore.java (original)
+++ incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/store/file/src/main/java/org/apache/stanbol/contenthub/store/file/FileStore.java Thu Jul 19 14:06:30 2012
@@ -118,7 +118,9 @@ public class FileStore implements Store
public static final String FIELD_TITLE = "title";
public static final String FIELD_ID = "id";
-
+
+ public static final String FILE_STORE_FOLDER_PATH = "datafiles/contenthub";
+
public static final String FILE_STORE_NAME = "filestore";
private static final String SELECT_RECENTLY_ENHANCED_ITEMS = "SELECT t1.id, mimeType, enhancementCount, title FROM "
@@ -176,7 +178,7 @@ public class FileStore implements Store
protected void activate(ComponentContext componentContext) throws StoreException {
// check store folder
String stanbolHome = componentContext.getBundleContext().getProperty("sling.home");
- storeFolder = new File(stanbolHome + "/" + FILE_STORE_NAME);
+ storeFolder = new File(stanbolHome + "/" + FILE_STORE_FOLDER_PATH + "/" + FILE_STORE_NAME);
if (!storeFolder.exists()) {
storeFolder.mkdirs();
}
Modified: incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/store/file/src/main/java/org/apache/stanbol/contenthub/store/file/FileStoreDBManager.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/store/file/src/main/java/org/apache/stanbol/contenthub/store/file/FileStoreDBManager.java?rev=1363343&r1=1363342&r2=1363343&view=diff
==============================================================================
--- incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/store/file/src/main/java/org/apache/stanbol/contenthub/store/file/FileStoreDBManager.java (original)
+++ incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/store/file/src/main/java/org/apache/stanbol/contenthub/store/file/FileStoreDBManager.java Thu Jul 19 14:06:30 2012
@@ -72,7 +72,7 @@ public class FileStoreDBManager {
@Activate
protected void activate(ComponentContext componentContext) throws StoreException {
String stanbolHome = componentContext.getBundleContext().getProperty("sling.home");
- DB_URL = "jdbc:derby:" + stanbolHome + "/filestore/filestorerevisions;create=true";
+ DB_URL = "jdbc:derby:" + stanbolHome + "/datafiles/contenthub/filestore/filestorerevisions;create=true";
log.info("Initializing file store revision database");
Connection con = getConnection();
Statement stmt = null;
Modified: incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/test/pom.xml
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/test/pom.xml?rev=1363343&r1=1363342&r2=1363343&view=diff
==============================================================================
--- incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/test/pom.xml (original)
+++ incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/test/pom.xml Thu Jul 19 14:06:30 2012
@@ -54,10 +54,9 @@
</dependency>
<dependency>
<groupId>org.apache.stanbol</groupId>
- <artifactId>org.apache.stanbol.contenthub.store.file</artifactId>
+ <artifactId>org.apache.stanbol.contenthub.index</artifactId>
<version>0.10.0-incubating-SNAPSHOT</version>
</dependency>
-
<dependency>
<groupId>org.apache.clerezza</groupId>
<artifactId>rdf.core</artifactId>
Added: incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/test/src/main/java/org/apache/stanbol/contenthub/test/index/ldpath/LDPathSemanticIndexTest.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/test/src/main/java/org/apache/stanbol/contenthub/test/index/ldpath/LDPathSemanticIndexTest.java?rev=1363343&view=auto
==============================================================================
--- incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/test/src/main/java/org/apache/stanbol/contenthub/test/index/ldpath/LDPathSemanticIndexTest.java (added)
+++ incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/test/src/main/java/org/apache/stanbol/contenthub/test/index/ldpath/LDPathSemanticIndexTest.java Thu Jul 19 14:06:30 2012
@@ -0,0 +1,283 @@
+package org.apache.stanbol.contenthub.test.index.ldpath;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.lang.reflect.Field;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.sling.junit.annotations.SlingAnnotationsTestRunner;
+import org.apache.sling.junit.annotations.TestReference;
+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.common.SolrDocument;
+import org.apache.solr.common.SolrDocumentList;
+import org.apache.solr.common.SolrInputDocument;
+import org.apache.stanbol.contenthub.index.ldpath.LDPathSemanticIndex;
+import org.apache.stanbol.contenthub.index.ldpath.LDPathSemanticIndexManager;
+import org.apache.stanbol.contenthub.servicesapi.index.IndexException;
+import org.apache.stanbol.contenthub.servicesapi.index.IndexManagementException;
+import org.apache.stanbol.contenthub.servicesapi.index.SemanticIndex;
+import org.apache.stanbol.contenthub.servicesapi.index.SemanticIndexManager;
+import org.apache.stanbol.contenthub.servicesapi.store.vocabulary.SolrVocabulary.SolrFieldName;
+import org.apache.stanbol.enhancer.servicesapi.ContentItem;
+import org.apache.stanbol.enhancer.servicesapi.ContentItemFactory;
+import org.apache.stanbol.enhancer.servicesapi.impl.StringSource;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@RunWith(SlingAnnotationsTestRunner.class)
+public class LDPathSemanticIndexTest {
+
+ private static Logger logger = LoggerFactory.getLogger(LDPathSemanticIndexTest.class);
+
+ private static final int TESTCOUNT = 12;
+
+ @TestReference
+ private ContentItemFactory contentItemFactory;
+
+ @TestReference
+ private LDPathSemanticIndexManager ldPathSemanticIndexManager;
+
+ @TestReference
+ private SemanticIndexManager semanticIndexManager;
+
+ @TestReference
+ private BundleContext bundleContext;
+
+ private static LDPathSemanticIndex semanticIndex;
+ private static SolrServer solrServer;
+ private static String pid;
+ private static int counter = 0;
+
+ @Before
+ public void before() throws IndexManagementException, IndexException, InterruptedException, IOException {
+ String name = "test_index_name";
+ if (counter == 0) {
+ String program = "@prefix dbp-ont : <http://dbpedia.org/ontology/>; city = dbp-ont:city / rdfs:label :: xsd:string; country = dbp-ont:country / rdfs:label :: xsd:string; ";
+ pid = ldPathSemanticIndexManager.createIndex(name, "test_index_description", program);
+ SemanticIndex tempSemanticIndex = semanticIndexManager.getIndex(name);
+ int timeoutCount = 0;
+ while (tempSemanticIndex == null) {
+ if(timeoutCount == 8) break;
+ Thread.sleep(500);
+ tempSemanticIndex = semanticIndexManager.getIndex(name);
+ timeoutCount++;
+ }
+ semanticIndex = (LDPathSemanticIndex) tempSemanticIndex;
+ solrServer = semanticIndex.getServer();
+ }
+ }
+
+ @Test
+ public void ldPathSemanticIndexTest() {
+ assertNotNull("Expecting LDPathSemanticIndex to be injected by Sling test runner", semanticIndex);
+ assertTrue("Expection LDPathSemanticIndex implementation of SemanticIndex interface",
+ semanticIndex instanceof LDPathSemanticIndex);
+ }
+
+ @Test
+ public void bundleContextTest() {
+ assertNotNull("Expecting BundleContext to be injected by Sling test runner", bundleContext);
+ }
+
+ @Test
+ public void contentItemFactoryTest() {
+ assertNotNull("Expecting ContentItemFactory to be injected by Sling test runner", contentItemFactory);
+ }
+
+ @Test
+ public void ldPathSemanticIndexManagerTest() {
+ assertNotNull("Expecting LDPathSemanticIndexManager to be injected by Sling test runner",
+ ldPathSemanticIndexManager);
+ }
+
+ @Test
+ public void semanticIndexManagerTest() {
+ assertNotNull("Expecting SemanticIndexManager to be injected by Sling test runner",
+ semanticIndexManager);
+ }
+
+ @Test
+ public void testIndex() throws IndexException {
+ String name = semanticIndex.getName();
+ String id = "test_document_id";
+ ContentItem ci;
+ try {
+ ci = contentItemFactory.createContentItem(new UriRef(id), new StringSource(
+ "test_document_content"));
+ } catch (IOException e) {
+ logger.error("Failed to create contentitem");
+ throw new IndexException("Failed to create contentitem");
+ }
+ semanticIndex.index(ci);
+
+ SolrQuery solrQuery = new SolrQuery();
+ solrQuery.setQuery(SolrFieldName.ID.toString() + ":" + id);
+ SolrDocumentList sdl = null;
+ try {
+ sdl = solrServer.query(solrQuery).getResults();
+ } catch (SolrServerException e) {
+ logger.error("Failed to get indexed document from solr for index " + name, e);
+ throw new IndexException("Failed to get indexed document from solr for index " + name, e);
+ }
+ assertTrue("Indexed content item cannot be found", sdl.size() == 1);
+
+ try {
+ solrServer.deleteById(id);
+ solrServer.commit();
+ } catch (SolrServerException e) {
+ logger.error("Failed to remove indexed document from solr for index " + name, e);
+ throw new IndexException("Failed to remove indexed document from solr for index " + name, e);
+ } catch (IOException e) {
+ logger.error("Failed to remove indexed document from solr for index " + name, e);
+ throw new IndexException("Failed to remove indexed document from solr for index " + name, e);
+ }
+ }
+
+ @Test
+ public void testRemove() throws IndexException {
+ String name = semanticIndex.getName();
+ String id = "test_document_id";
+ try {
+ SolrInputDocument doc = new SolrInputDocument();
+ doc.addField(SolrFieldName.ID.toString(), id);
+ doc.addField("title_t", "test_document_title");
+ solrServer.add(doc);
+ solrServer.commit();
+ } catch (SolrServerException e) {
+ logger.error("Test Document cannot be added to Solr Server with name " + name, e);
+ throw new IndexException("Test Document cannot be added to Solr Server with name " + name, e);
+ } catch (IOException e) {
+ logger.error("Test Document cannot be added to Solr Server with name " + name, e);
+ throw new IndexException("Test Document cannot be added to Solr Server with name " + name, e);
+ }
+
+ semanticIndex.remove(new UriRef(id));
+
+ SolrQuery solrQuery = new SolrQuery();
+ solrQuery.setQuery(SolrFieldName.ID.toString() + ":" + id);
+ SolrDocumentList sdl = null;
+ try {
+ sdl = solrServer.query(solrQuery).getResults();
+ } catch (SolrServerException e) {
+ logger.error("Failed to get test document from solr for index " + name, e);
+ throw new IndexException("Failed to get test document from solr for index " + name, e);
+ }
+ assertTrue("Test Document cannot be removed from Index with name " + name, sdl.size() == 0);
+ }
+
+ @Test
+ public void testPersist() throws IndexException {
+ String name = semanticIndex.getName();
+ semanticIndex.persist(3);
+ assertTrue("Revision cannot be persist with given value 3", semanticIndex.getRevision() == 3);
+
+ SolrQuery solrQuery = new SolrQuery();
+ solrQuery.setQuery(SolrFieldName.ID.toString() + ":" + SolrFieldName.REVISIONID.toString());
+ SolrDocumentList sdl = null;
+ try {
+ sdl = solrServer.query(solrQuery).getResults();
+ } catch (SolrServerException e) {
+ logger.error("Failed to get revision from solr for index " + name, e);
+ throw new IndexException("Failed to get revision from solr for index " + name, e);
+ }
+ SolrDocument solrDocument = sdl.get(0);
+ assertTrue("Return value of getRevision() is not match with the revision stored in Solr",
+ (semanticIndex.getRevision() == (Long) solrDocument.getFieldValue(SolrFieldName.REVISION
+ .toString())));
+ }
+
+ @Test
+ public void testGetRevision() throws IndexException {
+ Field field = null;
+ long revision = 0;
+ try {
+ field = semanticIndex.getClass().getDeclaredField("revision");
+ field.setAccessible(true);
+ revision = (Long) field.get(semanticIndex);
+ } catch (SecurityException e) {
+ logger.error("Failed to get private member revision");
+ throw new IndexException("Failed to get private member revision");
+ } catch (NoSuchFieldException e) {
+ logger.error("There is no field with name revision");
+ throw new IndexException("There is no field with name revision");
+ } catch (IllegalArgumentException e) {
+ logger.error("revision field cannot be retrieved from Semantic Index");
+ throw new IndexException("revision field cannot be retrieved from Semantic Index");
+ } catch (IllegalAccessException e) {
+ logger.error("revision field cannot be retrieved from Semantic Index");
+ throw new IndexException("revision field cannot be retrieved from Semantic Index");
+ }
+ assertTrue("Return value of getRevision() is not match with actual revision " + revision,
+ revision == semanticIndex.getRevision());
+ }
+
+ @Test
+ public void testGetFieldsNames() throws IndexException {
+ List<String> fieldNames = semanticIndex.getFieldsNames();
+ assertTrue(String.format("Index must contain %s field", SolrFieldName.ID.toString()),
+ fieldNames.contains(SolrFieldName.ID.toString()));
+ assertTrue("Index must contain city field", fieldNames.contains("city"));
+ assertTrue("Index must contain country field", fieldNames.contains("country"));
+ }
+
+ @Test
+ public void testGetFieldProperties() throws IndexException {
+ Map<String,Object> fieldProperties = semanticIndex.getFieldProperties(SolrFieldName.ID.toString());
+ String type = (String) fieldProperties.get("type");
+ assertNotNull(String.format("Type property must exist in %s field", SolrFieldName.ID.toString()),
+ type);
+ assertTrue(String.format("Type property must be string in %s field", SolrFieldName.ID.toString()),
+ type.equals("string"));
+
+ Boolean required = (Boolean) fieldProperties.get("required");
+ assertNotNull(String.format("required property must exist in %s field", SolrFieldName.ID.toString()),
+ required);
+ assertTrue(String.format("Type property must be string in %s field", SolrFieldName.ID.toString()),
+ required.equals(true));
+ }
+
+ // @Test
+ // public void testGetRESTSearchEndpoints() {
+ // Map<EndpointType,String> searchEndpoints = semanticIndex.getRESTSearchEndpoints();
+ // for(Entry<EndpointType,String> entry : searchEndpoints.entrySet()){
+ // EndpointType endpointType = entry.getKey();
+ // String endpoint = entry.getValue();
+ // }
+ // }
+
+ @Test
+ public void testGetSearchEndPoints() {
+ Map<Class<?>,ServiceReference> searchEndpoints = semanticIndex.getSearchEndPoints();
+ for (Entry<Class<?>,ServiceReference> entry : searchEndpoints.entrySet()) {
+ Class<?> clazz = entry.getKey();
+ ServiceReference serviceReference = entry.getValue();
+ Object service = clazz.cast(bundleContext.getService(serviceReference));
+ assertNotNull(String.format(
+ "Service cannot be retrieved by given %s Class and its Service Reference", clazz.getName()),
+ service);
+ }
+
+ }
+
+ @After
+ public void after() throws IndexManagementException {
+ counter++;
+ if (counter == TESTCOUNT) {
+ counter = 0;
+ ldPathSemanticIndexManager.removeIndex(pid);
+ }
+ }
+}
Modified: incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/test/src/main/java/org/apache/stanbol/contenthub/test/store/file/FileStoreTest.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/test/src/main/java/org/apache/stanbol/contenthub/test/store/file/FileStoreTest.java?rev=1363343&r1=1363342&r2=1363343&view=diff
==============================================================================
--- incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/test/src/main/java/org/apache/stanbol/contenthub/test/store/file/FileStoreTest.java (original)
+++ incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/test/src/main/java/org/apache/stanbol/contenthub/test/store/file/FileStoreTest.java Thu Jul 19 14:06:30 2012
@@ -72,8 +72,9 @@ public class FileStoreTest {
@Test
public void storeFolderTest() {
- String stanbolHome = bundleContext.getProperty("sling.home");
- File storeFolder = new File(stanbolHome + "/filestore");
+ String fileStoreFolder = bundleContext.getProperty("sling.home") + "/"
+ + FileStore.FILE_STORE_FOLDER_PATH + "/" + FileStore.FILE_STORE_NAME;
+ File storeFolder = new File(fileStoreFolder);
assertTrue("No store folder exists", storeFolder.exists());
}
@@ -86,8 +87,9 @@ public class FileStoreTest {
id = store.put(ci);
// check zip file
- String stanbolHome = bundleContext.getProperty("sling.home");
- File storeFolder = new File(stanbolHome + "/filestore");
+ String fileStoreFolder = bundleContext.getProperty("sling.home") + "/"
+ + FileStore.FILE_STORE_FOLDER_PATH + "/" + FileStore.FILE_STORE_NAME;
+ File storeFolder = new File(fileStoreFolder);
String[] fileNames = storeFolder.list();
boolean zipExists = false;
for (String fileName : fileNames) {
@@ -147,7 +149,8 @@ public class FileStoreTest {
private void clearTestContentItem(String id) throws StoreException {
// delete the file
- String fileStoreFolder = bundleContext.getProperty("sling.home") + "/" + FileStore.FILE_STORE_NAME;
+ String fileStoreFolder = bundleContext.getProperty("sling.home") + "/"
+ + FileStore.FILE_STORE_FOLDER_PATH + "/" + FileStore.FILE_STORE_NAME;
File f = new File(fileStoreFolder + "/" + encodeId(id) + ".zip");
f.delete();
Modified: incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/web/pom.xml
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/web/pom.xml?rev=1363343&r1=1363342&r2=1363343&view=diff
==============================================================================
--- incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/web/pom.xml (original)
+++ incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/web/pom.xml Thu Jul 19 14:06:30 2012
@@ -70,7 +70,7 @@
<exclude>src/main/resources/org/apache/stanbol/contenthub/web/static/style/jquery-ui-1.8.11.custom.css</exclude>
<exclude>src/main/resources/org/apache/stanbol/contenthub/web/static/scripts/jquery-ui-1.8.11.custom.min.js</exclude>
<exclude>src/main/resources/org/apache/stanbol/contenthub/web/static/scripts/jquery-1.5.1.min.js</exclude>
- <exclude>src/main/resources/org/apache/stanbol/contenthub/web/static/scripts/jquery-1.4.2.js</exclude>
+ <exclude>src/main/resources/org/apache/stanbol/contenthub/web/static/scripts/jquery-1.4.2.js</exclude>
<!-- BSD License -->
<exclude>src/main/resources/org/apache/stanbol/contenthub/web/static/scripts/jit.js</exclude>
@@ -93,11 +93,16 @@
</dependency>
<dependency>
<groupId>org.apache.stanbol</groupId>
+ <artifactId>org.apache.stanbol.contenthub.index</artifactId>
+ <version>0.10.0-incubating-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.stanbol</groupId>
<artifactId>org.apache.stanbol.contenthub.store.file</artifactId>
<version>0.10.0-incubating-SNAPSHOT</version>
</dependency>
-<!-- needed for ContentItemResource -->
+ <!-- needed for ContentItemResource -->
<dependency>
<groupId>org.apache.clerezza</groupId>
<artifactId>jaxrs.rdf.providers</artifactId>
@@ -110,7 +115,7 @@
<dependency>
<groupId>org.apache.stanbol</groupId>
<artifactId>org.apache.stanbol.entityhub.core</artifactId>
- <version>0.10.1-incubating-SNAPSHOT</version>
+ <version>0.11.0-incubating-SNAPSHOT</version>
</dependency>
<!-- Jersey -->
@@ -175,7 +180,7 @@
</dependency>
<dependency>
<groupId>org.apache.stanbol</groupId>
- <artifactId>org.apache.stanbol.commons.solr.managed</artifactId>
+ <artifactId>org.apache.stanbol.contenthub.search.solr</artifactId>
<version>0.10.0-incubating-SNAPSHOT</version>
</dependency>
<dependency>
Modified: incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/fragment/ContenthubWebFragment.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/fragment/ContenthubWebFragment.java?rev=1363343&r1=1363342&r2=1363343&view=diff
==============================================================================
--- incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/fragment/ContenthubWebFragment.java (original)
+++ incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/fragment/ContenthubWebFragment.java Thu Jul 19 14:06:30 2012
@@ -30,11 +30,13 @@ import org.apache.stanbol.commons.web.ba
import org.apache.stanbol.commons.web.base.NavigationLink;
import org.apache.stanbol.commons.web.base.ScriptResource;
import org.apache.stanbol.commons.web.base.WebFragment;
+import org.apache.stanbol.contenthub.web.resources.FeaturedSearchResource;
+import org.apache.stanbol.contenthub.web.resources.LDPathSemanticIndexResource;
import org.apache.stanbol.contenthub.web.resources.RootResource;
import org.apache.stanbol.contenthub.web.resources.SemanticIndexManagerResource;
import org.apache.stanbol.contenthub.web.resources.StoreResource;
-import org.apache.stanbol.contenthub.web.writers.LDProgramCollectionWriter;
import org.apache.stanbol.contenthub.web.writers.SearchResultWriter;
+import org.apache.stanbol.contenthub.web.writers.SemanticIndexWriter;
import org.osgi.framework.BundleContext;
import org.osgi.service.component.ComponentContext;
@@ -71,9 +73,11 @@ public class ContenthubWebFragment imple
Set<Class<?>> classes = new HashSet<Class<?>>();
classes.add(RootResource.class);
classes.add(StoreResource.class);
- classes.add(SemanticIndexManagerResource.class);
- classes.add(LDProgramCollectionWriter.class);
+ classes.add(LDPathSemanticIndexResource.class);
+ classes.add(SemanticIndexWriter.class);
classes.add(SearchResultWriter.class);
+ classes.add(SemanticIndexManagerResource.class);
+ classes.add(FeaturedSearchResource.class);
return classes;
}
Added: incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/resources/FeaturedSearchResource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/resources/FeaturedSearchResource.java?rev=1363343&view=auto
==============================================================================
--- incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/resources/FeaturedSearchResource.java (added)
+++ incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/resources/FeaturedSearchResource.java Thu Jul 19 14:06:30 2012
@@ -0,0 +1,356 @@
+/*
+ * 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.web.resources;
+
+import static org.apache.stanbol.commons.web.base.CorsHelper.addCORSOrigin;
+import static org.apache.stanbol.commons.web.base.CorsHelper.enableCORS;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.servlet.ServletContext;
+import javax.ws.rs.DefaultValue;
+import javax.ws.rs.GET;
+import javax.ws.rs.OPTIONS;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.ResponseBuilder;
+import javax.ws.rs.core.Response.Status;
+
+import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.clerezza.rdf.core.access.TcManager;
+import org.apache.solr.client.solrj.SolrQuery;
+import org.apache.solr.client.solrj.SolrServerException;
+import org.apache.stanbol.commons.web.base.ContextHelper;
+import org.apache.stanbol.commons.web.base.resource.BaseStanbolResource;
+import org.apache.stanbol.contenthub.search.solr.util.SolrQueryUtil;
+import org.apache.stanbol.contenthub.servicesapi.Constants;
+import org.apache.stanbol.contenthub.servicesapi.index.SemanticIndexManager;
+import org.apache.stanbol.contenthub.servicesapi.index.search.SearchException;
+import org.apache.stanbol.contenthub.servicesapi.index.search.featured.FacetResult;
+import org.apache.stanbol.contenthub.servicesapi.index.search.featured.FeaturedSearch;
+import org.apache.stanbol.contenthub.servicesapi.index.search.featured.SearchResult;
+import org.apache.stanbol.contenthub.servicesapi.index.search.related.RelatedKeywordSearchManager;
+import org.apache.stanbol.contenthub.servicesapi.store.vocabulary.SolrVocabulary;
+import org.apache.stanbol.contenthub.web.util.JSONUtils;
+import org.apache.stanbol.contenthub.web.util.RestUtil;
+import org.osgi.framework.InvalidSyntaxException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.sun.jersey.api.view.Viewable;
+
+/**
+ * This class is the web resource which provides RESTful and HTTP interfaces for {@link FeaturedSearch}
+ * services.
+ *
+ * @author anil.sinaci
+ * @author suat
+ *
+ */
+@Path("/contenthub/{index}/search/featured")
+public class FeaturedSearchResource extends BaseStanbolResource {
+
+ private final static Logger log = LoggerFactory.getLogger(FeaturedSearchResource.class);
+
+ private TcManager tcManager;
+
+ private FeaturedSearch featuredSearch;
+
+ private String indexName;
+
+ /**
+ *
+ * @param context
+ * @param indexName
+ * Name of the LDPath program (name of the Solr core/index) to be used while storing this
+ * content item. LDPath programs can be managed through {@link SemanticIndexManagerResource} or
+ * {@link SemanticIndexManager}
+ * @throws IOException
+ * @throws InvalidSyntaxException
+ */
+ public FeaturedSearchResource(@Context ServletContext context,
+ @PathParam(value = "index") String indexName) throws IOException,
+ InvalidSyntaxException {
+ this.indexName = indexName;
+ this.featuredSearch = ContextHelper.getServiceFromContext(FeaturedSearch.class, context);
+ this.tcManager = ContextHelper.getServiceFromContext(TcManager.class, context);
+ }
+
+ @OPTIONS
+ public Response handleCorsPreflight(@Context HttpHeaders headers) {
+ ResponseBuilder res = Response.ok();
+ enableCORS(servletContext, res, headers);
+ return res.build();
+ }
+
+ /**
+ * HTTP GET method to make a featured search over Contenthub.
+ *
+ * @param queryTerm
+ * A keyword a statement or a set of keywords which can be regarded as the query term.
+ * @param solrQuery
+ * Solr query string. This is the string format which is accepted by a Solr server. For
+ * example, {@code q="john doe"&fl=score} is a valid value for this parameter. If this
+ * parameter exists, search is performed based on this solrQuery and any queryTerms are
+ * neglected.
+ * @param jsonCons
+ * Constrainst in JSON format. These constraints are tranformed to corresponding Solr queries
+ * to enable faceted search. Each constraint is a facet field and values of the constraints
+ * maps to the values of the facet fields in Solr queries.
+ * @param ontologyURI
+ * URI of the ontology in which related keywords will be searched by
+ * {@link RelatedKeywordSearchManager#getRelatedKeywordsFromOntology(String, String)}
+ * @param offset
+ * The offset of the document from which the resultant documents will start as the search
+ * result. {@link offset} and {@link limit} parameters can be used to make a pagination
+ * mechanism for search results.
+ * @param limit
+ * Maximum number of resultant documents to be returned as the search result. {@link offset}
+ * and {@link limit} parameters can be used to make a pagination mechanism for search results.
+ * @param fromStore
+ * Special parameter for HTML view only.
+ * @param headers
+ * HTTP headers
+ * @return HTML view or JSON representation of the search results or HTTP BAD REQUEST(400)
+ * @throws IllegalArgumentException
+ * @throws SearchException
+ * @throws InstantiationException
+ * @throws IllegalAccessException
+ * @throws SolrServerException
+ * @throws IOException
+ */
+ @GET
+ @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON})
+ public final Response get(@QueryParam("queryTerm") String queryTerm,
+ @QueryParam("solrQuery") String solrQuery,
+ @QueryParam("constraints") String jsonCons,
+ @QueryParam("ontologyURI") String ontologyURI,
+ @QueryParam("offset") @DefaultValue("0") int offset,
+ @QueryParam("limit") @DefaultValue("10") int limit,
+ @QueryParam("fromStore") String fromStore,
+ @Context HttpHeaders headers) throws IllegalArgumentException,
+ SearchException,
+ InstantiationException,
+ IllegalAccessException,
+ SolrServerException,
+ IOException {
+ MediaType acceptedHeader = RestUtil.getAcceptedMediaType(headers);
+
+ this.queryTerm = queryTerm = RestUtil.nullify(queryTerm);
+ solrQuery = RestUtil.nullify(solrQuery);
+ ontologyURI = RestUtil.nullify(ontologyURI);
+ jsonCons = RestUtil.nullify(jsonCons);
+ this.offset = offset;
+ this.pageSize = limit;
+
+ if (acceptedHeader.isCompatible(MediaType.TEXT_HTML_TYPE)) {
+ if (fromStore != null) {
+ return Response.ok(new Viewable("index", this), MediaType.TEXT_HTML).build();
+ }
+ if (queryTerm == null && solrQuery == null) {
+ this.ontologies = new ArrayList<String>();
+ Set<UriRef> mGraphs = tcManager.listMGraphs();
+ Iterator<UriRef> it = mGraphs.iterator();
+ while (it.hasNext()) {
+ ontologyURI = it.next().getUnicodeString();
+ if (Constants.isGraphReserved(ontologyURI)) {
+ continue;
+ }
+ this.ontologies.add(ontologyURI);
+ }
+ return Response.ok(new Viewable("index", this), MediaType.TEXT_HTML).build();
+ } else {
+ ResponseBuilder rb = performSearch(queryTerm, solrQuery, jsonCons, ontologyURI, offset,
+ limit, MediaType.TEXT_HTML_TYPE);
+ addCORSOrigin(servletContext, rb, headers);
+ return rb.build();
+ }
+ } else {
+ if (queryTerm == null && solrQuery == null) {
+ return Response.status(Status.BAD_REQUEST)
+ .entity("Either 'queryTerm' or 'solrQuery' should be specified").build();
+ } else {
+ ResponseBuilder rb = performSearch(queryTerm, solrQuery, jsonCons, ontologyURI, offset,
+ limit, MediaType.APPLICATION_JSON_TYPE);
+ addCORSOrigin(servletContext, rb, headers);
+ return rb.build();
+ }
+ }
+ }
+
+ private ResponseBuilder performSearch(String queryTerm,
+ String solrQuery,
+ String jsonCons,
+ String ontologyURI,
+ int offset,
+ int limit,
+ MediaType acceptedMediaType) throws SearchException {
+
+ if (solrQuery != null) {
+ this.searchResults = featuredSearch.search(new SolrQuery(solrQuery), ontologyURI, indexName);
+ } else if (queryTerm != null) {
+ Map<String,List<Object>> constraintsMap = JSONUtils.convertToMap(jsonCons);
+ this.chosenFacets = JSONUtils.convertToString(constraintsMap);
+
+ SolrQuery sq = null;
+ if (this.chosenFacets != null) {
+ List<FacetResult> allAvailableFacets = featuredSearch.getAllFacetResults(indexName);
+ sq = SolrQueryUtil.prepareSolrQuery(queryTerm, allAvailableFacets, constraintsMap);
+ } else {
+ sq = SolrQueryUtil.prepareSolrQuery(queryTerm);
+ }
+ sq.setStart(offset);
+ sq.setRows(limit + 1);
+ this.searchResults = featuredSearch.search(sq, ontologyURI, indexName);
+ } else {
+ log.error("Should never reach here!!!!");
+ throw new SearchException("Either 'queryTerm' or 'solrQuery' paramater should be set");
+ }
+
+ ResponseBuilder rb = null;
+ if (acceptedMediaType.isCompatible(MediaType.TEXT_HTML_TYPE)) {
+ // return HTML document
+ /*
+ * For HTML view, sort facets according to their names
+ */
+ this.searchResults.setFacets(sortFacetResults(this.searchResults.getFacets()));
+ rb = Response.ok(new Viewable("result.ftl", this));
+ rb.header(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_HTML + "; charset=utf-8");
+
+ } else {
+ // it is compatible with JSON (default) - return JSON
+ rb = Response.ok(this.searchResults);
+ rb.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON + "; charset=utf-8");
+ }
+ return rb;
+ }
+
+ private List<FacetResult> sortFacetResults(List<FacetResult> facetResults) {
+ List<FacetResult> orderedFacets = new ArrayList<FacetResult>();
+ int annotatedFacetNum = 0;
+ for (FacetResult fr : facetResults) {
+ String facetName = fr.getFacetField().getName();
+ if (fr.getFacetField().getValues() == null) {
+ continue;
+ } else if (SolrVocabulary.SolrFieldName.isAnnotatedEntityFacet(facetName)) {
+ orderedFacets.add(annotatedFacetNum, fr);
+ annotatedFacetNum++;
+ } else {
+ boolean inserted = false;
+ for (int j = annotatedFacetNum; j < orderedFacets.size(); j++) {
+ if (facetName.compareTo(orderedFacets.get(j).getFacetField().getName()) < 0) {
+ orderedFacets.add(j, fr);
+ inserted = true;
+ break;
+ }
+ }
+ if (inserted == false) {
+ orderedFacets.add(fr);
+ }
+ }
+ }
+ return orderedFacets;
+ }
+
+ // /*
+ // * Services to draw HTML view
+ // */
+ //
+ // // Data holders for HTML view
+ private List<String> ontologies = null;
+ private String queryTerm = null;
+ // // private String solrQuery = null;
+ // // private String ldProgram = null;
+ // // private String graphURI = null;
+ private SearchResult searchResults = null;
+ private String chosenFacets = null;
+ private int offset = 0;
+ private int pageSize = 10;
+
+ // // ///////////////////////////
+ //
+ // /*
+ // * Helper methods for HTML view
+ // */
+ //
+ public Object getMoreRecentItems() {
+ if (offset >= pageSize) {
+ return new Object();
+ } else {
+ return null;
+ }
+ }
+
+ public Object getOlderItems() {
+ if (searchResults.getDocuments().size() <= pageSize) {
+ return null;
+ } else {
+ return new Object();
+ }
+ }
+
+ public int getOffset() {
+ return this.offset;
+ }
+
+ public int getPageSize() {
+ return this.pageSize;
+ }
+
+ public Object getSearchResults() {
+ return this.searchResults;
+ }
+
+ public Object getDocuments() {
+ if (searchResults.getDocuments().size() > pageSize) {
+ return searchResults.getDocuments().subList(0, pageSize);
+ } else {
+ return searchResults.getDocuments();
+ }
+ }
+
+ public Object getOntologies() {
+ return this.ontologies;
+ }
+
+ public Object getQueryTerm() {
+ if (queryTerm != null) {
+ return queryTerm;
+ }
+ return "";
+ }
+
+ public String getChosenFacets() {
+ return this.chosenFacets;
+ }
+
+ public String getIndexName() {
+ return this.indexName;
+ }
+}
\ No newline at end of file