use of org.apache.lucene.index.MergePolicy in project lucene-solr by apache.
the class WrapperMergePolicyFactoryTest method implTestUpgradeIndexMergePolicyFactory.
private void implTestUpgradeIndexMergePolicyFactory(Double wrappingNoCFSRatio, Double wrappedNoCFSRatio) {
final MergePolicyFactoryArgs args = new MergePolicyFactoryArgs();
if (wrappingNoCFSRatio != null) {
// noCFSRatio for the wrapping merge policy
args.add("noCFSRatio", wrappingNoCFSRatio);
}
args.add(WrapperMergePolicyFactory.WRAPPED_PREFIX, "wrapped");
args.add("wrapped.class", TieredMergePolicyFactory.class.getName());
if (wrappedNoCFSRatio != null) {
// noCFSRatio for the wrapped merge policy
args.add("wrapped.noCFSRatio", wrappedNoCFSRatio);
}
MergePolicyFactory mpf;
try {
mpf = new UpgradeIndexMergePolicyFactory(resourceLoader, args, null);
assertFalse("Should only reach here if wrapping and wrapped args don't overlap!", (wrappingNoCFSRatio != null && wrappedNoCFSRatio != null));
for (int ii = 1; ii <= 2; ++ii) {
// it should be okay to call getMergePolicy() more than once
final MergePolicy mp = mpf.getMergePolicy();
if (wrappingNoCFSRatio != null) {
assertEquals("#" + ii + " wrappingNoCFSRatio", wrappingNoCFSRatio.doubleValue(), mp.getNoCFSRatio(), 0.0d);
}
if (wrappedNoCFSRatio != null) {
assertEquals("#" + ii + " wrappedNoCFSRatio", wrappedNoCFSRatio.doubleValue(), mp.getNoCFSRatio(), 0.0d);
}
assertSame(mp.getClass(), UpgradeIndexMergePolicy.class);
}
} catch (IllegalArgumentException iae) {
assertEquals("Wrapping and wrapped merge policy args overlap! [noCFSRatio]", iae.getMessage());
assertTrue("Should only reach here if wrapping and wrapped args do overlap!", (wrappingNoCFSRatio != null && wrappedNoCFSRatio != null));
}
}
use of org.apache.lucene.index.MergePolicy in project lucene-solr by apache.
the class SolrIndexConfigTest method testSortingMPSolrIndexConfigCreation.
public void testSortingMPSolrIndexConfigCreation() throws Exception {
final String expectedFieldName = "timestamp_i_dvo";
final SortField.Type expectedFieldType = SortField.Type.INT;
final boolean expectedFieldSortDescending = true;
SolrConfig solrConfig = new SolrConfig(instanceDir, solrConfigFileNameSortingMergePolicyFactory, null);
SolrIndexConfig solrIndexConfig = new SolrIndexConfig(solrConfig, null, null);
assertNotNull(solrIndexConfig);
IndexSchema indexSchema = IndexSchemaFactory.buildIndexSchema(schemaFileName, solrConfig);
h.getCore().setLatestSchema(indexSchema);
IndexWriterConfig iwc = solrIndexConfig.toIndexWriterConfig(h.getCore());
final MergePolicy mergePolicy = iwc.getMergePolicy();
assertNotNull("null mergePolicy", mergePolicy);
assertTrue("mergePolicy (" + mergePolicy + ") is not a SortingMergePolicy", mergePolicy instanceof SortingMergePolicy);
final SortingMergePolicy sortingMergePolicy = (SortingMergePolicy) mergePolicy;
final Sort expected = new Sort(new SortField(expectedFieldName, expectedFieldType, expectedFieldSortDescending));
final Sort actual = sortingMergePolicy.getSort();
assertEquals("SortingMergePolicy.getSort", expected, actual);
}
use of org.apache.lucene.index.MergePolicy in project lucene-solr by apache.
the class SimplePrimaryNode method initWriter.
private static IndexWriter initWriter(int id, Random random, Path indexPath, boolean doCheckIndexOnClose) throws IOException {
Directory dir = SimpleReplicaNode.getDirectory(random, id, indexPath, doCheckIndexOnClose);
MockAnalyzer analyzer = new MockAnalyzer(random);
analyzer.setMaxTokenLength(TestUtil.nextInt(random, 1, IndexWriter.MAX_TERM_LENGTH));
IndexWriterConfig iwc = LuceneTestCase.newIndexWriterConfig(random, analyzer);
MergePolicy mp = iwc.getMergePolicy();
// Force more frequent merging so we stress merge warming:
if (mp instanceof TieredMergePolicy) {
TieredMergePolicy tmp = (TieredMergePolicy) mp;
tmp.setSegmentsPerTier(3);
tmp.setMaxMergeAtOnce(3);
} else if (mp instanceof LogMergePolicy) {
LogMergePolicy lmp = (LogMergePolicy) mp;
lmp.setMergeFactor(3);
}
IndexWriter writer = new IndexWriter(dir, iwc);
TestUtil.reduceOpenFiles(writer);
return writer;
}
use of org.apache.lucene.index.MergePolicy in project lucene-solr by apache.
the class SimpleMergePolicyFactory method getMergePolicy.
@Override
public final MergePolicy getMergePolicy() {
final MergePolicy mp = getMergePolicyInstance();
args.invokeSetters(mp);
return mp;
}
use of org.apache.lucene.index.MergePolicy in project lucene-solr by apache.
the class SegmentsInfoRequestHandler method getMergeCandidatesNames.
private List<String> getMergeCandidatesNames(SolrQueryRequest req, SegmentInfos infos) throws IOException {
List<String> result = new ArrayList<String>();
RefCounted<IndexWriter> refCounted = req.getCore().getSolrCoreState().getIndexWriter(req.getCore());
try {
IndexWriter indexWriter = refCounted.get();
//get chosen merge policy
MergePolicy mp = indexWriter.getConfig().getMergePolicy();
//Find merges
MergeSpecification findMerges = mp.findMerges(MergeTrigger.EXPLICIT, infos, indexWriter);
if (findMerges != null && findMerges.merges != null && findMerges.merges.size() > 0) {
for (OneMerge merge : findMerges.merges) {
//TODO: add merge grouping
for (SegmentCommitInfo mergeSegmentInfo : merge.segments) {
result.add(mergeSegmentInfo.info.name);
}
}
}
return result;
} finally {
refCounted.decref();
}
}
Aggregations