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();
}
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;
}
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");
}
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");
}
}
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;
}
Aggregations