Search in sources :

Example 26 with SolrServer

use of org.apache.solr.client.solrj.SolrServer in project jackrabbit-oak by apache.

the class FullTextSolrSearchTest method createEmbeddedSolrServerProvider.

private EmbeddedSolrServerProvider createEmbeddedSolrServerProvider(boolean http) throws Exception {
    String tempDirectoryPath = FileUtils.getTempDirectoryPath();
    File solrHome = new File(tempDirectoryPath, "solr" + System.nanoTime());
    EmbeddedSolrServerConfiguration embeddedSolrServerConfiguration = new EmbeddedSolrServerConfiguration(solrHome.getAbsolutePath(), "oak");
    if (http) {
        embeddedSolrServerConfiguration = embeddedSolrServerConfiguration.withHttpConfiguration("/solr", 8983);
    }
    EmbeddedSolrServerProvider embeddedSolrServerProvider = embeddedSolrServerConfiguration.getProvider();
    SolrServer solrServer = embeddedSolrServerProvider.getSolrServer();
    if (storageEnabled != null && !storageEnabled) {
        // change schema.xml and reload the core
        File schemaXML = new File(solrHome.getAbsolutePath() + "/oak/conf", "schema.xml");
        InputStream inputStream = getClass().getResourceAsStream("/solr/oak/conf/schema.xml");
        String schemaString = IOUtils.toString(inputStream).replace("<dynamicField name=\"*\" type=\"text_general\" indexed=\"true\" stored=\"true\" multiValued=\"true\"/>", "<dynamicField name=\"*\" type=\"text_general\" indexed=\"true\" stored=\"false\" multiValued=\"true\"/>");
        FileOutputStream fileOutputStream = new FileOutputStream(schemaXML);
        IOUtils.copy(new StringReader(schemaString), fileOutputStream);
        fileOutputStream.flush();
        ((EmbeddedSolrServer) solrServer).getCoreContainer().reload("oak");
    }
    return embeddedSolrServerProvider;
}
Also used : EmbeddedSolrServerConfiguration(org.apache.jackrabbit.oak.plugins.index.solr.configuration.EmbeddedSolrServerConfiguration) EmbeddedSolrServerProvider(org.apache.jackrabbit.oak.plugins.index.solr.server.EmbeddedSolrServerProvider) InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) StringReader(java.io.StringReader) File(java.io.File) EmbeddedSolrServer(org.apache.solr.client.solrj.embedded.EmbeddedSolrServer) SolrServer(org.apache.solr.client.solrj.SolrServer)

Example 27 with SolrServer

use of org.apache.solr.client.solrj.SolrServer in project jackrabbit-oak by apache.

the class SolrIndexEditorTest method testIgnoredPropertiesNotIndexed.

@Test
public void testIgnoredPropertiesNotIndexed() throws Exception {
    NodeBuilder builder = mock(NodeBuilder.class);
    SolrServer solrServer = TestUtils.createSolrServer();
    OakSolrConfiguration configuration = new DefaultSolrConfiguration() {

        @Nonnull
        @Override
        public Collection<String> getIgnoredProperties() {
            return Arrays.asList("foo2");
        }

        @Nonnull
        @Override
        public CommitPolicy getCommitPolicy() {
            return CommitPolicy.HARD;
        }
    };
    IndexUpdateCallback callback = mock(IndexUpdateCallback.class);
    SolrIndexEditor solrIndexEditor = new SolrIndexEditor(solrServer, configuration, callback);
    NodeState before = mock(NodeState.class);
    NodeState after = mock(NodeState.class);
    Iterable properties = new Iterable<PropertyState>() {

        @Override
        public Iterator<PropertyState> iterator() {
            return Arrays.asList(PropertyStates.createProperty("foo2", "bar")).iterator();
        }
    };
    when(after.getProperties()).thenReturn(properties);
    solrIndexEditor.leave(before, after);
    QueryResponse queryResponse = solrServer.query(new SolrQuery("foo2:*"));
    assertEquals(0, queryResponse.getResults().getNumFound());
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) IndexUpdateCallback(org.apache.jackrabbit.oak.plugins.index.IndexUpdateCallback) DefaultSolrConfiguration(org.apache.jackrabbit.oak.plugins.index.solr.configuration.DefaultSolrConfiguration) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) OakSolrConfiguration(org.apache.jackrabbit.oak.plugins.index.solr.configuration.OakSolrConfiguration) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) SolrServer(org.apache.solr.client.solrj.SolrServer) SolrQuery(org.apache.solr.client.solrj.SolrQuery) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) Test(org.junit.Test)

