本文整理匯總了Java中org.apache.solr.client.solrj.embedded.EmbeddedSolrServer類的典型用法代碼示例。如果您正苦於以下問題:Java EmbeddedSolrServer類的具體用法?Java EmbeddedSolrServer怎麽用?Java EmbeddedSolrServer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
EmbeddedSolrServer類屬於org.apache.solr.client.solrj.embedded包,在下文中一共展示了EmbeddedSolrServer類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createNewSolrClient
import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer; //導入依賴的package包/類
public SolrClient createNewSolrClient(final String index) {
if (jetty != null) {
try {
// setup the client...
String url = jetty.getBaseUrl().toString() + "/" + index;
HttpSolrClient client = getHttpSolrClient(url);
client.setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT);
client.setDefaultMaxConnectionsPerHost(100);
client.setMaxTotalConnections(100);
return client;
} catch (Exception ex) {
throw new RuntimeException(ex);
}
} else {
return new EmbeddedSolrServer(h.getCoreContainer(), index);
}
}
示例2: doInitialize
import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer; //導入依賴的package包/類
@Override
protected void doInitialize() throws Exception {
if (solrHomeFolder == null) {
File target = pluginFolder.getFile();
solrHomeFolder = Paths.get(target.getPath(),"solr");
}
if (Files.notExists(solrHomeFolder)) {
doInstall();
}
EmbeddedSolrServer solrServer = new EmbeddedSolrServer(solrHomeFolder,"easyrec");
// String urlString = "http://localhost:8983/solr/easyrec";
// SolrClient solrClient = new HttpSolrClient(urlString);
if (solrServer == null) throw new Exception("Could not initialize Solr server!");
solrSimilarityService.setSolrClient(solrServer);
}
示例3: activateSolr
import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer; //導入依賴的package包/類
@Override
public void activateSolr() throws Exception
{
ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader( getClass().getClassLoader() );
try
{
File directory = new File( fileConfig.dataDirectory(), descriptor.identity().toString() );
directory.mkdirs();
System.setProperty( "solr.solr.home", directory.getAbsolutePath() );
CoreContainer.Initializer initializer = new CoreContainer.Initializer();
coreContainer = initializer.initialize();
server = new EmbeddedSolrServer( coreContainer, "" );
core = coreContainer.getCore( "" );
} finally
{
Thread.currentThread().setContextClassLoader( oldCl );
}
}
示例4: create
import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer; //導入依賴的package包/類
/**
*
* @param solrHome
* path to directory where solr.xml lives
*
* @param coreName
* the name of the core to load
* @param dataDir
* the data dir for the core
*
* @return an EmbeddedSolrServer for the given core
*/
public static SolrClient create(String solrHome, String coreHome, String coreName, String dataDir) throws IOException {
File coreDataDir = new File(dataDir + "/" + coreName);
if (coreDataDir.exists()) {
FileUtils.deleteDirectory(coreDataDir);
}
CoreContainer coreContainer = new CoreContainer(solrHome);
coreContainer.load();
Properties props = new Properties();
props.setProperty("dataDir", dataDir + "/" + coreName);
CoreDescriptor descriptor = new CoreDescriptor(coreContainer, coreName,
new File(coreHome, coreName).getAbsolutePath(), props);
SolrCore solrCore = coreContainer.create(descriptor);
//coreContainer.register(solrCore, false);
return new EmbeddedSolrServer(coreContainer, coreName);
}
示例5: createNewSolrServer
import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer; //導入依賴的package包/類
/**
* Create a new solr server.
* If createJetty was called, an http implementation will be created,
* otherwise an embedded implementation will be created.
* Subclasses should override for other options.
*/
public SolrServer createNewSolrServer() {
if (jetty != null) {
try {
// setup the server...
String url = jetty.getBaseUrl().toString() + "/" + "collection1";
HttpSolrServer s = new HttpSolrServer( url );
s.setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT);
s.setDefaultMaxConnectionsPerHost(100);
s.setMaxTotalConnections(100);
return s;
}
catch( Exception ex ) {
throw new RuntimeException( ex );
}
} else {
return new EmbeddedSolrServer( h.getCoreContainer(), "" );
}
}
示例6: BatchWriter
import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer; //導入依賴的package包/類
public BatchWriter(EmbeddedSolrServer solr, int batchSize, TaskID tid,
int writerThreads, int queueSize) {
this.solr = solr;
this.writerThreads = writerThreads;
this.queueSize = queueSize;
taskId = tid;
// we need to obtain the settings before the constructor
if (writerThreads != 0) {
batchPool = new ThreadPoolExecutor(writerThreads, writerThreads, 5,
TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(queueSize),
new ThreadPoolExecutor.CallerRunsPolicy());
} else { // single threaded case
batchPool = null;
}
}
示例7: validateSolrServerDocumentCount
import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer; //導入依賴的package包/類
public static void validateSolrServerDocumentCount(File solrHomeDir, FileSystem fs, Path outDir, int expectedDocs, int expectedShards)
throws IOException, SolrServerException {
long actualDocs = 0;
int actualShards = 0;
for (FileStatus dir : fs.listStatus(outDir)) { // for each shard
if (dir.getPath().getName().startsWith("part") && dir.isDirectory()) {
actualShards++;
EmbeddedSolrServer solr = SolrRecordWriter.createEmbeddedSolrServer(
new Path(solrHomeDir.getAbsolutePath()), fs, dir.getPath());
try {
SolrQuery query = new SolrQuery();
query.setQuery("*:*");
QueryResponse resp = solr.query(query);
long numDocs = resp.getResults().getNumFound();
actualDocs += numDocs;
} finally {
solr.shutdown();
}
}
}
assertEquals(expectedShards, actualShards);
assertEquals(expectedDocs, actualDocs);
}
示例8: exportSchema
import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer; //導入依賴的package包/類
@Override
public void exportSchema(String user, String password, String schema,
File dumpFile) throws MojoExecutionException {
String solrUrl = url.substring("jdbc:solr:".length());
try {
SolrConnection connection = ConnectionTypeDetector.getInstance().find(solrUrl);
if (connection instanceof EmbeddedConnectionImpl) {
System.err.println(solrUrl);
EmbeddedSolrServer solrServer = (EmbeddedSolrServer) connection.getSolrServer();
SolrCore core = solrServer.getCoreContainer().getCore(solrServer.getCoreContainer().getDefaultCoreName());
ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(dumpFile.getAbsolutePath()));
}
} catch (Exception e) {
throw new MojoExecutionException("Export error", e);
}
}
示例9: createSolrServer
import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer; //導入依賴的package包/類
private EmbeddedSolrServer createSolrServer(Map<String,String> urlParams) {
String solrHome = urlParams.get("SOLR_HOME");
StringBuilder paramStr = new StringBuilder();
if (solrHome != null) {
System.setProperty("solr.solr.home", solrHome);
paramStr.append(";SOLR_HOME=").append(solrHome);
}
String dataDir = urlParams.get("DATA_DIR");
if (dataDir != null) {
System.setProperty("solr.data.dir", dataDir);
paramStr.append(";DATA_DIR=").append(dataDir);
}
try {
DriverManager.getConnection("jdbc:solr:s" + paramStr.toString());
} catch (SQLException e) {
throw new SQLRuntimeException(e);
}
CoreContainer.Initializer initializer = new CoreContainer.Initializer();
CoreContainer coreContainer = initializer.initialize();
return new EmbeddedSolrServer(coreContainer, coreContainer.getDefaultCoreName());
}
示例10: startSolr
import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer; //導入依賴的package包/類
/**
* Start up an embedded Solr server.
*
* @param home The path to the Solr home directory
* @return EmbeddedSolrServer: The instantiated server
* @throws Exception if any errors occur
*/
private EmbeddedSolrServer startSolr(String home) throws Exception {
try {
SolrConfig solrConfig = new SolrConfig(home, SOLR_CONFIG, null);
IndexSchema schema = new IndexSchema(solrConfig, SOLR_SCHEMA, null);
solrContainer = new CoreContainer(new SolrResourceLoader(
SolrResourceLoader.locateSolrHome()));
CoreDescriptor descriptor = new CoreDescriptor(solrContainer, "",
solrConfig.getResourceLoader().getInstanceDir());
descriptor.setConfigName(solrConfig.getResourceName());
descriptor.setSchemaName(schema.getResourceName());
solrCore = new SolrCore(null, solrConfig.getDataDir(),
solrConfig, schema, descriptor);
solrContainer.register("cheese", solrCore, false);
// CoreAdminRequest.create
return new EmbeddedSolrServer(solrContainer, "cheese");
} catch(Exception ex) {
log.error("\nFailed to start Solr server\n");
throw ex;
}
}
示例11: createEmbeddedSolrServer
import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer; //導入依賴的package包/類
public static EmbeddedSolrServer createEmbeddedSolrServer(String solrHome, boolean recreateDataDir) {
logger.info(format("Creating embedded SOLr server. Solr home: %s, recreateDataDir: %s.",
solrHome, recreateDataDir));
if (recreateDataDir) {
File dataDir = new File(solrHome, String.join("/", DEFAULT_CORE_NAME, DEFAULT_DATA_DIR_NAME));
if (dataDir.exists() && !FileUtils.deleteQuietly(dataDir)) {
String msg = format("Unable to delete SOLr data dir %s.", dataDir);
logger.fatal(msg);
throw new IllegalStateException(msg);
}
}
CoreContainer coreContainer = Value.with(new CoreContainer(solrHome), CoreContainer::load);
return new EmbeddedSolrServer(coreContainer, DEFAULT_CORE_NAME);
}
示例12: setUp
import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer; //導入依賴的package包/類
@Before
public void setUp() throws Exception {
Path carbonHome = Paths.get("target", "test-classes", "carbon-home");
System.setProperty("carbon.home", carbonHome.toString());
Path registryPath = IndexingTestUtils.getResourcePath("registry-indexing.xml");
System.setProperty("wso2.registry.xml", registryPath.toString());
System.setProperty("carbon.home", registryPath.toString());
Path resourcePath = IndexingTestUtils.getResourcePath("conf");
System.setProperty("carbon.config.dir.path", resourcePath.toString());
CoreContainer coreContainer = mock(CoreContainer.class);
whenNew(CoreContainer.class).withParameterTypes(String.class).withArguments(anyString())
.thenReturn(coreContainer);
server = mock(EmbeddedSolrServer.class);
whenNew(EmbeddedSolrServer.class).withParameterTypes(CoreContainer.class, String.class).withArguments
(anyObject(), anyString()).thenReturn(server);
client = SolrClient.getInstance();
MessageContext.currentMessageContext.remove();
}
示例13: createNewSolrServer
import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer; //導入依賴的package包/類
/**
* Create a new solr server.
* If createJetty was called, an http implementation will be created,
* otherwise an embedded implementation will be created.
* Subclasses should override for other options.
*/
public SolrServer createNewSolrServer() {
if (jetty != null) {
try {
// setup the server...
String url = jetty.getBaseUrl().toString();
HttpSolrServer s = new HttpSolrServer( url );
s.setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT);
s.setDefaultMaxConnectionsPerHost(100);
s.setMaxTotalConnections(100);
return s;
}
catch( Exception ex ) {
throw new RuntimeException( ex );
}
} else {
return new EmbeddedSolrServer( h.getCoreContainer(), "" );
}
}
示例14: main
import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer; //導入依賴的package包/類
public static void main(String[] args) throws IOException, JATEException, SolrServerException {
Logger logger = Logger.getLogger(Indexing.class.getName());
JATEProperties prop = new JATEProperties(args[0]);
boolean deletePrevious = Boolean.valueOf(args[2]);
SolrClient solrClient = new EmbeddedSolrServer(Paths.get(args[3]), args[4]);
try {
if (deletePrevious) {
logger.info("DELETING PREVIOUS INDEX");
solrClient.deleteByQuery("*:*");
solrClient.commit();
}
logger.info("INDEXING BEGINS");
IndexingHandler m = new IndexingHandler();
List<String> files = new ArrayList<>();
for (File f : new File(args[1]).listFiles())
files.add(f.toString());
m.index(files, prop.getIndexerMaxUnitsToCommit(), new TikaSimpleDocumentCreator(), solrClient, prop);
logger.info("INDEXING COMPLETE");
System.exit(0);
} finally {
solrClient.close();
}
}
示例15: indexJATEDocuments
import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer; //導入依賴的package包/類
protected void indexJATEDocuments(Path file, EmbeddedSolrServer solrServer, JATEProperties jateProp, boolean commit) throws JATEException {
if (file == null) {
return;
}
try {
JATEDocument jateDocument = JATEUtil.loadJATEDocument(file);
if (isNotEmpty(jateDocument))
JATEUtil.addNewDoc(solrServer, jateDocument.getId(),
jateDocument.getId(), jateDocument.getContent(), jateProp, commit);
} catch (FileNotFoundException ffe) {
throw new JATEException(ffe.toString());
} catch (IOException ioe) {
throw new JATEException(String.format("failed to index [%s]", file.toString()) + ioe.toString());
} catch (SolrServerException sse) {
throw new JATEException(String.format("failed to index [%s] ", file.toString()) + sse.toString());
}
}