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 [2/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...

Added: incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/index/src/main/java/org/apache/stanbol/contenthub/index/ldpath/LDPathSemanticIndexManager.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/index/src/main/java/org/apache/stanbol/contenthub/index/ldpath/LDPathSemanticIndexManager.java?rev=1363343&view=auto
==============================================================================
--- incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/index/src/main/java/org/apache/stanbol/contenthub/index/ldpath/LDPathSemanticIndexManager.java (added)
+++ incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/index/src/main/java/org/apache/stanbol/contenthub/index/ldpath/LDPathSemanticIndexManager.java Thu Jul 19 14:06:30 2012
@@ -0,0 +1,420 @@
+/*
+ * 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.index.ldpath;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Properties;
+
+import org.apache.commons.compress.archivers.ArchiveInputStream;
+import org.apache.commons.io.IOUtils;
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.stanbol.commons.solr.managed.IndexMetadata;
+import org.apache.stanbol.commons.solr.managed.ManagedSolrServer;
+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.entityhub.servicesapi.site.SiteManager;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
+import org.osgi.service.component.ComponentContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.xml.sax.SAXException;
+
+/**
+ * This class provides facilities to create {@link LDPathSemanticIndex} instances based on given LDPath
+ * program other parameters. {@link SemanticIndex}es can be created through both Felix Web console by
+ * configuring a new {@link LDPathSemanticIndex} or through the REST/Java API by giving the necessary
+ * information to create the index.
+ * 
+ * @author suat
+ * @author anil
+ * 
+ */
+@Component(immediate = true)
+@Service(value = LDPathSemanticIndexManager.class)
+public class LDPathSemanticIndexManager {
+
+    private final Logger logger = LoggerFactory.getLogger(LDPathSemanticIndexManager.class);
+
+    private final static String INDEX_METADATA_FOLDER_PATH = "LDPathSemanticIndexMetadata";
+
+    private File indexMetadataDirectory;
+
+    private Map<String,Properties> indexMetadataMap = new HashMap<String,Properties>();
+
+    private LDPathUtils ldPathUtils;
+
+    private BundleContext bundleContext;
+
+    @Reference(target = "(org.apache.solr.core.CoreContainer.name=contenthub)")
+    private ManagedSolrServer managedSolrServer;
+
+    @Reference
+    private SiteManager siteManager;
+
+    @Activate
+    public void activator(ComponentContext context) throws IndexManagementException {
+        this.bundleContext = context.getBundleContext();
+        ldPathUtils = new LDPathUtils(bundleContext.getBundle(), siteManager);
+
+        indexMetadataDirectory = bundleContext.getDataFile(INDEX_METADATA_FOLDER_PATH);
+
+        // if directory for programs does not exist, create it
+        if (!indexMetadataDirectory.exists()) {
+            if (indexMetadataDirectory.mkdirs()) {
+                logger.info("Directory for index metadata created succesfully");
+            } else {
+                logger.error("Directory for index metadata COULD NOT be created");
+                throw new IndexManagementException("Directory : " + indexMetadataDirectory.getAbsolutePath()
+                                                   + " cannot be created");
+            }
+        }
+
+        // load index metadata to memory
+        synchronized (indexMetadataMap) {
+            File[] metadataList = indexMetadataDirectory.listFiles();
+            for (File configFile : metadataList) {
+                String pid = configFile.getName().substring(0, configFile.getName().lastIndexOf('.'));
+                Properties props = new Properties();
+                InputStream is = null;
+                try {
+                    is = new FileInputStream(configFile);
+                    props.load(is);
+                    indexMetadataMap.put(pid, props);
+                    logger.info("Index metadata has been loaded from the location: {}",
+                        configFile.getAbsolutePath());
+                } catch (FileNotFoundException e) {
+                    logger.error("IndexMetadata file cannot be found");
+                    throw new IndexManagementException("IndexMetadata file cannot be found");
+                } catch (IOException e) {
+                    logger.error("Failed to read from input stream");
+                    throw new IndexManagementException("Failed to read from input stream");
+                } finally {
+                    IOUtils.closeQuietly(is);
+                }
+            }
+        }
+    }
+
+    /**
+     * Creates an {@link LDPathSemanticIndex} instance based on the given name, description and LDPath
+     * program. For other parameters that are used to create the index, the following default values are
+     * provided:
+     * <ul>
+     * <li>{@link LDPathSemanticIndex#PROP_INDEX_CONTENT}: {@code true}</li>
+     * <li>{@link LDPathSemanticIndex#PROP_BATCH_SIZE}: 10</li>
+     * <li>{@link LDPathSemanticIndex#PROP_STORE_CHECK_PERIOD}: 10</li>
+     * <li>{@link LDPathSemanticIndex#PROP_SOLR_CHECK_TIME}: 5</li>
+     * <li>{@link Constants#SERVICE_RANKING}: 0</li>
+     * </ul>
+     * 
+     * Each created {@link LDPathSemanticIndex} becomes an OSGi component and it can be obtained as a
+     * {@link ServiceReference}. It is possible to get indexes through the {@link SemanticIndexManager} or
+     * {@link BundleContext}.
+     * 
+     * @param indexName
+     *            name of the index to be created
+     * @param indexDescription
+     *            description of the index to be created
+     * @param ldPathProgram
+     *            LDPath program on which the Solr core will created
+     * @throws IndexManagementException
+     */
+    public String createIndex(String indexName, String indexDescription, String ldPathProgram) throws IndexManagementException {
+        if (indexName == null || indexName.isEmpty() || ldPathProgram == null || ldPathProgram.isEmpty()) {
+            throw new IndexManagementException("Index name and LDPath program cannot be null or empty");
+        }
+
+        if (managedSolrServer.isManagedIndex(indexName)) {
+            throw new IndexManagementException(String.format("There is already an index with the name: %s",
+                indexName));
+        }
+
+        Properties props = new Properties();
+        props.put(LDPathSemanticIndex.PROP_NAME, indexName);
+        props.put(LDPathSemanticIndex.PROP_LD_PATH_PROGRAM, ldPathProgram);
+        props.put(LDPathSemanticIndex.PROP_DESCRIPTION, indexDescription);
+        return createIndex(props);
+    }
+    
+    /**
+     * Creates an {@link LDPathSemanticIndex} instance based on the given index metadata. However, provided
+     * {@link Properties} must include the following items.
+     * <ul>
+     * <li><b>{@link LDPathSemanticIndex#PROP_NAME}</b></li>
+     * <li><b>{@link LDPathSemanticIndex#PROP_LD_PATH_PROGRAM}</b></li>
+     * </ul>
+     * For other parameters that are used to create the index, the following default values are provided:
+     * <ul>
+     * <li>{@link LDPathSemanticIndex#PROP_INDEX_CONTENT}: {@code true}</li>
+     * <li>{@link LDPathSemanticIndex#PROP_BATCH_SIZE}: 10</li>
+     * <li>{@link LDPathSemanticIndex#PROP_STORE_CHECK_PERIOD}: 10</li>
+     * <li>{@link LDPathSemanticIndex#PROP_SOLR_CHECK_TIME}: 5</li>
+     * <li>{@link Constants#SERVICE_RANKING}: 0</li>
+     * </ul>
+     * An new configuration for the {@link LDPathSemanticIndex} is created by {@link ConfigurationAdmin} of
+     * OSGi using the provided index metadata. So, each created {@link LDPathSemanticIndex} becomes an OSGi
+     * component and it can be obtained as a {@link ServiceReference}. It is possible to get indexes through
+     * the {@link SemanticIndexManager} or {@link BundleContext}.
+     * 
+     * @param indexMetadata
+     *            {@link Properties} containing the possible metadata about the index to be created
+     * @throws IndexManagementException
+     */
+    public String createIndex(Properties indexMetadata) throws IndexManagementException {
+        // validate properties
+        String indexName = (String) indexMetadata.get(SemanticIndex.PROP_NAME);
+        String ldPathProgram = (String) indexMetadata.get(LDPathSemanticIndex.PROP_LD_PATH_PROGRAM);
+        String configurationPID = (String) indexMetadata.get(Constants.SERVICE_PID);
+
+        if (indexName == null || indexName.isEmpty() || ldPathProgram == null || ldPathProgram.isEmpty()) {
+            throw new IndexManagementException("Index name and LDPath program cannot be null or empty");
+        }
+
+        if (managedSolrServer.isManagedIndex(indexName)) {
+            throw new IndexManagementException(String.format("There is already an index with the name: %s",
+                indexName));
+        }
+
+        checkValues(indexMetadata);
+
+        // create solr core
+        createSolrCore(indexName, ldPathProgram);
+        logger.info("Solr core for the Semantic Index: {} has been created successfully", indexName);
+
+        // activate the OSGI component if it is not already done. This is the case when an LDPathSemanticIndex
+        // is created through the REST/Java API
+        if (configurationPID == null) {
+            ServiceReference reference = bundleContext
+                    .getServiceReference(ConfigurationAdmin.class.getName());
+            ConfigurationAdmin configAdmin = (ConfigurationAdmin) bundleContext.getService(reference);
+            Configuration config;
+            try {
+                config = configAdmin.createFactoryConfiguration(LDPathSemanticIndex.class.getName(), null);
+                configurationPID = config.getPid();
+
+                storeIndexMetadata(configurationPID, indexMetadata);
+                config.update(indexMetadata);
+                logger.info(
+                    "A new configuration has been created for the Semantic Index: {} and its metadata was stored",
+                    indexName);
+            } catch (IOException e) {
+                logger.error("Failed to create Factory Configuration for LDPathSemanticIndex: {}", indexName);
+                throw new IndexManagementException(String.format(
+                    "Failed to create Factory Configuration for LDPathSemanticIndex: %s", indexName), e);
+            }
+
+            // the index created through the Felix Web console
+        } else {
+            storeIndexMetadata(configurationPID, indexMetadata);
+            logger.info(
+                "A configuration has already been created for the Semantic Index: {}, so only its metadata was stored",
+                indexName);
+        }
+        return configurationPID;
+    }
+
+    private void checkValues(Properties indexMetadata) {
+        if (indexMetadata.get(LDPathSemanticIndex.PROP_DESCRIPTION) == null) {
+            indexMetadata.put(LDPathSemanticIndex.PROP_DESCRIPTION, "");
+        }
+        if (indexMetadata.get(LDPathSemanticIndex.PROP_INDEX_CONTENT) == null) {
+            indexMetadata.put(LDPathSemanticIndex.PROP_INDEX_CONTENT, true);
+        }
+        if (indexMetadata.get(LDPathSemanticIndex.PROP_BATCH_SIZE) == null) {
+            indexMetadata.put(LDPathSemanticIndex.PROP_BATCH_SIZE, 10);
+        }
+        if (indexMetadata.get(LDPathSemanticIndex.PROP_STORE_CHECK_PERIOD) == null) {
+            indexMetadata.put(LDPathSemanticIndex.PROP_STORE_CHECK_PERIOD, 10);
+        }
+        if (indexMetadata.get(LDPathSemanticIndex.PROP_SOLR_CHECK_TIME) == null) {
+            indexMetadata.put(LDPathSemanticIndex.PROP_SOLR_CHECK_TIME, 5);
+        }
+        if (indexMetadata.get(Constants.SERVICE_RANKING) == null) {
+            indexMetadata.put(Constants.SERVICE_RANKING, 0);
+        }
+    }
+
+    /**
+     * Create a Solr core using the given {@code coreName} and {@code ldPathProgram}. A solr schema
+     * configuration archive is formed based on the given parameters through the
+     * {@link LDPathUtils#createSchemaArchive(String, String)} and this archive is used to create a Solr core
+     * by {@link ManagedSolrServer}.
+     * 
+     * @param coreName
+     *            Name of the Solr core to be created
+     * @param ldPathProgram
+     *            LDPath program to adjust the Solr core configuration
+     * @return the {@link IndexMetadata} of the created Solr core
+     * @throws IndexManagementException
+     */
+    public IndexMetadata createSolrCore(String coreName, String ldPathProgram) throws IndexManagementException {
+        ArchiveInputStream coreArchive = ldPathUtils.createSchemaArchive(coreName, ldPathProgram);
+        try {
+            return managedSolrServer.createSolrIndex(coreName, coreArchive);
+        } catch (IOException e) {
+            logger.error(e.getMessage(), e);
+            throw new IndexManagementException(e.getMessage(), e);
+        } catch (SAXException e) {
+            String msg = "ManagedSolrServer cannot parse the related XML files.";
+            logger.error(msg, e);
+            throw new IndexManagementException(msg, e);
+        }
+    }
+
+    /**
+     * Returns the metadata of the index specified with the given persistent identifier (pid)
+     * 
+     * @param pid
+     * @return
+     */
+    public Properties getIndexMetadata(String pid) {
+        synchronized (indexMetadataMap) {
+            return indexMetadataMap.get(pid);
+        }
+    }
+
+    /**
+     * Updates the metadata of the index specified with the given persistent identifier (pid)
+     * 
+     * @param pid
+     * @param indexMetadata
+     * @throws IndexManagementException
+     * @throws IOException
+     */
+    public void updateIndexMetadata(String pid, Properties indexMetadata) throws IndexManagementException {
+        synchronized (indexMetadataMap) {
+            storeIndexMetadata(pid, indexMetadata);
+        }
+    }
+
+    /**
+     * Returns the {@link Map} containing metadata of the {@link LDPathSemanticIndex} instances.
+     * 
+     * @return
+     */
+    public Map<String,Properties> getAllIndexMetadata() {
+        synchronized (indexMetadataMap) {
+            return indexMetadataMap;
+        }
+    }
+
+    /**
+     * Returns whether a Solr core for the given {@code pid} is already configured.
+     * 
+     * @param pid
+     *            persistent identifier(pid) of the factory configuration of {@link LDPathSemanticIndex}
+     * @return
+     */
+    public boolean isConfigured(String pid) {
+        synchronized (indexMetadataMap) {
+            return indexMetadataMap.containsKey(pid);
+        }
+    }
+
+    /**
+     * Remove the underlying Solr core and index metadata associated with the {@code pid}
+     * 
+     * @param pid
+     *            persistent identifier (pid) of the factory configuration of {@link LDPathSemanticIndex}
+     * @throws IndexManagementException
+     */
+    public void removeIndex(String pid) throws IndexManagementException {
+
+        Properties indexMetadata = removeIndexMetadata(pid);
+        managedSolrServer.removeIndex(indexMetadata.getProperty(SemanticIndex.PROP_NAME), true);
+        ServiceReference reference = bundleContext.getServiceReference(ConfigurationAdmin.class.getName());
+        ConfigurationAdmin configAdmin = (ConfigurationAdmin) bundleContext.getService(reference);
+        Configuration config;
+        String indexName = (String) indexMetadata.get(SemanticIndex.PROP_NAME);
+        try {
+            config = configAdmin.getConfiguration(pid);
+            config.delete();
+            logger.info("Semantic Index: {} was removed successfully", indexName);
+        } catch (IOException e) {
+            throw new IndexManagementException(String.format(
+                "Failed to remove configuration for the Semantic Index: %s", indexName));
+        }
+    }
+
+    private Properties removeIndexMetadata(String pid) throws IndexManagementException {
+        String indexMetadataFilePath = indexMetadataDirectory.getAbsolutePath() + File.separator + pid
+                                       + ".props";
+        File file = new File(indexMetadataFilePath);
+        if (file.exists()) {
+            file.delete();
+        } else {
+            logger.error("Failed to delete IndexMetadata file");
+            throw new IndexManagementException("Failed to delete IndexMetadata file");
+        }
+
+        Properties indexMetadata;
+        synchronized (indexMetadataMap) {
+            indexMetadata = indexMetadataMap.remove(pid);
+        }
+
+        return indexMetadata;
+    }
+
+    private void storeIndexMetadata(String pid, Properties indexMetadata) throws IndexManagementException {
+        String indexMetadataFilePath = indexMetadataDirectory.getAbsolutePath() + File.separator + pid
+                                       + ".props";
+        synchronized (indexMetadataMap) {
+            FileOutputStream out = null;
+            Properties stringValues = getStringValues(indexMetadata);
+            try {
+                out = new FileOutputStream(indexMetadataFilePath);
+                stringValues.store(out, null);
+            } catch (IOException e) {
+                logger.error("Failed to write indexMetadataFilePath to the specified output stream");
+                throw new IndexManagementException(
+                        "Failed to write indexMetadataFilePath to the specified output stream");
+            } finally {
+                IOUtils.closeQuietly(out);
+            }
+            indexMetadataMap.put(pid, stringValues);
+        }
+    }
+
+    private Properties getStringValues(Properties indexMetadata) {
+        Properties properties = new Properties();
+        for (Entry<Object,Object> property : indexMetadata.entrySet()) {
+            Object value = property.getValue();
+            if (value instanceof String) {
+                properties.put(property.getKey(), value);
+            } else {
+                properties.put(property.getKey(), value.toString());
+            }
+        }
+        return properties;
+    }
+}

Added: incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/index/src/main/java/org/apache/stanbol/contenthub/index/ldpath/LDPathUtils.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/index/src/main/java/org/apache/stanbol/contenthub/index/ldpath/LDPathUtils.java?rev=1363343&view=auto
==============================================================================
--- incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/index/src/main/java/org/apache/stanbol/contenthub/index/ldpath/LDPathUtils.java (added)
+++ incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/index/src/main/java/org/apache/stanbol/contenthub/index/ldpath/LDPathUtils.java Thu Jul 19 14:06:30 2012
@@ -0,0 +1,417 @@
+/*
+ * 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.index.ldpath;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.UnsupportedEncodingException;
+import java.net.URL;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.apache.commons.compress.archivers.ArchiveException;
+import org.apache.commons.compress.archivers.ArchiveInputStream;
+import org.apache.commons.compress.archivers.ArchiveStreamFactory;
+import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
+import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;
+import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
+import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream;
+import org.apache.commons.io.IOUtils;
+import org.apache.stanbol.contenthub.servicesapi.Constants;
+import org.apache.stanbol.contenthub.servicesapi.index.IndexManagementException;
+import org.apache.stanbol.entityhub.ldpath.backend.SiteManagerBackend;
+import org.apache.stanbol.entityhub.servicesapi.site.SiteManager;
+import org.osgi.framework.Bundle;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.bootstrap.DOMImplementationRegistry;
+import org.w3c.dom.ls.DOMImplementationLS;
+import org.w3c.dom.ls.LSOutput;
+import org.w3c.dom.ls.LSSerializer;
+import org.xml.sax.SAXException;
+
+import at.newmedialab.ldpath.api.backend.RDFBackend;
+import at.newmedialab.ldpath.model.fields.FieldMapping;
+import at.newmedialab.ldpath.model.programs.Program;
+import at.newmedialab.ldpath.parser.ParseException;
+import at.newmedialab.ldpath.parser.RdfPathParser;
+
+/**
+ * Class containing utility methods for LDPath functionalities.
+ * 
+ * @author anil.sinaci
+ * 
+ */
+public class LDPathUtils {
+    private static final Logger logger = LoggerFactory.getLogger(LDPathUtils.class);
+
+    public static final String NS_XSD = "http://www.w3.org/2001/XMLSchema#";
+
+    private static final String SOLR_CORE_PATH = "solr/core/";
+    private static final String SOLR_TEMPLATE_NAME = "template";
+    private static final String SOLR_TEMPLATE_ZIP = SOLR_TEMPLATE_NAME + ".zip";
+    private static final String SOLR_TEMPLATE_SCHEMA = SOLR_TEMPLATE_NAME + "/conf/schema-template.xml";
+    private static final String SOLR_SCHEMA = "/conf/schema.xml";
+    private static final String SOLR_ALLTEXT_FIELD = "contenthubreserved_text_all";
+
+    private static final int BUFFER_SIZE = 8024;
+
+    private static final Set<String> SOLR_FIELD_OPTIONS;
+    static {
+        HashSet<String> opt = new HashSet<String>();
+        opt.add("default");
+        opt.add("indexed");
+        opt.add("stored");
+        opt.add("compressed");
+        opt.add("compressThreshold");
+        opt.add("multiValued");
+        opt.add("omitNorms");
+        opt.add("omitTermFreqAndPositions");
+        opt.add("termVectors");
+        opt.add("termPositions");
+        opt.add("termOffsets");
+
+        SOLR_FIELD_OPTIONS = Collections.unmodifiableSet(opt);
+    }
+    private static final String SOLR_COPY_FIELD_OPTION = "copy";
+
+    /**
+     * A map mapping from XSD types to SOLR types.
+     */
+    private static final Map<String,String> xsdSolrTypeMap;
+    static {
+        Map<String,String> typeMap = new HashMap<String,String>();
+
+        typeMap.put(NS_XSD + "decimal", "long");
+        typeMap.put(NS_XSD + "integer", "int");
+        typeMap.put(NS_XSD + "int", "int");
+        typeMap.put(NS_XSD + "long", "long");
+        typeMap.put(NS_XSD + "short", "int");
+        typeMap.put(NS_XSD + "double", "double");
+        typeMap.put(NS_XSD + "float", "float");
+        typeMap.put(NS_XSD + "dateTime", "date");
+        typeMap.put(NS_XSD + "date", "date");
+        typeMap.put(NS_XSD + "time", "date");
+        typeMap.put(NS_XSD + "boolean", "boolean");
+        typeMap.put(NS_XSD + "anyURI", "uri");
+        typeMap.put(NS_XSD + "string", "string");
+
+        xsdSolrTypeMap = Collections.unmodifiableMap(typeMap);
+    }
+
+    private Bundle bundle;
+
+    private SiteManager siteManager;
+
+    /**
+     * Constructor taking a {@link Bundle} parameter. This bundle is used when obtaining Solr schema template.
+     * 
+     * @param bundle
+     *            From which the template Solr schema is obtained.
+     */
+    public LDPathUtils(Bundle bundle, SiteManager siteManager) {
+        this.bundle = bundle;
+        this.siteManager = siteManager;
+    }
+
+    /**
+     * Return the SOLR field type for the XSD type passed as argument. The xsdType needs to be a fully
+     * qualified URI. If no field type is defined, will return null.
+     * 
+     * @param xsdType
+     *            a URI identifying the XML Schema datatype
+     * @return
+     */
+    public String getSolrFieldType(String xsdType) {
+        String result = xsdSolrTypeMap.get(xsdType);
+        if (result == null) {
+            logger.error("Could not find SOLR field type for type " + xsdType);
+            return null;
+        } else {
+            return result;
+        }
+    }
+
+    /**
+     * Creates a {@link Reader} instance from the given program string.
+     * 
+     * @param program
+     * @return a {@link InputStreamReader}.
+     * @throws IndexManagementException
+     *             if {@link Constants#DEFAULT_ENCODING} is not supported
+     */
+    public static Reader constructReader(String program) throws IndexManagementException {
+        try {
+            return new InputStreamReader(new ByteArrayInputStream(
+                    program.getBytes(Constants.DEFAULT_ENCODING)), Constants.DEFAULT_ENCODING);
+        } catch (UnsupportedEncodingException e) {
+            String msg = String.format("Encoding {} should be supported by the system",
+                Constants.DEFAULT_ENCODING);
+            logger.error(msg, e);
+            throw new IndexManagementException(msg, e);
+        }
+    }
+
+    private Program<Object> getLDPathProgram(String ldPathProgram) throws IndexManagementException {
+        if (ldPathProgram == null || ldPathProgram.isEmpty()) {
+            String msg = "LDPath Program cannot be null.";
+            logger.error(msg);
+            throw new IndexManagementException(msg);
+        }
+        RDFBackend<Object> rdfBackend = new SiteManagerBackend(siteManager);
+        RdfPathParser<Object> LDparser = new RdfPathParser<Object>(rdfBackend, constructReader(ldPathProgram));
+        Program<Object> program = null;
+        try {
+            program = LDparser.parseProgram();
+        } catch (ParseException e) {
+            String msg = "Cannot parse LDPath Program";
+            logger.error(msg, e);
+            throw new IndexManagementException(msg, e);
+        }
+        return program;
+    }
+
+    /**
+     * This method creates an {@link ArchiveInputStream} containing Solr schema configurations based on the
+     * provided <code>ldPathProgram</code>. All folders and files except <b>"schema-template.xml"</b> is took
+     * from a default Solr configuration template which is located in the resources of the bundle specified in
+     * the constructor of this class i.e {@link LDPathUtils}. Instead of the "schema-template" file, a
+     * <b>"schema.xml"</b> is created.
+     * 
+     * @param coreName
+     *            Name of the Solr core that is used instead of template
+     * @param ldPathProgram
+     *            Program for which the Solr core will be created
+     * @return {@link ArchiveInputStream} containing the Solr configurations for the provided
+     *         <code>ldPathProgram</code>
+     * @throws IndexManagementException
+     */
+    public ArchiveInputStream createSchemaArchive(String coreName, String ldPathProgram) throws IndexManagementException {
+        ByteArrayOutputStream out = new ByteArrayOutputStream(BUFFER_SIZE);
+        ArchiveStreamFactory asf = new ArchiveStreamFactory();
+        TarArchiveOutputStream tarOutputStream = null;
+        try {
+            tarOutputStream = (TarArchiveOutputStream) asf.createArchiveOutputStream("tar", out);
+        } catch (ArchiveException e) {
+            String msg = "Cannot create an empty tar archive";
+            logger.error(msg, e);
+            throw new IndexManagementException(msg, e);
+        }
+
+        try {
+            InputStream is = getSolrTemplateStream();
+            ZipArchiveInputStream zis = new ZipArchiveInputStream(is);
+            ZipArchiveEntry ze = null;
+            byte[] schemaFile = null;
+            while ((ze = zis.getNextZipEntry()) != null) {
+                if (SOLR_TEMPLATE_SCHEMA.equals(ze.getName())) {
+                    schemaFile = createSchemaXML(getLDPathProgram(ldPathProgram), IOUtils.toByteArray(zis));
+                    TarArchiveEntry te = new TarArchiveEntry(coreName + SOLR_SCHEMA);
+                    te.setSize(schemaFile.length);
+                    tarOutputStream.putArchiveEntry(te);
+                    tarOutputStream.write(schemaFile);
+                    tarOutputStream.closeArchiveEntry();
+                } else {
+                    TarArchiveEntry te = new TarArchiveEntry(ze.getName().replaceAll(SOLR_TEMPLATE_NAME,
+                        coreName));
+                    te.setSize(ze.getSize());
+                    tarOutputStream.putArchiveEntry(te);
+                    tarOutputStream.write(IOUtils.toByteArray(zis));
+                    tarOutputStream.closeArchiveEntry();
+                }
+
+            }
+            if (schemaFile == null) {
+                throw new IndexManagementException("Schema template ZIP should include: "
+                                                   + SOLR_TEMPLATE_SCHEMA);
+            }
+            tarOutputStream.finish();
+            tarOutputStream.close();
+        } catch (IOException e) {
+            logger.error("", e);
+            throw new IndexManagementException(e);
+        }
+
+        ArchiveInputStream ret;
+        try {
+            ret = asf.createArchiveInputStream(new ByteArrayInputStream(out.toByteArray()));
+        } catch (ArchiveException e) {
+            String msg = "Cannot create a final tar archive while creating an ArchiveInputStream to create a Solr core";
+            logger.error(msg, e);
+            throw new IndexManagementException(msg, e);
+        }
+        return ret;
+    }
+
+    private InputStream getSolrTemplateStream() throws IndexManagementException {
+        String solrCorePath = SOLR_CORE_PATH;
+        if (!solrCorePath.endsWith(File.separator)) solrCorePath += File.separator;
+        String templateZip = solrCorePath + SOLR_TEMPLATE_ZIP;
+
+        URL resource = bundle.getEntry(templateZip);
+        InputStream is = null;
+        try {
+            is = resource != null ? resource.openStream() : null;
+        } catch (IOException e) {
+            String msg = "Cannot open input stream on URL resource gathered from bundle.getEntry()";
+            logger.error(msg, e);
+            throw new IndexManagementException(msg, e);
+        }
+        if (is == null) {
+            String msg = "Solr Template ZIP cannot be found in:" + templateZip;
+            logger.error(msg);
+            throw new IndexManagementException(msg);
+        }
+        return is;
+    }
+
+    /**
+     * Creates <b>"schema.xml"</b> file for the Solr configurations to be created for the provided LDPath
+     * program. Creates <b>Solr fields</b> for each field obtained by calling {@link Program#getFields()} of
+     * provided <code>program</code>. By default, <i>name</i>, <i>type</i>, <i>stored</i>, <i>indexed</i> and
+     * <i>multiValued</i> attributes of fields are set. Furthermore, any attribute obtained from the fields of
+     * the program is also set if it is included in {@link LDPathUtils#SOLR_FIELD_OPTIONS}. Another
+     * configuration about the fields obtained from the program is {@link LDPathUtils#SOLR_COPY_FIELD_OPTION}.
+     * If there is a specified configuration about this field, <b>destination</b> of <b>copyField</b> element
+     * is set accordingly. Otherwise, the destination is set as <b>contenthubreserved_text_all</b>
+     * 
+     * @param program
+     *            LDPath program of which fields will be obtained
+     * @param template
+     *            Solr schema template to be populated with the fields based on the provided
+     *            <code>program</code>
+     * @return created template in an array of bytes.
+     * @throws IndexManagementException
+     */
+    private byte[] createSchemaXML(Program<Object> program, byte[] template) throws IndexManagementException {
+        Document document;
+        try {
+            document = DocumentBuilderFactory.newInstance().newDocumentBuilder()
+                    .parse(new ByteArrayInputStream(template));
+        } catch (SAXException e) {
+            String msg = e.getMessage();
+            logger.error(msg, e);
+            throw new IndexManagementException(msg, e);
+        } catch (IOException e) {
+            String msg = e.getMessage();
+            logger.error(msg, e);
+            throw new IndexManagementException(msg, e);
+        } catch (ParserConfigurationException e) {
+            String msg = e.getMessage();
+            logger.error(msg, e);
+            throw new IndexManagementException(msg, e);
+        }
+
+        Element schemaNode = document.getDocumentElement();
+        NodeList fieldsNodeList = schemaNode.getElementsByTagName("fields");
+        if (fieldsNodeList.getLength() != 1) {
+            throw new IndexManagementException(
+                    "Template is an invalid SOLR schema. It should be a valid a byte array");
+        }
+
+        Node fieldsNode = fieldsNodeList.item(0);
+
+        for (FieldMapping<?,Object> fieldMapping : program.getFields()) {
+            String fieldName = fieldMapping.getFieldName();
+            String solrType = getSolrFieldType(fieldMapping.getFieldType());
+
+            if (solrType == null) {
+                logger.error("field {} has an invalid field type; ignoring field definition", fieldName);
+            } else {
+                Element fieldElement = document.createElement("field");
+                fieldElement.setAttribute("name", fieldName);
+                fieldElement.setAttribute("type", solrType);
+                fieldElement.setAttribute("stored", "true");
+                fieldElement.setAttribute("indexed", "true");
+                fieldElement.setAttribute("multiValued", "true");
+
+                // Handle extra field configuration
+                final Map<String,String> fieldConfig = fieldMapping.getFieldConfig();
+                if (fieldConfig != null) {
+                    for (String attr : fieldConfig.keySet()) {
+                        if (SOLR_FIELD_OPTIONS.contains(attr)) {
+                            fieldElement.setAttribute(attr, fieldConfig.get(attr));
+                        }
+                    }
+                }
+                fieldsNode.appendChild(fieldElement);
+
+                if (fieldConfig != null && fieldConfig.keySet().contains(SOLR_COPY_FIELD_OPTION)) {
+                    String[] copyFields = fieldConfig.get(SOLR_COPY_FIELD_OPTION).split(",\\s*");
+                    for (String copyField : copyFields) {
+                        Element copyElement = document.createElement("copyField");
+                        copyElement.setAttribute("source", fieldName);
+                        copyElement.setAttribute("dest", copyField);
+                        schemaNode.appendChild(copyElement);
+                    }
+                } else {
+                    Element copyElement = document.createElement("copyField");
+                    copyElement.setAttribute("source", fieldName);
+                    copyElement.setAttribute("dest", SOLR_ALLTEXT_FIELD);
+                    schemaNode.appendChild(copyElement);
+                }
+            }
+        }
+
+        DOMImplementationRegistry registry;
+        try {
+            registry = DOMImplementationRegistry.newInstance();
+        } catch (ClassCastException e) {
+            String msg = e.getMessage();
+            logger.error(msg, e);
+            throw new IndexManagementException(msg, e);
+        } catch (ClassNotFoundException e) {
+            String msg = e.getMessage();
+            logger.error(msg, e);
+            throw new IndexManagementException(msg, e);
+        } catch (InstantiationException e) {
+            String msg = e.getMessage();
+            logger.error(msg, e);
+            throw new IndexManagementException(msg, e);
+        } catch (IllegalAccessException e) {
+            String msg = e.getMessage();
+            logger.error(msg, e);
+            throw new IndexManagementException(msg, e);
+        }
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        DOMImplementationLS lsImpl = (DOMImplementationLS) registry.getDOMImplementation("LS");
+        LSSerializer lsSerializer = lsImpl.createLSSerializer();
+        LSOutput lsOutput = lsImpl.createLSOutput();
+        lsOutput.setEncoding("UTF-8");
+        lsOutput.setByteStream(baos);
+        lsSerializer.write(document, lsOutput);
+        String schemaStr = new String(baos.toByteArray());
+        return schemaStr.getBytes();
+    }
+
+}

Added: incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/index/src/main/resources/OSGI-INF/metatype/metatype.properties
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/index/src/main/resources/OSGI-INF/metatype/metatype.properties?rev=1363343&view=auto
==============================================================================
--- incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/index/src/main/resources/OSGI-INF/metatype/metatype.properties (added)
+++ incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/index/src/main/resources/OSGI-INF/metatype/metatype.properties Thu Jul 19 14:06:30 2012
@@ -0,0 +1,44 @@
+# 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.
+
+#===============================================================================
+#Properties and Options used to configure 
+#===============================================================================
+org.apache.stanbol.contenthub.index.ldpath.LDPathSemanticIndex.name=Apache Stanbol Contenthub LD Path Semantic Index Configuration
+org.apache.stanbol.contenthub.index.ldpath.LDPathSemanticIndex.description=Creates the underlying Solr core by parsing the provided LDPath program
+
+Semantic-Index-Name.name=Name
+Semantic-Index-Name.description=The name identifying the index
+
+Semantic-Index-Description.name=Description
+Semantic-Index-Description.description=Description of the index
+
+org.apache.stanbol.contenthub.index.ldpath.LDPathSemanticIndex.ldPathProgram.name=LDPath Program
+org.apache.stanbol.contenthub.index.ldpath.LDPathSemanticIndex.ldPathProgram.description=LDPath program that will be used as a source to create the semantic index. Index fields and Solr specific configurations regarding those index fields are given in this parameter.
+
+org.apache.stanbol.contenthub.index.ldpath.LDPathSemanticIndex.indexContent.name=Index Content
+org.apache.stanbol.contenthub.index.ldpath.LDPathSemanticIndex.indexContent.description=Set to TRUE to enable indexing content
+
+org.apache.stanbol.contenthub.index.ldpath.LDPathSemanticIndex.batchSize.name=Batch Size
+org.apache.stanbol.contenthub.index.ldpath.LDPathSemanticIndex.batchSize.description=Maximum number of changes to be returned
+
+org.apache.stanbol.contenthub.index.ldpath.LDPathSemanticIndex.storeCheckPeriod.name=Store Check Period
+org.apache.stanbol.contenthub.index.ldpath.LDPathSemanticIndex.storeCheckPeriod.description=Time to check changes in the Contenthub  Store in second units
+
+org.apache.stanbol.contenthub.index.ldpath.LDPathSemanticIndex.solrCheckTime.name=Solr Server Check Time
+org.apache.stanbol.contenthub.index.ldpath.LDPathSemanticIndex.solrCheckTime.description=Maximum time in seconds to wait for the availability of the Solr Server
+
+service.ranking.name=Service Ranking
+service.ranking.description=To be able to use other SemanticIndex implementations rather than this, Service Ranking property of other implementations should be set higher than of this one
\ No newline at end of file

Added: incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/index/src/main/resources/config/org.apache.stanbol.commons.solr.managed.impl.ManagedSolrServerImpl-contenthub.config
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/index/src/main/resources/config/org.apache.stanbol.commons.solr.managed.impl.ManagedSolrServerImpl-contenthub.config?rev=1363343&view=auto
==============================================================================
--- incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/index/src/main/resources/config/org.apache.stanbol.commons.solr.managed.impl.ManagedSolrServerImpl-contenthub.config (added)
+++ incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/index/src/main/resources/config/org.apache.stanbol.commons.solr.managed.impl.ManagedSolrServerImpl-contenthub.config Thu Jul 19 14:06:30 2012
@@ -0,0 +1,3 @@
+org.apache.solr.core.CoreContainer.name="contenthub"
+service.ranking=I"0"
+org.apache.solr.core.CoreContainer.publishREST=B"true"
\ No newline at end of file

Added: incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/index/src/main/resources/config/org.apache.stanbol.contenthub.index.ldpath.LDPathSemanticIndex-default.config
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/index/src/main/resources/config/org.apache.stanbol.contenthub.index.ldpath.LDPathSemanticIndex-default.config?rev=1363343&view=auto
==============================================================================
--- incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/index/src/main/resources/config/org.apache.stanbol.contenthub.index.ldpath.LDPathSemanticIndex-default.config (added)
+++ incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/index/src/main/resources/config/org.apache.stanbol.contenthub.index.ldpath.LDPathSemanticIndex-default.config Thu Jul 19 14:06:30 2012
@@ -0,0 +1,28 @@
+Semantic-Index-Name="contenthub"
+Semantic-Index-Description="Default\ instance\ for\ the\ LDPathSemanticIndex"
+org.apache.stanbol.contenthub.index.ldpath.LDPathSemanticIndex.ldPathProgram="@prefix\ dbp-ont:\ <http://dbpedia.org/ontology/>;\
+@prefix\ dbp-prop:\ <http://dbpedia.org/property/>;\
+@prefix\ foaf\ :\ <http://xmlns.com/foaf/0.1/>;\
+\
+persons\ \=\ .[rdf:type\ is\ dbp-ont:Person]\ ::\ xsd:anyURI\ (termVectors\=\"true\");\
+persons_known_fors\ \=\ dbp-prop:knownFor\ |\ dbp-prop:knownFor/rdfs:label\ ::\ xsd:string;\
+persons_birth_places\ \=\ dbp-ont:birthPlace/rdfs:label\ |\ dbp-prop:placeOfBirth/rdfs:label\ ::\ xsd:string;\
+persons_work_instutions\ \=\ dbp-prop:workInstitutions/rdfs:label\ ::\ xsd:string;\
+\
+organizations\ \=\ .[rdf:type\ is\ dbp-ont:Organization]\ ::\ xsd:anyURI\ (termVectors\=\"true\");\
+\
+places\ \=\ .[rdf:type\ is\ dbp-ont:Place]\ ::\ xsd:anyURI\ (termVectors\=\"true\");\
+place_countries\ \=\ dbp-ont:country/rdfs:label\ ::\ xsd:string;\
+place_regions\ \=\ dbp-ont:region/rdfs:label\ |\ ^dbp-ont:region/rdfs:label\ |\ dbp-prop:region/rdfs:label\ |\ ^dbp-prop:region/rdfs:label::\ xsd:string;\
+place_capitals\ \=\ dbp-ont:capital/rdfs:label\ ::\ xsd:string;\
+place_governors\ \=\ dbp-prop:governer/rdfs:label\ ::\ xsd:string;\
+place_largest_cities\ \=\ dbp-ont:largestCity/rdfs:label\ ::\ xsd:string;\
+place_leaders\ \=\ dbp-prop:leaderName/rdfs:label\ |\ dbp-ont:leader/rdfs:label\ ::\ xsd:string;\
+\
+entity_given_names\ \=\ foaf:givenName\ ::\ xsd:string;\
+entity_captions\ \=\ dbp-prop:caption\ ::\ xsd:string;"
+org.apache.stanbol.contenthub.index.ldpath.LDPathSemanticIndex.indexContent=B"true"
+org.apache.stanbol.contenthub.index.ldpath.LDPathSemanticIndex.batchSize=I"10"
+org.apache.stanbol.contenthub.index.ldpath.LDPathSemanticIndex.storeCheckPeriod=I"5"
+org.apache.stanbol.contenthub.index.ldpath.LDPathSemanticIndex.solrCheckTime=I"5"
+service.ranking=I"0"
\ No newline at end of file

Added: incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/index/src/main/resources/solr/conf/solr.xml
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/index/src/main/resources/solr/conf/solr.xml?rev=1363343&view=auto
==============================================================================
--- incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/index/src/main/resources/solr/conf/solr.xml (added)
+++ incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/index/src/main/resources/solr/conf/solr.xml Thu Jul 19 14:06:30 2012
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+ 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.
+-->
+
+<!--
+ SolrYard Configuration for the internally managed Embedded SolrServer:
+
+ By default no cores are defined by this configuration because they are added
+ at runtime via the Java API
+-->
+<solr persistent="false">
+  <cores adminPath="/admin/cores">
+    <!-- Cores are added dynamically at runtime -->
+  </cores>
+</solr>

Added: incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/index/src/main/resources/solr/core/template.zip
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/index/src/main/resources/solr/core/template.zip?rev=1363343&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/index/src/main/resources/solr/core/template.zip
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Modified: incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/pom.xml
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/pom.xml?rev=1363343&r1=1363342&r2=1363343&view=diff
==============================================================================
--- incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/pom.xml (original)
+++ incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/pom.xml Thu Jul 19 14:06:30 2012
@@ -39,12 +39,13 @@
     <module>parent</module>
     <module>servicesapi</module>
     <module>store/file</module>
-<!--     <module>store/solr</module> -->
-<!--     <module>search</module> -->
+    <module>search/solr</module>
+    <module>search/featured</module>
+    <module>search/related</module>
+    <module>index</module>
     <module>web</module>
-    <module>bundlelist</module>
-<!--     <module>index</module> -->
     <module>test</module>
+    <module>bundlelist</module>
   </modules>
 
-</project>
+</project>  	

Modified: incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/search/featured/pom.xml
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/search/featured/pom.xml?rev=1363343&r1=1363342&r2=1363343&view=diff
==============================================================================
--- incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/search/featured/pom.xml (original)
+++ incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/search/featured/pom.xml Thu Jul 19 14:06:30 2012
@@ -17,7 +17,7 @@
   <parent>
     <groupId>org.apache.stanbol</groupId>
     <artifactId>org.apache.stanbol.contenthub.parent</artifactId>
-    <version>0.9.0-incubating-SNAPSHOT</version>
+    <version>0.10.0-incubating-SNAPSHOT</version>
     <relativePath>../../parent</relativePath>
   </parent>
 
@@ -44,14 +44,22 @@
     <dependency>
       <groupId>org.apache.stanbol</groupId>
       <artifactId>org.apache.stanbol.contenthub.servicesapi</artifactId>
+      <version>0.10.0-incubating-SNAPSHOT</version>
     </dependency>
     <dependency>
       <groupId>org.apache.stanbol</groupId>
       <artifactId>org.apache.stanbol.contenthub.store.solr</artifactId>
+      <version>0.10.0-incubating-SNAPSHOT</version>
+    </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.search.solr</artifactId>
+      <version>0.10.0-incubating-SNAPSHOT</version>
     </dependency>
     <dependency>
       <groupId>org.apache.felix</groupId>

Modified: incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/search/featured/src/main/java/org/apache/stanbol/contenthub/search/featured/FacetResultImpl.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/search/featured/src/main/java/org/apache/stanbol/contenthub/search/featured/FacetResultImpl.java?rev=1363343&r1=1363342&r2=1363343&view=diff
==============================================================================
--- incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/search/featured/src/main/java/org/apache/stanbol/contenthub/search/featured/FacetResultImpl.java (original)
+++ incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/search/featured/src/main/java/org/apache/stanbol/contenthub/search/featured/FacetResultImpl.java Thu Jul 19 14:06:30 2012
@@ -24,31 +24,31 @@ import org.apache.stanbol.contenthub.ser
 
 public class FacetResultImpl implements FacetResult {
 
-	private FacetField facetField;
+    private FacetField facetField;
 
-	private String type;
+    private String type;
 
-	public FacetResultImpl(FacetField facetField) {
-		this.facetField = facetField;
-		this.type = "UNKNOWN";
-	}
-	
-	public FacetResultImpl(FacetField facetField, String type) {
-		this.facetField = facetField;
-		this.type = type;
-	}
-
-	@Override
-	public FacetField getFacetField() {
-		return this.facetField;
-	}
-
-	@Override
-	public String getType() {
-		return this.type;
-	}
-	
-	public String getHtmlName() {
+    public FacetResultImpl(FacetField facetField) {
+        this.facetField = facetField;
+        this.type = "UNKNOWN";
+    }
+
+    public FacetResultImpl(FacetField facetField, String type) {
+        this.facetField = facetField;
+        this.type = type;
+    }
+
+    @Override
+    public FacetField getFacetField() {
+        return this.facetField;
+    }
+
+    @Override
+    public String getType() {
+        return this.type;
+    }
+
+    public String getHtmlName() {
         String name = getFacetField().getName();
         if (name.startsWith(STANBOLRESERVED_PREFIX)) {
             return name.substring(STANBOLRESERVED_PREFIX.length());

Modified: incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/search/featured/src/main/java/org/apache/stanbol/contenthub/search/featured/FeaturedSearchImpl.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/search/featured/src/main/java/org/apache/stanbol/contenthub/search/featured/FeaturedSearchImpl.java?rev=1363343&r1=1363342&r2=1363343&view=diff
==============================================================================
--- incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/search/featured/src/main/java/org/apache/stanbol/contenthub/search/featured/FeaturedSearchImpl.java (original)
+++ incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/search/featured/src/main/java/org/apache/stanbol/contenthub/search/featured/FeaturedSearchImpl.java Thu Jul 19 14:06:30 2012
@@ -31,39 +31,34 @@ import org.apache.clerezza.rdf.core.Lite
 import org.apache.clerezza.rdf.core.MGraph;
 import org.apache.clerezza.rdf.core.Resource;
 import org.apache.clerezza.rdf.core.Triple;
-import org.apache.felix.scr.annotations.Activate;
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Reference;
 import org.apache.felix.scr.annotations.Service;
 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.response.FacetField;
 import org.apache.solr.client.solrj.response.QueryResponse;
 import org.apache.solr.common.SolrDocument;
 import org.apache.solr.common.params.SolrParams;
-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.index.ldpath.LDPathSemanticIndex;
 import org.apache.stanbol.contenthub.search.solr.util.SolrQueryUtil;
 import org.apache.stanbol.contenthub.servicesapi.Constants;
+import org.apache.stanbol.contenthub.servicesapi.index.IndexException;
+import org.apache.stanbol.contenthub.servicesapi.index.IndexManagementException;
+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.DocumentResult;
 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.RelatedKeyword;
 import org.apache.stanbol.contenthub.servicesapi.index.search.related.RelatedKeywordSearchManager;
 import org.apache.stanbol.contenthub.servicesapi.index.search.solr.SolrSearch;
-import org.apache.stanbol.contenthub.servicesapi.store.StoreException;
-import org.apache.stanbol.contenthub.store.solr.manager.SolrCoreManager;
+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.EnhancementException;
 import org.apache.stanbol.enhancer.servicesapi.EnhancementJobManager;
-import org.apache.stanbol.enhancer.servicesapi.helper.InMemoryContentItem;
+import org.apache.stanbol.enhancer.servicesapi.impl.ByteArraySource;
 import org.apache.stanbol.enhancer.servicesapi.rdf.Properties;
-import org.osgi.framework.BundleContext;
-import org.osgi.service.component.ComponentContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -102,25 +97,23 @@ public class FeaturedSearchImpl implemen
     private SolrSearch solrSearch;
 
     @Reference
-    private RelatedKeywordSearchManager relatedKeywordSearchManager;
+    private SemanticIndexManager semanticIndexManager;
 
     @Reference
-    private ManagedSolrServer managedSolrServer;
+    private RelatedKeywordSearchManager relatedKeywordSearchManager;
 
     @Reference
     private EnhancementJobManager enhancementJobManager;
 
-    private BundleContext bundleContext;
-
-    @Activate
-    public void activate(ComponentContext context) {
-        this.bundleContext = context.getBundleContext();
-    }
+    @Reference
+    private ContentItemFactory contentItemFactory;
 
-    @Override
-    public SearchResult search(String queryTerm) throws SearchException {
-        return search(queryTerm, null, null);
-    }
+    // private BundleContext bundleContext;
+    //
+    // @Activate
+    // public void activate(ComponentContext context) {
+    // this.bundleContext = context.getBundleContext();
+    // }
 
     private List<FacetResult> convertFacetFields(List<FacetField> facetFields, List<FacetResult> allFacets) {
         List<FacetResult> facets = new ArrayList<FacetResult>();
@@ -145,20 +138,22 @@ public class FeaturedSearchImpl implemen
     }
 
     @Override
-    public SearchResult search(String queryTerm, String ontologyURI, String ldProgramName) throws SearchException {
-        QueryResponse queryResponse = solrSearch.search(queryTerm, ldProgramName);
-        return search(queryTerm, queryResponse, ontologyURI, ldProgramName, null);
+    public SearchResult search(String queryTerm, String ontologyURI, String indexName) throws SearchException {
+        QueryResponse queryResponse = solrSearch.search(queryTerm, indexName);
+        return search(queryTerm, queryResponse, ontologyURI, indexName, null);
     }
 
     private SearchResult search(String queryTerm,
                                 QueryResponse queryResponse,
                                 String ontologyURI,
-                                String ldProgramName,
+                                String indexName,
                                 List<FacetResult> allFacets) throws SearchException {
-        List<DocumentResult> resultantDocuments = new ArrayList<DocumentResult>();
+        List<String> resultantDocuments = new ArrayList<String>();
         for (SolrDocument solrDocument : queryResponse.getResults()) {
-            resultantDocuments.add(SolrContentItemConverter.solrDocument2solrContentItem(solrDocument,
-                ldProgramName));
+            Object uri = solrDocument.getFieldValue(SolrFieldName.ID.toString());
+            if (uri != null) {
+                resultantDocuments.add(uri.toString());
+            }
         }
         Map<String,Map<String,List<RelatedKeyword>>> relatedKeywords = new HashMap<String,Map<String,List<RelatedKeyword>>>();
         List<String> queryTerms = tokenizeEntities(queryTerm);
@@ -172,75 +167,53 @@ public class FeaturedSearchImpl implemen
     }
 
     @Override
-    public SearchResult search(SolrParams solrQuery) throws SearchException {
-        return search(solrQuery, null, null);
-    }
-
-    @Override
-    public SearchResult search(SolrParams solrParams, String ontologyURI, String ldProgramName) throws SearchException {
+    public SearchResult search(SolrParams solrParams, String ontologyURI, String indexName) throws SearchException {
         /*
          * RESTful services uses search method with "SolrParams" argument. For those operations
          */
         SolrQuery solrQuery = new SolrQuery();
         solrQuery.add(solrParams);
-        List<FacetResult> allFacets = getAllFacetResults(ldProgramName);
+        List<FacetResult> allFacets = getAllFacetResults(indexName);
         SolrQueryUtil.setDefaultQueryParameters(solrQuery, allFacets);
-        QueryResponse queryResponse = solrSearch.search(solrQuery, ldProgramName);
+        QueryResponse queryResponse = solrSearch.search(solrQuery, indexName);
         String queryTerm = SolrQueryUtil.extractQueryTermFromSolrQuery(solrParams);
-        return search(queryTerm, queryResponse, ontologyURI, ldProgramName, allFacets);
-    }
-
-    @Override
-    public List<FacetResult> getAllFacetResults() throws SearchException {
-        return getAllFacetResults(null);
+        return search(queryTerm, queryResponse, ontologyURI, indexName, allFacets);
     }
 
     @Override
-    public List<FacetResult> getAllFacetResults(String ldProgramName) throws SearchException {
-        SolrServer solrServer = getSolrServer(ldProgramName);
+    public List<FacetResult> getAllFacetResults(String indexName) throws SearchException {
+        LDPathSemanticIndex semanticIndex = null;
+        try {
+            semanticIndex = (LDPathSemanticIndex) semanticIndexManager.getIndex(indexName);
+        } catch (IndexManagementException e) {
+            log.error("Failed to get index {}", indexName, e);
+            throw new SearchException("Failed to get index " + indexName, e);
+        }
         List<FacetResult> facetResults = new ArrayList<FacetResult>();
-        NamedList<Object> fieldsList;
+        List<String> fieldsNames = new ArrayList<String>();
         try {
-            fieldsList = SolrQueryUtil.getAllFacetFields(solrServer);
-            for (int i = 0; i < fieldsList.size(); i++) {
-                String fn = fieldsList.getName(i);
-                @SuppressWarnings("unchecked")
-                NamedList<Object> values = (NamedList<Object>) fieldsList.getVal(i);
-                String type = (String) values.get("type");
+            fieldsNames = semanticIndex.getFieldsNames();
+            for (int i = 0; i < fieldsNames.size(); i++) {
+                String fn = fieldsNames.get(i);
+                String type = (String) semanticIndex.getFieldProperties(fn).get("type");
                 facetResults.add(new FacetResultImpl(new FacetField(fn), type.trim()));
             }
-        } catch (SolrServerException e) {
-            String msg = "SolrSearchImpl.getFacetNames: Failed to execute solr query";
-            log.error(msg, e);
-            throw new SearchException(msg, e);
-        } catch (IOException e) {
+        } catch (IndexException e) {
+            log.error(e.getMessage(), e);
             throw new SearchException(e.getMessage(), e);
         }
 
         return facetResults;
     }
 
-    private SolrServer getSolrServer(String ldProgramName) throws SearchException {
-        try {
-            SolrServer solrServer = SolrCoreManager.getInstance(bundleContext, managedSolrServer).getServer(
-                ldProgramName);
-            return solrServer;
-        } catch (StoreException e) {
-            String msg = String
-                    .format("SolrSearchImpl.getFacetNames: Failed to obtain solr server for ldprogram: %s",
-                        ldProgramName);
-            log.error(msg, e);
-            throw new SearchException(msg, e);
-        }
-    }
-
     @Override
     public List<String> tokenizeEntities(String queryTerm) {
         // obtain entities about query term through Enhancer
         ContentItem ci = null;
         boolean error = false;
         try {
-            ci = new InMemoryContentItem(queryTerm.getBytes(Constants.DEFAULT_ENCODING), "text/plain");
+            ci = contentItemFactory.createContentItem(new ByteArraySource(queryTerm
+                    .getBytes(Constants.DEFAULT_ENCODING), "text/plain"));
             enhancementJobManager.enhanceContent(ci);
         } catch (UnsupportedEncodingException e) {
             log.error("Failed to get bytes of query term: {}", queryTerm, e);
@@ -248,6 +221,9 @@ public class FeaturedSearchImpl implemen
         } catch (EnhancementException e) {
             log.error("Failed to get enmancements for the query term: {}", queryTerm, e);
             error = true;
+        } catch (IOException e) {
+            log.error("Failed to get bytes of query term: {}", queryTerm, e);
+            error = true;
         }
 
         List<String> tokenizedTerms = new ArrayList<String>();

Modified: incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/search/featured/src/main/java/org/apache/stanbol/contenthub/search/featured/FeaturedSearchResult.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/search/featured/src/main/java/org/apache/stanbol/contenthub/search/featured/FeaturedSearchResult.java?rev=1363343&r1=1363342&r2=1363343&view=diff
==============================================================================
--- incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/search/featured/src/main/java/org/apache/stanbol/contenthub/search/featured/FeaturedSearchResult.java (original)
+++ incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/search/featured/src/main/java/org/apache/stanbol/contenthub/search/featured/FeaturedSearchResult.java Thu Jul 19 14:06:30 2012
@@ -19,18 +19,17 @@ package org.apache.stanbol.contenthub.se
 import java.util.List;
 import java.util.Map;
 
-import org.apache.stanbol.contenthub.servicesapi.index.search.featured.DocumentResult;
 import org.apache.stanbol.contenthub.servicesapi.index.search.featured.FacetResult;
 import org.apache.stanbol.contenthub.servicesapi.index.search.featured.SearchResult;
 import org.apache.stanbol.contenthub.servicesapi.index.search.related.RelatedKeyword;
 
 public class FeaturedSearchResult implements SearchResult {
 
-    private List<DocumentResult> documentResults;
+    private List<String> documentResults;
     private List<FacetResult> facetResults;
     private Map<String,Map<String,List<RelatedKeyword>>> relatedKeywords;
 
-    public FeaturedSearchResult(List<DocumentResult> documentResults,
+    public FeaturedSearchResult(List<String> documentResults,
                                 List<FacetResult> facetResults,
                                 Map<String,Map<String,List<RelatedKeyword>>> relatedKeywords) {
         this.documentResults = documentResults;
@@ -39,7 +38,7 @@ public class FeaturedSearchResult implem
     }
 
     @Override
-    public List<DocumentResult> getDocuments() {
+    public List<String> getDocuments() {
         return this.documentResults;
     }
 
@@ -54,7 +53,7 @@ public class FeaturedSearchResult implem
     }
 
     @Override
-    public void setDocuments(List<DocumentResult> documentresults) {
+    public void setDocuments(List<String> documentresults) {
         this.documentResults = documentresults;
     }
 

Modified: incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/search/related/pom.xml
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/search/related/pom.xml?rev=1363343&r1=1363342&r2=1363343&view=diff
==============================================================================
--- incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/search/related/pom.xml (original)
+++ incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/search/related/pom.xml Thu Jul 19 14:06:30 2012
@@ -17,7 +17,7 @@
   <parent>
     <groupId>org.apache.stanbol</groupId>
     <artifactId>org.apache.stanbol.contenthub.parent</artifactId>
-    <version>0.9.0-incubating-SNAPSHOT</version>
+    <version>0.10.0-incubating-SNAPSHOT</version>
     <relativePath>../../parent</relativePath>
   </parent>
 
@@ -52,10 +52,12 @@ Finds related keywords from various type
     <dependency>
       <groupId>org.apache.stanbol</groupId>
       <artifactId>org.apache.stanbol.entityhub.model.clerezza</artifactId>
+      <version>0.11.0-incubating-SNAPSHOT</version>
     </dependency>
     <dependency>
       <groupId>org.apache.stanbol</groupId>
       <artifactId>org.apache.stanbol.contenthub.servicesapi</artifactId>
+      <version>0.10.0-incubating-SNAPSHOT</version>
     </dependency>
     <dependency>
       <groupId>org.apache.felix</groupId>
@@ -91,6 +93,7 @@ Finds related keywords from various type
     <dependency>
       <groupId>edu.smu.tspell</groupId>
       <artifactId>jaws</artifactId>
+      <version>1.2</version>
     </dependency>
   </dependencies>
 

Modified: incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/search/related/src/main/java/org/apache/stanbol/contenthub/search/related/RelatedKeywordSearchResult.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/search/related/src/main/java/org/apache/stanbol/contenthub/search/related/RelatedKeywordSearchResult.java?rev=1363343&r1=1363342&r2=1363343&view=diff
==============================================================================
--- incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/search/related/src/main/java/org/apache/stanbol/contenthub/search/related/RelatedKeywordSearchResult.java (original)
+++ incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/search/related/src/main/java/org/apache/stanbol/contenthub/search/related/RelatedKeywordSearchResult.java Thu Jul 19 14:06:30 2012
@@ -19,8 +19,6 @@ package org.apache.stanbol.contenthub.se
 import java.util.List;
 import java.util.Map;
 
-import org.apache.commons.lang.NotImplementedException;
-import org.apache.stanbol.contenthub.servicesapi.index.search.featured.DocumentResult;
 import org.apache.stanbol.contenthub.servicesapi.index.search.featured.FacetResult;
 import org.apache.stanbol.contenthub.servicesapi.index.search.featured.SearchResult;
 import org.apache.stanbol.contenthub.servicesapi.index.search.related.RelatedKeyword;
@@ -42,7 +40,7 @@ public class RelatedKeywordSearchResult 
     }
 
     @Override
-    public List<DocumentResult> getDocuments() {
+    public List<String> getDocuments() {
         log.warn("RelatedKeywordSearchResult does not contain any ResultantDocument");
         return null;
     }
@@ -59,17 +57,17 @@ public class RelatedKeywordSearchResult 
     }
 
     @Override
-    public void setDocuments(List<DocumentResult> resultantDocuments) {
-        String msg = "RelatedKeywordSearchResult cannot contain any ResultantDocument";
-        log.error(msg);
-        throw new NotImplementedException(msg);
+    public void setDocuments(List<String> resultantDocuments) {
+        // String msg = "RelatedKeywordSearchResult cannot contain any ResultantDocument";
+        // log.error(msg);
+        // throw new NotImplementedException(msg);
     }
 
     @Override
     public void setFacets(List<FacetResult> facets) {
-        String msg = "RelatedKeywordSearchResult cannot contain any FacetField";
-        log.error(msg);
-        throw new NotImplementedException(msg);
+        // String msg = "RelatedKeywordSearchResult cannot contain any FacetField";
+        // log.error(msg);
+        // throw new NotImplementedException(msg);
     }
 
     @Override

Modified: incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/search/solr/pom.xml
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/search/solr/pom.xml?rev=1363343&r1=1363342&r2=1363343&view=diff
==============================================================================
--- incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/search/solr/pom.xml (original)
+++ incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/search/solr/pom.xml Thu Jul 19 14:06:30 2012
@@ -17,7 +17,7 @@
   <parent>
     <groupId>org.apache.stanbol</groupId>
     <artifactId>org.apache.stanbol.contenthub.parent</artifactId>
-    <version>0.9.0-incubating-SNAPSHOT</version>
+    <version>0.10.0-incubating-SNAPSHOT</version>
     <relativePath>../../parent</relativePath>
   </parent>
 
@@ -44,14 +44,17 @@
     <dependency>
       <groupId>org.apache.stanbol</groupId>
       <artifactId>org.apache.stanbol.contenthub.servicesapi</artifactId>
+      <version>0.10.0-incubating-SNAPSHOT</version>
     </dependency>
     <dependency>
       <groupId>org.apache.stanbol</groupId>
       <artifactId>org.apache.stanbol.contenthub.store.solr</artifactId>
+      <version>0.10.0-incubating-SNAPSHOT</version>
     </dependency>
     <dependency>
       <groupId>org.apache.stanbol</groupId>
-      <artifactId>org.apache.stanbol.commons.solr.managed</artifactId>
+      <artifactId>org.apache.stanbol.contenthub.index</artifactId>
+      <version>0.10.0-incubating-SNAPSHOT</version>
     </dependency>
     <dependency>
       <groupId>org.apache.felix</groupId>

Modified: incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/search/solr/src/main/java/org/apache/stanbol/contenthub/search/solr/SolrSearchImpl.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/search/solr/src/main/java/org/apache/stanbol/contenthub/search/solr/SolrSearchImpl.java?rev=1363343&r1=1363342&r2=1363343&view=diff
==============================================================================
--- incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/search/solr/src/main/java/org/apache/stanbol/contenthub/search/solr/SolrSearchImpl.java (original)
+++ incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/search/solr/src/main/java/org/apache/stanbol/contenthub/search/solr/SolrSearchImpl.java Thu Jul 19 14:06:30 2012
@@ -18,7 +18,6 @@ package org.apache.stanbol.contenthub.se
 
 import java.io.IOException;
 
-import org.apache.felix.scr.annotations.Activate;
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Reference;
 import org.apache.felix.scr.annotations.Service;
@@ -27,14 +26,13 @@ import org.apache.solr.client.solrj.Solr
 import org.apache.solr.client.solrj.SolrServerException;
 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.index.ldpath.LDPathSemanticIndex;
 import org.apache.stanbol.contenthub.search.solr.util.SolrQueryUtil;
+import org.apache.stanbol.contenthub.servicesapi.index.IndexException;
+import org.apache.stanbol.contenthub.servicesapi.index.IndexManagementException;
+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.solr.SolrSearch;
-import org.apache.stanbol.contenthub.servicesapi.store.StoreException;
-import org.apache.stanbol.contenthub.store.solr.manager.SolrCoreManager;
-import org.osgi.framework.BundleContext;
-import org.osgi.service.component.ComponentContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -45,74 +43,53 @@ public class SolrSearchImpl implements S
     private static final Logger log = LoggerFactory.getLogger(SolrSearchImpl.class);
 
     @Reference
-    private ManagedSolrServer managedSolrServer;
-
-    private BundleContext bundleContext;
-
-    @Activate
-    public void activate(ComponentContext context) {
-        this.bundleContext = context.getBundleContext();
-    }
+    private SemanticIndexManager semanticIndexManager;
 
     @Override
-    public QueryResponse search(String queryTerm) throws SearchException {
+    public QueryResponse search(String queryTerm, String indexName) throws SearchException {
+        // By default solr query, we perform a faceted search when a keyword is supplied. To customize the
+        // search
+        // please use the method which accepts SolrParams/SolrQuery
         SolrQuery solrQuery = null;
         SolrServer solrServer = null;
         try {
-            solrServer = SolrCoreManager.getInstance(bundleContext, managedSolrServer).getServer();
-            solrQuery = SolrQueryUtil.prepareDefaultSolrQuery(solrServer, queryTerm);
-        } catch (StoreException e) {
-            throw new SearchException(e.getMessage(), e);
+            LDPathSemanticIndex semanticIndex = (LDPathSemanticIndex) semanticIndexManager
+                    .getIndex(indexName);
+            solrServer = semanticIndex.getServer();
+            solrQuery = SolrQueryUtil.prepareSolrQuery(solrServer, queryTerm);
         } catch (SolrServerException e) {
-            throw new SearchException(e.getMessage(), e);
+            log.error("Failed to prepare default solr query");
+            throw new SearchException("Failed to prepare default solr query", e);
         } catch (IOException e) {
+            log.error("Failed to prepare default solr query");
+            throw new SearchException("Failed to prepare default solr query", e);
+        } catch (IndexException e) {
+            log.error(e.getMessage(), e);
+            throw new SearchException(e.getMessage(), e);
+        } catch (IndexManagementException e) {
+            log.error(e.getMessage(), e);
             throw new SearchException(e.getMessage(), e);
         }
         return executeSolrQuery(solrServer, solrQuery);
     }
 
     @Override
-    public QueryResponse search(String queryTerm, String ldProgramName) throws SearchException {
-        // By default solr query, we perform a faceted search when a keyword is supplied. To customize the search
-        // please use the method which accepts SolrParams/SolrQuery
-        SolrQuery solrQuery = null;
+    public QueryResponse search(SolrParams solrQuery, String indexName) throws SearchException {
         SolrServer solrServer = null;
         try {
-            solrServer = SolrCoreManager.getInstance(bundleContext, managedSolrServer).getServer(ldProgramName);
-            solrQuery = SolrQueryUtil.prepareDefaultSolrQuery(solrServer, queryTerm);
-        } catch (StoreException e) {
-            throw new SearchException(e.getMessage(), e);
-        } catch (SolrServerException e) {
+            LDPathSemanticIndex semanticIndex = (LDPathSemanticIndex) semanticIndexManager
+                    .getIndex(indexName);
+            solrServer = semanticIndex.getServer();
+        } catch (IndexManagementException e) {
+            log.error(e.getMessage(), e);
             throw new SearchException(e.getMessage(), e);
-        } catch (IOException e) {
+        } catch (IndexException e) {
+            log.error(e.getMessage(), e);
             throw new SearchException(e.getMessage(), e);
         }
         return executeSolrQuery(solrServer, solrQuery);
     }
 
-    @Override
-    public QueryResponse search(SolrParams solrQuery) throws SearchException {
-        SolrServer solrServer = null;
-        try {
-            solrServer = SolrCoreManager.getInstance(bundleContext, managedSolrServer).getServer();
-        } catch (StoreException e) {
-            throw new SearchException(e);
-        }
-        return executeSolrQuery(solrServer, solrQuery);
-    }
-
-    @Override
-    public QueryResponse search(SolrParams solrQuery, String ldProgramName) throws SearchException {
-        SolrServer solrServer = null;
-        try {
-            solrServer = SolrCoreManager.getInstance(bundleContext, managedSolrServer).getServer(
-                ldProgramName);
-        } catch (StoreException e) {
-            throw new SearchException(e);
-        }
-        return executeSolrQuery(solrServer, solrQuery);
-    }
-
     private QueryResponse executeSolrQuery(SolrServer solrServer, SolrParams solrQuery) throws SearchException {
         try {
             return solrServer.query(solrQuery);

Modified: incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/search/solr/src/main/java/org/apache/stanbol/contenthub/search/solr/util/SolrQueryUtil.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/search/solr/src/main/java/org/apache/stanbol/contenthub/search/solr/util/SolrQueryUtil.java?rev=1363343&r1=1363342&r2=1363343&view=diff
==============================================================================
--- incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/search/solr/src/main/java/org/apache/stanbol/contenthub/search/solr/util/SolrQueryUtil.java (original)
+++ incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/search/solr/src/main/java/org/apache/stanbol/contenthub/search/solr/util/SolrQueryUtil.java Thu Jul 19 14:06:30 2012
@@ -58,15 +58,17 @@ public class SolrQueryUtil {
     public final static List<Character> queryDelimiters = Arrays.asList(' ', ',');
 
     private static String getFacetFieldType(String fieldName, List<FacetResult> allAvailableFacets) {
-    	for(FacetResult fr : allAvailableFacets) {
-    		if(fieldName.equals(fr.getFacetField().getName())) {
-    			return fr.getType();
-    		}
-    	}
-    	return "";
+        for (FacetResult fr : allAvailableFacets) {
+            if (fieldName.equals(fr.getFacetField().getName())) {
+                return fr.getType();
+            }
+        }
+        return "";
     }
-    
-    private static SolrQuery keywordQueryWithFacets(String keyword, List<FacetResult> allAvailableFacets, Map<String,List<Object>> constraints) {
+
+    private static SolrQuery keywordQueryWithFacets(String keyword,
+                                                    List<FacetResult> allAvailableFacets,
+                                                    Map<String,List<Object>> constraints) {
         SolrQuery query = new SolrQuery();
         query.setQuery(keyword);
         if (constraints != null) {
@@ -158,29 +160,30 @@ public class SolrQueryUtil {
                 } else {
                     facetName = facet.toString();
                 }
-                if (SolrFieldName.CREATIONDATE.toString().equals(facetName)
-                    || (!SolrFieldName.isNameReserved(facetName) && !SolrVocabulary.isNameExcluded(facetName))) {
+                if (!SolrFieldName.isNameReserved(facetName) && !SolrVocabulary.isNameExcluded(facetName)) {
                     solrQuery.addFacetField(facetName);
                 }
             }
         }
     }
 
-    public static SolrQuery prepareDefaultSolrQuery(SolrServer solrServer, String queryTerm) throws SolrServerException,
-                                                                                            IOException {
+    public static SolrQuery prepareSolrQuery(SolrServer solrServer, String queryTerm) throws SolrServerException,
+                                                                                     IOException {
         SolrQuery solrQuery = new SolrQuery();
         solrQuery.setQuery(queryTerm);
         setDefaultQueryParameters(solrQuery, getAllFacetNames(solrServer));
         return solrQuery;
     }
 
-    public static SolrQuery prepareDefaultSolrQuery(String queryTerm) {
+    public static SolrQuery prepareSolrQuery(String queryTerm) {
         SolrQuery solrQuery = new SolrQuery();
         solrQuery.setQuery(queryTerm);
         return solrQuery;
     }
 
-    public static SolrQuery prepareFacetedSolrQuery(String queryTerm, List<FacetResult> allAvailableFacets, Map<String,List<Object>> constraints) {
+    public static SolrQuery prepareSolrQuery(String queryTerm,
+                                             List<FacetResult> allAvailableFacets,
+                                             Map<String,List<Object>> constraints) {
         SolrQuery solrQuery = keywordQueryWithFacets(queryTerm, allAvailableFacets, constraints);
         return solrQuery;
     }

Modified: incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/servicesapi/pom.xml
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/servicesapi/pom.xml?rev=1363343&r1=1363342&r2=1363343&view=diff
==============================================================================
--- incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/servicesapi/pom.xml (original)
+++ incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/servicesapi/pom.xml Thu Jul 19 14:06:30 2012
@@ -45,7 +45,7 @@
     <dependency>
       <groupId>org.apache.stanbol</groupId>
       <artifactId>org.apache.stanbol.entityhub.servicesapi</artifactId>
-      <version>0.10.1-incubating-SNAPSHOT</version>
+      <version>0.11.0-incubating-SNAPSHOT</version>
     </dependency>
     <dependency>
       <groupId>org.apache.solr</groupId>

Modified: incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/servicesapi/src/main/java/org/apache/stanbol/contenthub/servicesapi/index/EndpointType.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/EndpointType.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/EndpointType.java (original)
+++ incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/servicesapi/src/main/java/org/apache/stanbol/contenthub/servicesapi/index/EndpointType.java Thu Jul 19 14:06:30 2012
@@ -1,18 +1,28 @@
 package org.apache.stanbol.contenthub.servicesapi.index;
 
+/**
+ * Possible REST endpoint types for search operations offered by {@link SemanticIndex}.
+ * 
+ */
 public enum EndpointType {
-    SOLR
-    ;
-    
+    /**
+     * RESTful endpoint of the Solr
+     */
+    SOLR,
+    /**
+     * RESTful search endpoint specific to the Contenthub
+     */
+    CONTENTHUB;
+
     private static final String prefix = "http://stanbol.apache.org/ontology/contenthub#endpointType_";
-    
+
     public String getUri() {
-    	return prefix+name().toLowerCase();
-	}
+        return prefix + name().toLowerCase();
+    }
 
     @Override
     public String toString() {
-    	return getUri();
+        return getUri();
     }
 
 }