use of org.apache.solr.client.solrj.SolrServer in project stanbol by apache.
the class LDPathTestBase method setup.
@BeforeClass
public static void setup() throws Exception {
// get the working directory
// use property substitution to test this feature!
String prefix = System.getProperty("basedir") == null ? "." : "${basedir}";
String solrServerDir = prefix + TEST_INDEX_REL_PATH;
log.info("Test Solr Server Directory: {}", solrServerDir);
System.setProperty(ManagedSolrServer.MANAGED_SOLR_DIR_PROPERTY, solrServerDir);
SolrYardConfig config = new SolrYardConfig(TEST_YARD_ID, TEST_SOLR_CORE_NAME);
config.setAllowInitialisation(false);
//the dbpedia default data
config.setIndexConfigurationName(TEST_SOLR_CORE_CONFIGURATION);
//init from datafile provider
config.setAllowInitialisation(true);
config.setName("DBpedia.org default data");
config.setDescription("Data used for the LDPath setup");
// create the Yard used for the tests
IndexReference solrIndexRef = IndexReference.parse(config.getSolrServerLocation());
SolrServer server = StandaloneEmbeddedSolrServerProvider.getInstance().getSolrServer(solrIndexRef, config.getIndexConfigurationName());
Assert.assertNotNull("Unable to initialise SolrServer for testing", server);
yard = new SolrYard(server, config, null);
backend = new YardBackend(yard);
}
use of org.apache.solr.client.solrj.SolrServer in project stanbol by apache.
the class FstLinkingEngineTest method setup.
@BeforeClass
public static void setup() throws Exception {
// get the working directory
// use property substitution to test this feature!
String prefix = System.getProperty("basedir") == null ? "." : "${basedir}";
String solrServerDir = prefix + TEST_INDEX_REL_PATH;
log.info("Test Solr Server Directory: {}", solrServerDir);
System.setProperty(ManagedSolrServer.MANAGED_SOLR_DIR_PROPERTY, solrServerDir);
SolrYardConfig config = new SolrYardConfig(TEST_YARD_ID, TEST_SOLR_CORE_NAME);
config.setAllowInitialisation(false);
//the dbpedia default data
config.setIndexConfigurationName(TEST_SOLR_CORE_CONFIGURATION);
//init from datafile provider
config.setAllowInitialisation(true);
config.setName("DBpedia.org default data");
config.setDescription("Data used for FstLinkingEngie tests");
// create the Yard used for the tests
IndexReference solrIndexRef = IndexReference.parse(config.getSolrServerLocation());
SolrServer server = StandaloneEmbeddedSolrServerProvider.getInstance().getSolrServer(solrIndexRef, config.getIndexConfigurationName());
Assert.assertNotNull("Unable to initialise SolrServer for testing", server);
core = ((EmbeddedSolrServer) server).getCoreContainer().getCore(solrIndexRef.getIndex());
Assert.assertNotNull("Unable to get SolrCore '" + config.getIndexConfigurationName() + "' from SolrServer " + server, core);
yard = new SolrYard(server, config, null);
//setup the index configuration
LanguageConfiguration langConf = new LanguageConfiguration("not.used", new String[] { "en;field=dbpedia-ont:surfaceForm;generate=true" });
fstConfig = new IndexConfiguration(langConf, core, FieldEncodingEnum.SolrYard, "");
fstConfig.setExecutorService(Executors.newFixedThreadPool(1));
fstConfig.setTypeField("rdf:type");
fstConfig.setRankingField("entityhub:entityRank");
//fstConfig.setEntityCacheManager(new FastLRUCacheManager(2048));
fstConfig.setOrigin(new PlainLiteralImpl(TEST_ORIGIN));
//activate the FST config
//activate this configuration
fstConfig.activate();
//validate that the index contains the expected entities
validateTestIndex();
//now create the FST models
List<Future<?>> creationTasks = new ArrayList<Future<?>>();
for (CorpusInfo corpus : fstConfig.getCorpora()) {
Assert.assertTrue("Failure in UnitTest - all FST models need to be generate=true", corpus.allowCreation);
if (!corpus.isFstFile()) {
//create a task on the FST corpus creation service
creationTasks.add(fstConfig.getExecutorService().submit(new CorpusCreationTask(fstConfig, corpus)));
}
}
//typical hardware
for (Future<?> future : creationTasks) {
try {
future.get(FST_CREATION_WAIT_TIME, TimeUnit.SECONDS);
} catch (TimeoutException e) {
// we assert on future.isDone instead
}
Assert.assertTrue("FST Model creation not finished after " + FST_CREATION_WAIT_TIME + "seconds", future.isDone());
}
}
use of org.apache.solr.client.solrj.SolrServer in project stanbol by apache.
the class SolrYardComponent method initManagedSolrIndex.
/**
* initialise ManagedSolrIndex and that starts tracking for the {@link SolrCore}
* @param managedServer the managedServer to init the SolrCore (if necessary)
* @param config the {@link SolrYardConfig}
* @throws IllegalStateException if the initialization fails
*/
private void initManagedSolrIndex(final ManagedSolrServer managedServer, final SolrYardConfig config) {
if (managedServer == null || config == null) {
//component was not yet activated ... will be called again
return;
}
IndexReference solrIndexRef = IndexReference.parse(config.getSolrServerLocation());
if (config.isAllowInitialisation()) {
//are we allowed to create the SolrServer
//get the name of the config to be used (default: default.solrindex.zip")
String configName = config.getIndexConfigurationName();
IndexMetadata metadata = managedServer.getIndexMetadata(solrIndexRef.getIndex());
if (metadata == null) {
//create a new index
log.info(" ... creating Managed SolrIndex {} (configName: {}) on Server {}", new Object[] { solrIndexRef.getIndex(), configName, managedServer.getServerName() });
try {
metadata = managedServer.createSolrIndex(solrIndexRef.getIndex(), configName, null);
} catch (IOException e) {
throw new IllegalStateException("Unable to create Managed SolrIndex " + solrIndexRef.getIndex() + " (configName: " + configName + ") on Server " + managedServer.getServerName() + "!", e);
}
} else if (metadata.getState() != ManagedIndexState.ACTIVE) {
log.info(" ... activating Managed SolrIndex {} on Server {} (current state: {})", new Object[] { solrIndexRef.getIndex(), managedServer.getServerName(), metadata.getState() });
try {
managedServer.activateIndex(metadata.getIndexName());
} catch (IOException e) {
throw new IllegalStateException("Unable to activate Managed SolrIndex " + solrIndexRef.getIndex() + " (configName: " + configName + ") on Server " + managedServer.getServerName() + "!", e);
} catch (SAXException e) {
throw new IllegalStateException("Unable to activate Managed SolrIndex " + solrIndexRef.getIndex() + " (configName: " + configName + ") on Server " + managedServer.getServerName() + "!", e);
}
}
//else already active nothing todo
solrIndexRef = metadata.getIndexReference();
}
//else the SolrServer will be supplied (e.g. created by installing a full index)
try {
registeredServerTracker = new RegisteredSolrServerTracker(context, solrIndexRef, null) {
@Override
public void removedService(ServiceReference reference, Object service) {
updateSolrYardRegistration(registeredServerTracker.getService(), config);
super.removedService(reference, service);
}
@Override
public void modifiedService(ServiceReference reference, Object service) {
updateSolrYardRegistration(registeredServerTracker.getService(), config);
super.modifiedService(reference, service);
}
@Override
public SolrServer addingService(ServiceReference reference) {
SolrServer server = super.addingService(reference);
if (solrServer != null) {
log.warn("Multiple SolrServer for IndexLocation {} available!", config.getSolrServerLocation());
} else {
updateSolrYardRegistration(server, config);
}
return server;
}
};
log.info(" ... start tracking for SolrCore based on {}", solrIndexRef);
//start tracking
registeredServerTracker.open();
} catch (InvalidSyntaxException e) {
throw new IllegalStateException("Unable to track Managed SolrIndex " + solrIndexRef.getIndex() + "on Server " + managedServer.getServerName() + "!", e);
}
}
use of org.apache.solr.client.solrj.SolrServer in project qi4j-sdk by Qi4j.
the class SolrEntityQueryMixin method search.
@Override
public SolrDocumentList search(String queryString) throws SolrServerException {
SolrServer server = solr.solrServer();
NamedList<Object> list = new NamedList<Object>();
list.add("q", queryString);
QueryResponse query = server.query(SolrParams.toSolrParams(list));
return query.getResults();
}
use of org.apache.solr.client.solrj.SolrServer in project play-cookbook by spinscale.
the class SolrPlugin method onEvent.
@Override
public void onEvent(String message, Object context) {
if (!StringUtils.startsWith(message, "JPASupport.")) {
return;
}
try {
Model model = (Model) context;
String entityId = model.getClass().getName() + ":" + model.getId().toString();
SolrServer server = getSearchServer();
server.deleteById(entityId);
// if ("JPASupport.objectPersisted".equals(message) || "JPASupport.objectUpdated".equals(message)) {
if ("JPASupport.objectUpdated".equals(message)) {
SolrInputDocument doc = new SolrInputDocument();
doc.addField("id", entityId);
doc.addField("searchClass", model.getClass().getName());
for (java.lang.reflect.Field field : context.getClass().getFields()) {
String fieldName = field.getName();
Field annot = field.getAnnotation(Field.class);
if (annot == null) {
continue;
}
String annotationValue = annot.value();
if (annotationValue != null && !"#default".equals(annotationValue)) {
fieldName = annotationValue;
}
doc.addField(fieldName, field.get(context));
}
server.add(doc);
Logger.info("Added entity %s with fields %s on event %s", model.getClass().getSimpleName(), doc.getFieldNames(), message);
}
server.commit();
} catch (Exception e) {
Logger.error(e, "Problem updating entity %s on event %s with error %s", context, message, e.getMessage());
}
}
Aggregations