Search in sources :

Example 1 with MergePolicy

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));
    }
}
Also used : NoMergePolicy(org.apache.lucene.index.NoMergePolicy) MergePolicy(org.apache.lucene.index.MergePolicy) UpgradeIndexMergePolicy(org.apache.lucene.index.UpgradeIndexMergePolicy) TieredMergePolicy(org.apache.lucene.index.TieredMergePolicy)

Example 2 with MergePolicy

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);
}
Also used : SolrConfig(org.apache.solr.core.SolrConfig) SortingMergePolicy(org.apache.solr.index.SortingMergePolicy) MergePolicy(org.apache.lucene.index.MergePolicy) TieredMergePolicy(org.apache.lucene.index.TieredMergePolicy) SortingMergePolicy(org.apache.solr.index.SortingMergePolicy) Sort(org.apache.lucene.search.Sort) SortField(org.apache.lucene.search.SortField) IndexSchema(org.apache.solr.schema.IndexSchema) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig)

Example 3 with MergePolicy

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;
}
Also used : TieredMergePolicy(org.apache.lucene.index.TieredMergePolicy) MockAnalyzer(org.apache.lucene.analysis.MockAnalyzer) IndexWriter(org.apache.lucene.index.IndexWriter) MergePolicy(org.apache.lucene.index.MergePolicy) LogMergePolicy(org.apache.lucene.index.LogMergePolicy) TieredMergePolicy(org.apache.lucene.index.TieredMergePolicy) LogMergePolicy(org.apache.lucene.index.LogMergePolicy) Directory(org.apache.lucene.store.Directory) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig)

Example 4 with MergePolicy

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;
}
Also used : MergePolicy(org.apache.lucene.index.MergePolicy)

Example 5 with MergePolicy

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();
    }
}
Also used : OneMerge(org.apache.lucene.index.MergePolicy.OneMerge) SegmentCommitInfo(org.apache.lucene.index.SegmentCommitInfo) IndexWriter(org.apache.lucene.index.IndexWriter) MergePolicy(org.apache.lucene.index.MergePolicy) MergeSpecification(org.apache.lucene.index.MergePolicy.MergeSpecification) ArrayList(java.util.ArrayList)

Aggregations

MergePolicy (org.apache.lucene.index.MergePolicy)11 IndexWriterConfig (org.apache.lucene.index.IndexWriterConfig)5 TieredMergePolicy (org.apache.lucene.index.TieredMergePolicy)5 IndexWriter (org.apache.lucene.index.IndexWriter)3 Sort (org.apache.lucene.search.Sort)3 MockAnalyzer (org.apache.lucene.analysis.MockAnalyzer)2 ConcurrentMergeScheduler (org.apache.lucene.index.ConcurrentMergeScheduler)2 LogMergePolicy (org.apache.lucene.index.LogMergePolicy)2 MergeScheduler (org.apache.lucene.index.MergeScheduler)2 NoMergePolicy (org.apache.lucene.index.NoMergePolicy)2 UpgradeIndexMergePolicy (org.apache.lucene.index.UpgradeIndexMergePolicy)2 SortField (org.apache.lucene.search.SortField)2 Directory (org.apache.lucene.store.Directory)2 SortingMergePolicy (org.apache.solr.index.SortingMergePolicy)2 IndexSchema (org.apache.solr.schema.IndexSchema)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Analyzer (org.apache.lucene.analysis.Analyzer)1 Document (org.apache.lucene.document.Document)1 NumericDocValuesField (org.apache.lucene.document.NumericDocValuesField)1