Example 28 with SolrServer

use of org.apache.solr.client.solrj.SolrServer in project jackrabbit-oak by apache.

the class SolrQueryIndexTest method testNoNegativeCost.

@Test
public void testNoNegativeCost() throws Exception {
    NodeState root = InitialContent.INITIAL_CONTENT;
    NodeBuilder builder = root.builder();
    builder.child("oak:index").child("solr").setProperty("usedProperties", Collections.singleton("name"), Type.STRINGS).setProperty("propertyRestrictions", true).setProperty("type", "solr");
    nodeState = builder.getNodeState();
    SelectorImpl selector = newSelector(root, "a");
    String query = "select * from [nt:base] as a where native('solr','select?q=searchKeywords:\"foo\"^20 text:\"foo\"^1 " + "description:\"foo\"^8 something:\"foo\"^3 headline:\"foo\"^5 title:\"foo\"^10 &q.op=OR'";
    String sqlQuery = "select * from [nt:base] a where native('solr','" + query + "'";
    SolrServer solrServer = mock(SolrServer.class);
    SolrServerProvider solrServerProvider = mock(SolrServerProvider.class);
    when(solrServerProvider.getSearchingSolrServer()).thenReturn(solrServer);
    OakSolrConfigurationProvider configurationProvider = mock(OakSolrConfigurationProvider.class);
    OakSolrConfiguration configuration = new DefaultSolrConfiguration() {

        @Override
        public boolean useForPropertyRestrictions() {
            return true;
        }

        @Override
        public int getRows() {
            return 10;
        }
    };
    when(configurationProvider.getConfiguration()).thenReturn(configuration);
    SolrQueryIndex solrQueryIndex = new SolrQueryIndex(null, configurationProvider, solrServerProvider);
    FilterImpl filter = new FilterImpl(selector, sqlQuery, new QueryEngineSettings());
    filter.restrictProperty("native*solr", Operator.EQUAL, PropertyValues.newString(query));
    CountingResponse response = new CountingResponse(0);
    when(solrServer.query(any(SolrParams.class))).thenReturn(response);
    List<QueryIndex.IndexPlan> plans = solrQueryIndex.getPlans(filter, null, nodeState);
    for (QueryIndex.IndexPlan p : plans) {
        double costPerEntry = p.getCostPerEntry();
        assertTrue(costPerEntry >= 0);
        double costPerExecution = p.getCostPerExecution();
        assertTrue(costPerExecution >= 0);
        long estimatedEntryCount = p.getEstimatedEntryCount();
        assertTrue(estimatedEntryCount >= 0);
        double c = p.getCostPerExecution() + estimatedEntryCount * p.getCostPerEntry();
        assertTrue(c >= 0);
    }
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) FilterImpl(org.apache.jackrabbit.oak.query.index.FilterImpl) QueryEngineSettings(org.apache.jackrabbit.oak.query.QueryEngineSettings) OakSolrConfiguration(org.apache.jackrabbit.oak.plugins.index.solr.configuration.OakSolrConfiguration) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) SolrServer(org.apache.solr.client.solrj.SolrServer) OakSolrConfigurationProvider(org.apache.jackrabbit.oak.plugins.index.solr.configuration.OakSolrConfigurationProvider) SolrServerProvider(org.apache.jackrabbit.oak.plugins.index.solr.server.SolrServerProvider) SelectorImpl(org.apache.jackrabbit.oak.query.ast.SelectorImpl) DefaultSolrConfiguration(org.apache.jackrabbit.oak.plugins.index.solr.configuration.DefaultSolrConfiguration) SolrParams(org.apache.solr.common.params.SolrParams) QueryIndex(org.apache.jackrabbit.oak.spi.query.QueryIndex) Test(org.junit.Test)

