Search in sources :

Example 1 with HttpSolrServer

use of org.apache.solr.client.solrj.impl.HttpSolrServer in project e3mall by colg-cloud.

the class TestSolr method addDocument.

/**
 * 向索引库添加文档
 */
@Test
public void addDocument() throws SolrServerException, IOException {
    // 创建一个SolrServer对象,创建一个连接。参数:sorl服务的url
    SolrServer solrServer = new HttpSolrServer(BASE_URL);
    // 创建一个文档对象SolrInputDocument
    SolrInputDocument doc = new SolrInputDocument();
    // 向文档对象中添加域,文档中必须包含一个id域,所有的域的名称必须在schema.xml中定义
    doc.addField("id", "doc01");
    doc.addField("item_title", "测试商品01");
    doc.addField("item_price", 1000);
    // 把文档写入索引库
    solrServer.add(doc);
    // 提交
    solrServer.commit();
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) HttpSolrServer(org.apache.solr.client.solrj.impl.HttpSolrServer) SolrServer(org.apache.solr.client.solrj.SolrServer) HttpSolrServer(org.apache.solr.client.solrj.impl.HttpSolrServer) Test(org.junit.Test)

Example 2 with HttpSolrServer

use of org.apache.solr.client.solrj.impl.HttpSolrServer in project Xponents by OpenSextant.

the class SolrProxy method initializeHTTP.

/**
     * Get an HTTP server for Solr.
     *
     * @param url server represented by URL
     * @return Instance of a Solr server
     * @throws MalformedURLException
     */
public static SolrServer initializeHTTP(URL url) throws MalformedURLException {
    HttpSolrServer server = new HttpSolrServer(url.toString());
    server.setAllowCompression(true);
    return server;
}
Also used : HttpSolrServer(org.apache.solr.client.solrj.impl.HttpSolrServer)

Example 3 with HttpSolrServer

use of org.apache.solr.client.solrj.impl.HttpSolrServer in project camel by apache.

the class SolrFixtures method createSolrFixtures.

static void createSolrFixtures() throws Exception {
    solrHttpsRunner = JettySolrFactory.createJettyTestFixture(true);
    httpsPort = solrHttpsRunner.getLocalPort();
    log.info("Started Https Test Server: " + solrHttpsRunner.getBaseUrl());
    solrHttpsServer = new HttpSolrServer("https://localhost:" + httpsPort + "/solr");
    solrHttpsServer.setConnectionTimeout(60000);
    solrRunner = JettySolrFactory.createJettyTestFixture(false);
    port = solrRunner.getLocalPort();
    solrServer = new HttpSolrServer("http://localhost:" + port + "/solr");
    log.info("Started Test Server: " + solrRunner.getBaseUrl());
    cloudFixture = new SolrCloudFixture("src/test/resources/solr");
}
Also used : HttpSolrServer(org.apache.solr.client.solrj.impl.HttpSolrServer)

Example 4 with HttpSolrServer

use of org.apache.solr.client.solrj.impl.HttpSolrServer in project mamute by caelum.

the class SolrServerProvider method create.

@PostConstruct
public void create() {
    // embedded options
    Boolean embedded = Boolean.parseBoolean(env.get("solr.embedded", "false"));
    String solrCore = env.get("solr.core", "mamute");
    String solrHome = env.get("solr.home", "");
    // remote options
    String remoteUrl = env.get("solr.url", "");
    if (embedded) {
        LOGGER.info("Starting embedded Solr");
        String home = solrHome;
        if (isEmpty(home)) {
            String locale = env.get("locale");
            LOGGER.info("Using default home, with locale [" + locale + "]");
            home = env.getResource("/solr/" + locale).getPath();
        }
        CoreContainer coreContainer = new CoreContainer(home);
        coreContainer.load();
        server = new EmbeddedSolrServer(coreContainer, solrCore);
    } else if (isNotEmpty(remoteUrl)) {
        LOGGER.info("Connecting to external Solr at [" + remoteUrl + "]");
        server = new HttpSolrServer(remoteUrl);
    } else {
        LOGGER.warn("Solr config options not valid, not initting");
    }
}
Also used : CoreContainer(org.apache.solr.core.CoreContainer) HttpSolrServer(org.apache.solr.client.solrj.impl.HttpSolrServer) EmbeddedSolrServer(org.apache.solr.client.solrj.embedded.EmbeddedSolrServer) PostConstruct(javax.annotation.PostConstruct)

Example 5 with HttpSolrServer

use of org.apache.solr.client.solrj.impl.HttpSolrServer in project stanbol by apache.

the class SolrYardComponent method activate.

@Activate
protected void activate(ComponentContext ctx) throws ConfigurationException {
    this.context = ctx.getBundleContext();
    @SuppressWarnings("unchecked") SolrYardConfig config = new SolrYardConfig((Dictionary<String, Object>) ctx.getProperties());
    log.info("activate {} (name:{})", getClass().getSimpleName(), config.getId());
    String indexLocation = config.getSolrServerLocation();
    if (indexLocation.startsWith("http") && indexLocation.indexOf("://") > 0) {
        solrServer = new HttpSolrServer(indexLocation);
        // directly register configs that use a remote server
        updateSolrYardRegistration(solrServer, config);
    } else {
        // locally managed Server
        IndexReference solrServerRef = IndexReference.parse(config.getSolrServerLocation());
        // default
        if (config.isAllowInitialisation() && solrServerRef.getServer() != null) {
            throw new ConfigurationException(SolrYardConfig.SOLR_SERVER_LOCATION, "The SolrServerLocation ({server-name}:{index-name}) MUST NOT define a " + "{server-name} if '" + SolrYardConfig.ALLOW_INITIALISATION_STATE + "' is enabled. Change the cofiguration to use just a {index-name}");
        }
        // check if we need to init the SolrIndex
        initManagedSolrIndex(managedSolrServer, config);
    }
    // globally set the config
    this.config = config;
}
Also used : ConfigurationException(org.osgi.service.cm.ConfigurationException) HttpSolrServer(org.apache.solr.client.solrj.impl.HttpSolrServer) IndexReference(org.apache.stanbol.commons.solr.IndexReference) Activate(org.apache.felix.scr.annotations.Activate)

Aggregations

HttpSolrServer (org.apache.solr.client.solrj.impl.HttpSolrServer)8 SolrServer (org.apache.solr.client.solrj.SolrServer)4 Test (org.junit.Test)4 SolrQuery (org.apache.solr.client.solrj.SolrQuery)2 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)2 SolrDocumentList (org.apache.solr.common.SolrDocumentList)2 Map (java.util.Map)1 PostConstruct (javax.annotation.PostConstruct)1 Activate (org.apache.felix.scr.annotations.Activate)1 EmbeddedSolrServer (org.apache.solr.client.solrj.embedded.EmbeddedSolrServer)1 SolrInputDocument (org.apache.solr.common.SolrInputDocument)1 CoreContainer (org.apache.solr.core.CoreContainer)1 IndexReference (org.apache.stanbol.commons.solr.IndexReference)1 ConfigurationException (org.osgi.service.cm.ConfigurationException)1