本文整理汇总了Java中org.apache.solr.core.SolrCore类的典型用法代码示例。如果您正苦于以下问题:Java SolrCore类的具体用法?Java SolrCore怎么用?Java SolrCore使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SolrCore类属于org.apache.solr.core包,在下文中一共展示了SolrCore类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: SuggestionService
import org.apache.solr.core.SolrCore; //导入依赖的package包/类
public SuggestionService(SolrCore solrCore, NamedList args) {
NamedList l = new NamedList();
//set spellcheck component if there is one
if(((ArrayList)args.get("first-components")).contains("spellcheck")) {
List component = new ArrayList<String>();
component.add("spellcheck");
l.add("first-components",component);
spellcheck_enabled = true;
}
if(args.get("defaults") != null && ((NamedList)args.get("defaults")).get(SuggestionRequestParams.SUGGESTION_INTERNAL_LIMIT) != null) {
internalFacetLimit = (String)((NamedList)args.get("defaults")).get(SuggestionRequestParams.SUGGESTION_INTERNAL_LIMIT);
}
this.solrCore = solrCore;
this.searchHandler = new SearchHandler();
this.searchHandler.init(l);
this.searchHandler.inform(solrCore);
}
示例2: analyzeString
import org.apache.solr.core.SolrCore; //导入依赖的package包/类
/**
* analyzes string like the given field
* @param field the name of the field
* @param value the string to analyze
* @return the analyzed string
*/
public static String analyzeString(SolrCore core, String field, String value) {
try {
StringBuilder b = new StringBuilder();
try (TokenStream ts = core.getLatestSchema().getFieldType(field).getQueryAnalyzer().tokenStream(field, new StringReader(value))) {
ts.reset();
while (ts.incrementToken()) {
b.append(" ");
CharTermAttribute attr = ts.getAttribute(CharTermAttribute.class);
b.append(attr);
}
}
return b.toString().trim();
} catch (IOException e) {
//FIXME: This error should be properly logged!
e.printStackTrace();
return value;
}
}
示例3: testProperties
import org.apache.solr.core.SolrCore; //导入依赖的package包/类
@Test
public void testProperties() throws Exception{
SolrCore core = h.getCore();
IndexSchema schema = core.getLatestSchema();
assertFalse(schema.getField("id").multiValued());
// Test TrieDate fields. The following asserts are expecting a field type defined as:
String expectedDefinition = "<fieldtype name=\"tdatedv\" class=\"solr.TrieDateField\" " +
"precisionStep=\"6\" docValues=\"true\" multiValued=\"true\"/>";
FieldType tdatedv = schema.getFieldType("foo_tdtdv");
assertTrue("Expecting a field type defined as " + expectedDefinition,
tdatedv instanceof TrieDateField);
assertTrue("Expecting a field type defined as " + expectedDefinition,
tdatedv.hasProperty(FieldProperties.DOC_VALUES));
assertTrue("Expecting a field type defined as " + expectedDefinition,
tdatedv.isMultiValued());
assertEquals("Expecting a field type defined as " + expectedDefinition,
6, ((TrieDateField)tdatedv).getPrecisionStep());
}
示例4: testSourceGlobMatchesNoDynamicOrExplicitField
import org.apache.solr.core.SolrCore; //导入依赖的package包/类
@Test
public void testSourceGlobMatchesNoDynamicOrExplicitField()
{
// SOLR-4650: copyField source globs should not have to match an explicit or dynamic field
SolrCore core = h.getCore();
IndexSchema schema = core.getLatestSchema();
assertNull("'testing123_*' should not be (or match) a dynamic or explicit field", schema.getFieldOrNull("testing123_*"));
assertTrue("schema should contain dynamic field '*_s'", schema.getDynamicPattern("*_s").equals("*_s"));
assertU(adoc("id", "A5", "sku1", "10-1839ACX-93", "testing123_s", "AAM46"));
assertU(commit());
Map<String,String> args = new HashMap<>();
args.put( CommonParams.Q, "text:AAM46" );
args.put( "indent", "true" );
SolrQueryRequest req = new LocalSolrQueryRequest( core, new MapSolrParams( args) );
assertQ("sku2 copied to text", req
,"//*[@numFound='1']"
,"//result/doc[1]/str[@name='id'][.='A5']"
);
}
示例5: setUp
import org.apache.solr.core.SolrCore; //导入依赖的package包/类
@Override
public void setUp() throws Exception {
saveProp = System.getProperty("solr.directoryFactory");
System.setProperty("solr.directoryFactory", "solr.StandardDirectoryFactory");
super.setUp();
File dataDir1 = createTempDir();
// setup datadirs
System.setProperty( "solr.core0.data.dir", dataDir1.getCanonicalPath() );
dataDir2 = createTempDir();
System.setProperty( "solr.core1.data.dir", this.dataDir2.getCanonicalPath() );
setupCoreContainer();
SolrCore.log.info("CORES=" + cores + " : " + cores.getCoreNames());
}
示例6: test404Locally
import org.apache.solr.core.SolrCore; //导入依赖的package包/类
public void test404Locally() throws Exception {
// we need to test that executing the handler directly does not
// throw an exception, just sets the exception on the response.
initCore("solrconfig.xml", "schema.xml");
try {
// bypass TestHarness since it will throw any exception found in the
// response.
SolrCore core = h.getCore();
SolrQueryResponse rsp = new SolrQueryResponse();
core.execute(core.getRequestHandler("/admin/file"),
req("file", "does-not-exist-404.txt"), rsp);
assertNotNull("no exception in response", rsp.getException());
assertTrue("wrong type of exception: " + rsp.getException().getClass(),
rsp.getException() instanceof SolrException);
assertEquals(404, ((SolrException)rsp.getException()).code());
} catch (Exception e) {
assertNull("Should not have caught an exception", e);
}
}
示例7: create
import org.apache.solr.core.SolrCore; //导入依赖的package包/类
@Override
public Dictionary create(SolrCore core, SolrIndexSearcher searcher) {
if(params == null) {
// should not happen; implies setParams was not called
throw new IllegalStateException("Value of params not set");
}
String field = (String)params.get(SolrSpellChecker.FIELD);
if (field == null) {
throw new IllegalArgumentException(SolrSpellChecker.FIELD + " is a mandatory parameter");
}
float threshold = params.get(THRESHOLD_TOKEN_FREQUENCY) == null ? 0.0f
: (Float)params.get(THRESHOLD_TOKEN_FREQUENCY);
return new HighFrequencyDictionary(searcher.getIndexReader(), field, threshold);
}
示例8: syncWithReplicas
import org.apache.solr.core.SolrCore; //导入依赖的package包/类
private boolean syncWithReplicas(ZkController zkController, SolrCore core,
ZkNodeProps props, String collection, String shardId, boolean peerSyncOnlyWithActive) {
List<ZkCoreNodeProps> nodes = zkController.getZkStateReader()
.getReplicaProps(collection, shardId,core.getCoreDescriptor().getCloudDescriptor().getCoreNodeName());
if (nodes == null) {
// I have no replicas
return true;
}
List<String> syncWith = new ArrayList<>();
for (ZkCoreNodeProps node : nodes) {
syncWith.add(node.getCoreUrl());
}
// if we can't reach a replica for sync, we still consider the overall sync a success
// TODO: as an assurance, we should still try and tell the sync nodes that we couldn't reach
// to recover once more?
PeerSync peerSync = new PeerSync(core, syncWith, core.getUpdateHandler().getUpdateLog().numRecordsToKeep, true, true, peerSyncOnlyWithActive);
return peerSync.sync();
}
示例9: EmbeddedSolrServer
import org.apache.solr.core.SolrCore; //导入依赖的package包/类
/**
* Use the other constructor using a CoreContainer and a name.
* @deprecated use {@link #EmbeddedSolrServer(CoreContainer, String)} instead.
*/
@Deprecated
public EmbeddedSolrServer( SolrCore core )
{
if ( core == null ) {
throw new NullPointerException("SolrCore instance required");
}
CoreDescriptor dcore = core.getCoreDescriptor();
if (dcore == null)
throw new NullPointerException("CoreDescriptor required");
CoreContainer cores = dcore.getCoreContainer();
if (cores == null)
throw new NullPointerException("CoreContainer required");
coreName = dcore.getName();
coreContainer = cores;
_parser = new SolrRequestParsers( null );
}
示例10: clearLog
import org.apache.solr.core.SolrCore; //导入依赖的package包/类
/**
* Clears the logs on the file system. Only call before init.
*
* @param core the SolrCore
* @param ulogPluginInfo the init info for the UpdateHandler
*/
@Override
public void clearLog(SolrCore core, PluginInfo ulogPluginInfo) {
if (ulogPluginInfo == null) return;
Path tlogDir = new Path(getTlogDir(core, ulogPluginInfo));
try {
if (fs != null && fs.exists(tlogDir)) {
String[] files = getLogList(tlogDir);
for (String file : files) {
Path f = new Path(tlogDir, file);
boolean s = fs.delete(f, false);
if (!s) {
log.error("Could not remove tlog file:" + f);
}
}
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例11: testMultiMap
import org.apache.solr.core.SolrCore; //导入依赖的package包/类
@Test
public void testMultiMap() {
SolrCore core = h.getCore();
UpdateRequestProcessorChain chained = core.getUpdateProcessingChain("uima-multi-map");
assertNotNull(chained);
UIMAUpdateRequestProcessorFactory factory = (UIMAUpdateRequestProcessorFactory) chained
.getFactories()[0];
assertNotNull(factory);
UpdateRequestProcessor processor = factory.getInstance(req(), null, null);
assertTrue(processor instanceof UIMAUpdateRequestProcessor);
SolrUIMAConfiguration conf = ((UIMAUpdateRequestProcessor)processor).solrUIMAConfiguration;
Map<String, Map<String, MapField>> map = conf.getTypesFeaturesFieldsMapping();
Map<String, MapField> subMap = map.get("a-type-which-can-have-multiple-features");
assertEquals(2, subMap.size());
assertEquals("1", subMap.get("A").getFieldName(null));
assertEquals("2", subMap.get("B").getFieldName(null));
}
示例12: processCommit
import org.apache.solr.core.SolrCore; //导入依赖的package包/类
protected void processCommit(final String chain) throws IOException {
SolrCore core = h.getCore();
UpdateRequestProcessorChain pc = core.getUpdateProcessingChain(chain);
assertNotNull("No Chain named: " + chain, pc);
SolrQueryResponse rsp = new SolrQueryResponse();
SolrQueryRequest req = new LocalSolrQueryRequest(core, new ModifiableSolrParams());
CommitUpdateCommand cmd = new CommitUpdateCommand(req,false);
UpdateRequestProcessor processor = pc.createProcessor(req, rsp);
try {
processor.processCommit(cmd);
} finally {
req.close();
}
}
示例13: testWithPolyFieldsAndFieldBoost
import org.apache.solr.core.SolrCore; //导入依赖的package包/类
@Test
public void testWithPolyFieldsAndFieldBoost() {
SolrCore core = h.getCore();
IndexSchema schema = core.getLatestSchema();
assertFalse(schema.getField("store").omitNorms());
assertTrue(schema.getField("store_0_coordinate").omitNorms());
assertTrue(schema.getField("store_1_coordinate").omitNorms());
assertFalse(schema.getField("amount").omitNorms());
assertTrue(schema.getField("amount" + FieldType.POLY_FIELD_SEPARATOR + "_currency").omitNorms());
assertTrue(schema.getField("amount" + FieldType.POLY_FIELD_SEPARATOR + "_amount_raw").omitNorms());
SolrInputDocument doc = new SolrInputDocument();
doc.addField( "store", "40.7143,-74.006", 3.0f );
doc.addField( "amount", "10.5", 3.0f );
Document out = DocumentBuilder.toDocument( doc, schema );
assertNotNull( out.get( "store" ) );
assertNotNull( out.get( "amount" ) );
assertNotNull(out.getField("store_0_coordinate"));
//NOTE: As the subtypes have omitNorm=true, they must have boost=1F, otherwise this is going to fail when adding the doc to Lucene.
assertTrue(1f == out.getField("store_0_coordinate").boost());
assertTrue(1f == out.getField("store_1_coordinate").boost());
assertTrue(1f == out.getField("amount" + FieldType.POLY_FIELD_SEPARATOR + "_currency").boost());
assertTrue(1f == out.getField("amount" + FieldType.POLY_FIELD_SEPARATOR + "_amount_raw").boost());
}
示例14: handleRequestBufferUpdatesAction
import org.apache.solr.core.SolrCore; //导入依赖的package包/类
private void handleRequestBufferUpdatesAction(SolrQueryRequest req, SolrQueryResponse rsp) {
SolrParams params = req.getParams();
String cname = params.get(CoreAdminParams.NAME, "");
log.info("Starting to buffer updates on core:" + cname);
try (SolrCore core = coreContainer.getCore(cname)) {
if (core == null)
throw new SolrException(ErrorCode.BAD_REQUEST, "Core [" + cname + "] does not exist");
UpdateLog updateLog = core.getUpdateHandler().getUpdateLog();
if (updateLog.getState() != UpdateLog.State.ACTIVE) {
throw new SolrException(ErrorCode.SERVER_ERROR, "Core " + cname + " not in active state");
}
updateLog.bufferUpdates();
rsp.add("core", cname);
rsp.add("status", "BUFFERING");
} catch (Throwable e) {
if (e instanceof SolrException)
throw (SolrException)e;
else
throw new SolrException(ErrorCode.SERVER_ERROR, "Could not start buffering updates", e);
} finally {
if (req != null) req.close();
}
}
示例15: calcEtag
import org.apache.solr.core.SolrCore; //导入依赖的package包/类
/**
* Calculates a tag for the ETag header.
*
* @return a tag
*/
public static String calcEtag(final SolrQueryRequest solrReq) {
final SolrCore core = solrReq.getCore();
final long currentIndexVersion
= solrReq.getSearcher().getIndexReader().getVersion();
EtagCacheVal etagCache = etagCoreCache.get(core);
if (null == etagCache) {
final String etagSeed
= core.getSolrConfig().getHttpCachingConfig().getEtagSeed();
etagCache = new EtagCacheVal(etagSeed);
etagCoreCache.put(core, etagCache);
}
return etagCache.calcEtag(currentIndexVersion);
}