use of org.apache.solr.client.solrj.impl.BinaryRequestWriter in project play-cookbook by spinscale.
the class SolrSearchTest method setup.
@Before
public void setup() throws Exception {
Fixtures.deleteAllModels();
server = new CommonsHttpSolrServer("http://localhost:8983/solr");
server.setRequestWriter(new BinaryRequestWriter());
clearSolrServerIndex();
Fixtures.loadModels("test-data.yml");
}
use of org.apache.solr.client.solrj.impl.BinaryRequestWriter in project play-cookbook by spinscale.
the class SolrPlugin method getSearchServer.
public static SolrServer getSearchServer() {
String url = Play.configuration.getProperty("solr.server", "http://localhost:8983/solr");
CommonsHttpSolrServer server = null;
try {
server = new CommonsHttpSolrServer(url);
server.setRequestWriter(new BinaryRequestWriter());
} catch (MalformedURLException e) {
Logger.error(e, "Problem creating solr server object: %s", e.getMessage());
}
return server;
}
use of org.apache.solr.client.solrj.impl.BinaryRequestWriter in project mycore by MyCoRe-Org.
the class MCRSolrCore method setup.
protected void setup(String serverURL, String name) {
if (!serverURL.endsWith("/")) {
serverURL += serverURL + "/";
}
this.serverURL = serverURL;
this.name = name;
String coreURL = serverURL + name;
int connectionTimeout = MCRConfiguration.instance().getInt(CONFIG_PREFIX + "SolrClient.ConnectionTimeout");
int socketTimeout = MCRConfiguration.instance().getInt(CONFIG_PREFIX + "SolrClient.SocketTimeout");
// default server
solrClient = new HttpSolrClient.Builder(coreURL).withConnectionTimeout(connectionTimeout).withSocketTimeout(socketTimeout).build();
solrClient.setRequestWriter(new BinaryRequestWriter());
// concurrent server
if (USE_CONCURRENT_SERVER) {
int queueSize = MCRConfiguration.instance().getInt(CONFIG_PREFIX + "ConcurrentUpdateSolrClient.QueueSize");
int threadCount = MCRConfiguration.instance().getInt(CONFIG_PREFIX + "ConcurrentUpdateSolrClient.ThreadCount");
concurrentClient = new ConcurrentUpdateSolrClient.Builder(coreURL).withQueueSize(queueSize).withConnectionTimeout(connectionTimeout).withSocketTimeout(socketTimeout).withThreadCount(threadCount).build();
concurrentClient.setRequestWriter(new BinaryRequestWriter());
}
// shutdown handler
MCRShutdownHandler.getInstance().addCloseable(new MCRShutdownHandler.Closeable() {
@Override
public void prepareClose() {
}
@Override
public int getPriority() {
return Integer.MIN_VALUE + 5;
}
@Override
public void close() {
shutdown();
}
});
}
use of org.apache.solr.client.solrj.impl.BinaryRequestWriter in project ranger by apache.
the class SolrMgr method connect.
void connect() {
if (!initDone) {
synchronized (lock) {
if (!initDone) {
if ("solr".equalsIgnoreCase(rangerBizUtil.getAuditDBType())) {
String zkHosts = PropertiesUtil.getProperty(SOLR_ZK_HOSTS);
if (zkHosts == null) {
zkHosts = PropertiesUtil.getProperty("ranger.audit.solr.zookeeper");
}
if (zkHosts == null) {
zkHosts = PropertiesUtil.getProperty("ranger.solr.zookeeper");
}
String solrURL = PropertiesUtil.getProperty(SOLR_URLS_PROP);
if (solrURL == null) {
// Try with url
solrURL = PropertiesUtil.getProperty("ranger.audit.solr.url");
}
if (solrURL == null) {
// Let's try older property name
solrURL = PropertiesUtil.getProperty("ranger.solr.url");
}
if (zkHosts != null && !"".equals(zkHosts.trim()) && !"none".equalsIgnoreCase(zkHosts.trim())) {
zkHosts = zkHosts.trim();
String collectionName = PropertiesUtil.getProperty(SOLR_COLLECTION_NAME);
if (collectionName == null || "none".equalsIgnoreCase(collectionName)) {
collectionName = DEFAULT_COLLECTION_NAME;
}
logger.info("Solr zkHosts=" + zkHosts + ", collectionName=" + collectionName);
try (Krb5HttpClientBuilder krbBuild = new Krb5HttpClientBuilder()) {
// Instantiate
SolrHttpClientBuilder kb = krbBuild.getBuilder();
HttpClientUtil.setHttpClientBuilder(kb);
final List<String> zkhosts = new ArrayList<String>(Arrays.asList(zkHosts.split(",")));
CloudSolrClient solrCloudClient = new CloudSolrClient.Builder(zkhosts, Optional.empty()).build();
solrCloudClient.setDefaultCollection(collectionName);
solrClient = solrCloudClient;
} catch (Throwable t) {
logger.error("Can't connect to Solr server. ZooKeepers=" + zkHosts + ", collection=" + collectionName, t);
}
} else {
if (solrURL == null || solrURL.isEmpty() || "none".equalsIgnoreCase(solrURL)) {
logger.error("Solr ZKHosts and URL for Audit are empty. Please set property " + SOLR_ZK_HOSTS + " or " + SOLR_URLS_PROP);
} else {
try (Krb5HttpClientBuilder krbBuild = new Krb5HttpClientBuilder()) {
SolrHttpClientBuilder kb = krbBuild.getBuilder();
HttpClientUtil.setHttpClientBuilder(kb);
HttpSolrClient.Builder builder = new HttpSolrClient.Builder();
builder.withBaseSolrUrl(solrURL);
builder.allowCompression(true);
builder.withConnectionTimeout(1000);
HttpSolrClient httpSolrClient = builder.build();
httpSolrClient.setRequestWriter(new BinaryRequestWriter());
solrClient = httpSolrClient;
initDone = true;
} catch (Throwable t) {
logger.error("Can't connect to Solr server. URL=" + solrURL, t);
}
}
}
}
}
}
}
}
Aggregations