Example 29 with SolrServer

use of org.apache.solr.client.solrj.SolrServer in project jackrabbit-oak by apache.

the class RemoteSolrServerProviderIT method testCloudRemoteServerCreation.

@Test
public void testCloudRemoteServerCreation() throws Exception {
    // do this test only if a Solr Cloud server is available
    for (String host : zkHosts) {
        boolean cloudServerAvailable = false;
        try {
            cloudServerAvailable = canCreateCollections(host);
        } catch (Exception e) {
        // do nothing
        }
        if (cloudServerAvailable) {
            String collection = "sample_" + System.nanoTime();
            RemoteSolrServerProvider remoteSolrServerProvider = new RemoteSolrServerProvider(new RemoteSolrServerConfiguration(host, collection, 2, 2, null));
            SolrServer solrServer = remoteSolrServerProvider.getSolrServer();
            assertNotNull(solrServer);
            solrServer.shutdown();
            break;
        }
    }
}
Also used : RemoteSolrServerConfiguration(org.apache.jackrabbit.oak.plugins.index.solr.configuration.RemoteSolrServerConfiguration) SolrServer(org.apache.solr.client.solrj.SolrServer) CloudSolrServer(org.apache.solr.client.solrj.impl.CloudSolrServer) Test(org.junit.Test)

Example 30 with SolrServer

use of org.apache.solr.client.solrj.SolrServer in project jackrabbit-oak by apache.

the class SolrQueryIndex method getPlans.

@Override
public List<IndexPlan> getPlans(Filter filter, List<OrderEntry> sortOrder, NodeState rootState) {
    Collection<String> indexPaths = new SolrIndexLookup(rootState).collectIndexNodePaths(filter);
    List<IndexPlan> plans = Lists.newArrayListWithCapacity(indexPaths.size());
    for (String path : indexPaths) {
        OakSolrConfiguration configuration = getConfiguration(path, rootState);
        SolrServer solrServer = getServer(path, rootState);
        // only provide the plan if both valid configuration and server exist
        if (configuration != null && solrServer != null) {
            LMSEstimator estimator = getEstimator(path);
            IndexPlan plan = getIndexPlan(filter, configuration, estimator, sortOrder, path);
            if (plan != null) {
                plans.add(plan);
            }
        }
    }
    return plans;
}
Also used : OakSolrConfiguration(org.apache.jackrabbit.oak.plugins.index.solr.configuration.OakSolrConfiguration) OakSolrServer(org.apache.jackrabbit.oak.plugins.index.solr.server.OakSolrServer) SolrServer(org.apache.solr.client.solrj.SolrServer)

Aggregations

SolrServer (org.apache.solr.client.solrj.SolrServer)40 ManagedSolrServer (org.apache.stanbol.commons.solr.managed.ManagedSolrServer)21 SolrServerException (org.apache.solr.client.solrj.SolrServerException)18 EmbeddedSolrServer (org.apache.solr.client.solrj.embedded.EmbeddedSolrServer)17 ClassifierException (org.apache.stanbol.enhancer.topic.api.ClassifierException)13 IOException (java.io.IOException)12 SolrQuery (org.apache.solr.client.solrj.SolrQuery)12 ConfigurationException (org.osgi.service.cm.ConfigurationException)11 SolrDocument (org.apache.solr.common.SolrDocument)10 TrainingSetException (org.apache.stanbol.enhancer.topic.api.training.TrainingSetException)10 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)10 OakSolrConfiguration (org.apache.jackrabbit.oak.plugins.index.solr.configuration.OakSolrConfiguration)8 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)8 ArrayList (java.util.ArrayList)7 ChainException (org.apache.stanbol.enhancer.servicesapi.ChainException)7 EngineException (org.apache.stanbol.enhancer.servicesapi.EngineException)7 InvalidContentException (org.apache.stanbol.enhancer.servicesapi.InvalidContentException)7 EntityhubException (org.apache.stanbol.entityhub.servicesapi.EntityhubException)7 SolrInputDocument (org.apache.solr.common.SolrInputDocument)6 Test (org.junit.Test)6