本文整理汇总了Java中org.apache.solr.core.SolrResourceLoader类的典型用法代码示例。如果您正苦于以下问题:Java SolrResourceLoader类的具体用法?Java SolrResourceLoader怎么用?Java SolrResourceLoader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SolrResourceLoader类属于org.apache.solr.core包,在下文中一共展示了SolrResourceLoader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDict
import org.apache.solr.core.SolrResourceLoader; //导入依赖的package包/类
public static Dictionary getDict(String dicPath, ResourceLoader loader) {
Dictionary dic = null;
if(dicPath != null) {
File f = new File(dicPath);
if(!f.isAbsolute() && loader instanceof SolrResourceLoader) { //相对目录
SolrResourceLoader srl = (SolrResourceLoader) loader;
dicPath = srl.getInstanceDir()+dicPath;
f = new File(dicPath);
}
dic = Dictionary.getInstance(f);
} else {
dic = Dictionary.getInstance();
}
return dic;
}
示例2: init
import org.apache.solr.core.SolrResourceLoader; //导入依赖的package包/类
@Override
protected void init(IndexSchema schema, Map<String, String> args) {
SolrResourceLoader loader = schema.getResourceLoader();
if (args.containsKey(SERIALIZER_ARGNAME)) {
serializer = loader.newInstance(args.remove(SERIALIZER_ARGNAME), TextTransformer.class);
}
if (args.containsKey(DISPLAYIZER_ARGNAME)) {
displayizer = loader.newInstance(args.remove(DISPLAYIZER_ARGNAME), TextTransformer.class);
}
if (args.containsKey(PAYLOAD_HANDLER_ARGNAME)) {
payloadHandler = loader.newInstance(args.remove(PAYLOAD_HANDLER_ARGNAME), FacetPayload.class);
} else {
payloadHandler = new DefaultPayloadHandler();
}
if (args.containsKey(HIERARCHY_LEVEL_ARGNAME)) {
hierarchyLevel = loader.newInstance(args.remove(HIERARCHY_LEVEL_ARGNAME), Integer.class);
}
delim = initDelim(hierarchyLevel);
delimBytes = delim.getBytes(StandardCharsets.UTF_8);
super.init(schema, args);
}
示例3: testDateFacets
import org.apache.solr.core.SolrResourceLoader; //导入依赖的package包/类
@Test
public void testDateFacets() throws Exception {
XMLResponseParser parser = new XMLResponseParser();
InputStream is = new SolrResourceLoader(null, null).openResource("solrj/sampleDateFacetResponse.xml");
assertNotNull(is);
Reader in = new InputStreamReader(is, StandardCharsets.UTF_8);
NamedList<Object> response = parser.processResponse(in);
in.close();
QueryResponse qr = new QueryResponse(response, null);
Assert.assertNotNull(qr);
Assert.assertNotNull(qr.getFacetDates());
for (FacetField f : qr.getFacetDates()) {
Assert.assertNotNull(f);
// TODO - test values?
// System.out.println(f.toString());
// System.out.println("GAP: " + f.getGap());
// System.out.println("END: " + f.getEnd());
}
}
示例4: TestHarness
import org.apache.solr.core.SolrResourceLoader; //导入依赖的package包/类
/**
* @param coreName to initialize
* @param dataDir path for index data, will not be cleaned up
* @param solrConfig solrconfig resource name
* @param indexSchema schema resource name
*/
public TestHarness(String coreName, String dataDir, String solrConfig, String indexSchema) {
try {
if (coreName == null)
coreName = ConfigSolrXmlOld.DEFAULT_DEFAULT_CORE_NAME;
this.coreName = coreName;
SolrResourceLoader loader = new SolrResourceLoader(SolrResourceLoader.locateSolrHome());
ConfigSolr config = getTestHarnessConfig(loader, coreName, dataDir, solrConfig, indexSchema);
container = new CoreContainer(loader, config);
container.load();
updater = new UpdateRequestHandler();
updater.init( null );
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例5: getTestHarnessConfig
import org.apache.solr.core.SolrResourceLoader; //导入依赖的package包/类
private static ConfigSolr getTestHarnessConfig(SolrResourceLoader loader, String coreName, String dataDir,
String solrConfig, String schema) {
String solrxml = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
+ "<solr persistent=\"false\">\n"
+ " <cores adminPath=\"/admin/cores\" defaultCoreName=\""
+ ConfigSolrXmlOld.DEFAULT_DEFAULT_CORE_NAME
+ "\""
+ " host=\"${host:}\" hostPort=\"${hostPort:}\" hostContext=\"${hostContext:}\""
+ " distribUpdateSoTimeout=\"30000\""
+ " zkClientTimeout=\"${zkClientTimeout:30000}\" distribUpdateConnTimeout=\"30000\""
+ ">\n"
+ " <core name=\"" + coreName + "\" config=\"" + solrConfig
+ "\" schema=\"" + schema + "\" dataDir=\"" + dataDir
+ "\" transient=\"false\" loadOnStartup=\"true\""
+ " shard=\"${shard:shard1}\" collection=\"${collection:collection1}\" instanceDir=\"" + coreName + "/\" />\n"
+ " </cores>\n" + "</solr>";
return ConfigSolr.fromString(loader, solrxml);
}
示例6: newRegisteredLogWatcher
import org.apache.solr.core.SolrResourceLoader; //导入依赖的package包/类
/**
* Create and register a LogWatcher.
*
* JUL and Log4j watchers are supported out-of-the-box. You can register your own
* LogWatcher implementation via the plugins architecture
*
* @param config a LogWatcherConfig object, containing the configuration for this LogWatcher.
* @param loader a SolrResourceLoader, to be used to load plugin LogWatcher implementations.
* Can be null if one of the built-in implementations is being used.
*
* @return a LogWatcher configured for the container's logging framework
*/
public static LogWatcher newRegisteredLogWatcher(LogWatcherConfig config, SolrResourceLoader loader) {
if (!config.isEnabled()) {
log.info("A LogWatcher is not enabled");
return null;
}
LogWatcher logWatcher = createWatcher(config, loader);
if (logWatcher != null) {
if (config.getWatcherSize() > 0) {
log.info("Registering Log Listener [{}]", logWatcher.getName());
logWatcher.registerListener(config.asListenerConfig());
}
}
return logWatcher;
}
示例7: shouldMutate
import org.apache.solr.core.SolrResourceLoader; //导入依赖的package包/类
/**
* Utility method that can be used to define a FieldNameSelector
* using the same types of rules as the FieldMutatingUpdateProcessor init
* code. This may be useful for Factories that wish to define default
* selectors in similar terms to what the configuration would look like.
* @lucene.internal
*/
public static FieldNameSelector createFieldNameSelector
(final SolrResourceLoader loader,
final SolrCore core,
final SelectorParams params,
final FieldNameSelector defSelector) {
if (params.noSelectorsSpecified()) {
return defSelector;
}
final ConfigurableFieldNameSelectorHelper helper =
new ConfigurableFieldNameSelectorHelper(loader, params);
return new FieldNameSelector() {
@Override
public boolean shouldMutate(String fieldName) {
return helper.shouldMutateBasedOnSchema(fieldName, core.getLatestSchema());
}
};
}
示例8: getConfig
import org.apache.solr.core.SolrResourceLoader; //导入依赖的package包/类
public static CacheConfig getConfig(SolrConfig solrConfig, Node node) {
if (node==null) return null;
CacheConfig config = new CacheConfig();
config.nodeName = node.getNodeName();
config.args = DOMUtil.toMap(node.getAttributes());
String nameAttr = config.args.get("name"); // OPTIONAL
if (nameAttr==null) {
config.args.put("name",config.nodeName);
}
SolrResourceLoader loader = solrConfig.getResourceLoader();
config.cacheImpl = config.args.get("class");
config.regenImpl = config.args.get("regenerator");
config.clazz = loader.findClass(config.cacheImpl, SolrCache.class);
if (config.regenImpl != null) {
config.regenerator = loader.newInstance(config.regenImpl, CacheRegenerator.class);
}
return config;
}
示例9: newInstance
import org.apache.solr.core.SolrResourceLoader; //导入依赖的package包/类
/**
* Create a new ShardHandlerFactory instance
* @param info a PluginInfo object defining which type to create. If null,
* the default {@link HttpShardHandlerFactory} will be used
* @param loader a SolrResourceLoader used to find the ShardHandlerFactory classes
* @return a new, initialized ShardHandlerFactory instance
*/
public static ShardHandlerFactory newInstance(PluginInfo info, SolrResourceLoader loader) {
if (info == null)
info = DEFAULT_SHARDHANDLER_INFO;
try {
ShardHandlerFactory shf = loader.findClass(info.className, ShardHandlerFactory.class).newInstance();
if (PluginInfoInitialized.class.isAssignableFrom(shf.getClass()))
PluginInfoInitialized.class.cast(shf).init(info);
return shf;
}
catch (Exception e) {
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
String.format(Locale.ROOT, "Error instantiating shardHandlerFactory class [%s]: %s",
info.className, e.getMessage()));
}
}
示例10: createManagedResource
import org.apache.solr.core.SolrResourceLoader; //导入依赖的package包/类
/**
* Creates a ManagedResource using registration information.
*/
protected ManagedResource createManagedResource(ManagedResourceRegistration reg) throws SolrException {
ManagedResource res = null;
try {
Constructor<? extends ManagedResource> ctor =
reg.implClass.getConstructor(String.class, SolrResourceLoader.class, StorageIO.class);
res = ctor.newInstance(reg.resourceId, loader, storageIO);
res.loadManagedDataAndNotify(reg.observers);
} catch (Exception e) {
String errMsg =
String.format(Locale.ROOT,
"Failed to create new ManagedResource %s of type %s due to: %s",
reg.resourceId, reg.implClass.getName(), e);
throw new SolrException(ErrorCode.SERVER_ERROR, errMsg, e);
}
return res;
}
示例11: configure
import org.apache.solr.core.SolrResourceLoader; //导入依赖的package包/类
@Override
public void configure(SolrResourceLoader loader, NamedList<String> initArgs) throws SolrException {
// validate connectivity and the configured znode base
try {
if (!zkClient.exists(znodeBase, retryOnConnLoss)) {
zkClient.makePath(znodeBase, retryOnConnLoss);
}
} catch (Exception exc) {
String errMsg = String.format
(Locale.ROOT, "Failed to verify znode at %s due to: %s", znodeBase, exc.toString());
log.error(errMsg, exc);
throw new SolrException(ErrorCode.SERVER_ERROR, errMsg, exc);
}
log.info("Configured ZooKeeperStorageIO with znodeBase: "+znodeBase);
}
示例12: create
import org.apache.solr.core.SolrResourceLoader; //导入依赖的package包/类
/** Returns an index schema created from a local resource */
public IndexSchema create(String resourceName, SolrConfig config) {
SolrResourceLoader loader = config.getResourceLoader();
InputStream schemaInputStream = null;
if (null == resourceName) {
resourceName = IndexSchema.DEFAULT_SCHEMA_FILE;
}
try {
schemaInputStream = loader.openSchema(resourceName);
} catch (Exception e) {
final String msg = "Error loading schema resource " + resourceName;
log.error(msg, e);
throw new SolrException(ErrorCode.SERVER_ERROR, msg, e);
}
InputSource inputSource = new InputSource(schemaInputStream);
inputSource.setSystemId(SystemIdResolver.createSystemIdFromResourceName(resourceName));
IndexSchema schema = new IndexSchema(config, resourceName, inputSource);
return schema;
}
示例13: readSimilarity
import org.apache.solr.core.SolrResourceLoader; //导入依赖的package包/类
static SimilarityFactory readSimilarity(SolrResourceLoader loader, Node node) {
if (node==null) {
return null;
} else {
SimilarityFactory similarityFactory;
final String classArg = ((Element) node).getAttribute(SimilarityFactory.CLASS_NAME);
final Object obj = loader.newInstance(classArg, Object.class, "search.similarities.");
if (obj instanceof SimilarityFactory) {
// configure a factory, get a similarity back
final NamedList<Object> namedList = DOMUtil.childNodesToNamedList(node);
namedList.add(SimilarityFactory.CLASS_NAME, classArg);
SolrParams params = SolrParams.toSolrParams(namedList);
similarityFactory = (SimilarityFactory)obj;
similarityFactory.init(params);
} else {
// just like always, assume it's a Similarity and get a ClassCastException - reasonable error handling
similarityFactory = new SimilarityFactory() {
@Override
public Similarity getSimilarity() {
return (Similarity) obj;
}
};
}
return similarityFactory;
}
}
示例14: testReloadFromPersistentStorage
import org.apache.solr.core.SolrResourceLoader; //导入依赖的package包/类
@Test
public void testReloadFromPersistentStorage() throws Exception {
SolrResourceLoader loader = new SolrResourceLoader("./");
File unitTestStorageDir = createTempDir("testRestManager");
assertTrue(unitTestStorageDir.getAbsolutePath()+" is not a directory!",
unitTestStorageDir.isDirectory());
assertTrue(unitTestStorageDir.canRead());
assertTrue(unitTestStorageDir.canWrite());
NamedList<String> ioInitArgs = new NamedList<>();
ioInitArgs.add(ManagedResourceStorage.STORAGE_DIR_INIT_ARG,
unitTestStorageDir.getAbsolutePath());
StorageIO storageIO = new ManagedResourceStorage.FileStorageIO();
storageIO.configure(loader, ioInitArgs);
NamedList<String> initArgs = new NamedList<>();
RestManager restManager = new RestManager();
restManager.init(loader, initArgs, storageIO);
// verifies a RestManager can be reloaded from a previous RestManager's data
RestManager restManager2 = new RestManager();
restManager2.init(loader, initArgs, storageIO);
}
示例15: testZkBasedJsonStorage
import org.apache.solr.core.SolrResourceLoader; //导入依赖的package包/类
/**
* Runs persisted managed resource creation and update tests on Zookeeper storage.
*/
@Test
public void testZkBasedJsonStorage() throws Exception {
// test using ZooKeeper
assertTrue("Not using ZooKeeper", h.getCoreContainer().isZooKeeperAware());
SolrZkClient zkClient = h.getCoreContainer().getZkController().getZkClient();
SolrResourceLoader loader = new SolrResourceLoader("./");
// Solr unit tests can only write to their working directory due to
// a custom Java Security Manager installed in the test environment
NamedList<String> initArgs = new NamedList<>();
try {
ZooKeeperStorageIO zkStorageIO = new ZooKeeperStorageIO(zkClient, "/test");
zkStorageIO.configure(loader, initArgs);
doStorageTests(loader, zkStorageIO);
} finally {
zkClient.close();
}
}