Search in sources :

Example 6 with LogMergePolicy

use of org.apache.lucene.index.LogMergePolicy in project lucene-solr by apache.

the class TestMergePolicyConfig method implTestLogMergePolicyConfig.

private void implTestLogMergePolicyConfig(String solrConfigFileName, Class<? extends LogMergePolicy> mpClass) throws Exception {
    initCore(solrConfigFileName, "schema-minimal.xml");
    IndexWriterConfig iwc = solrConfig.indexConfig.toIndexWriterConfig(h.getCore());
    // verify some props set to -1 get lucene internal defaults
    assertEquals(-1, solrConfig.indexConfig.maxBufferedDocs);
    assertEquals(IndexWriterConfig.DISABLE_AUTO_FLUSH, iwc.getMaxBufferedDocs());
    assertEquals(-1, solrConfig.indexConfig.ramBufferSizeMB, 0.0D);
    assertEquals(IndexWriterConfig.DEFAULT_RAM_BUFFER_SIZE_MB, iwc.getRAMBufferSizeMB(), 0.0D);
    LogMergePolicy logMP = assertAndCast(mpClass, iwc.getMergePolicy());
    assertEquals(11, logMP.getMergeFactor());
    assertEquals(456, logMP.getMaxMergeDocs());
}
Also used : LogMergePolicy(org.apache.lucene.index.LogMergePolicy) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig)

Example 7 with LogMergePolicy

use of org.apache.lucene.index.LogMergePolicy in project lucene-solr by apache.

the class FileBasedSpellChecker method loadExternalFileDictionary.

private void loadExternalFileDictionary(SolrCore core, SolrIndexSearcher searcher) {
    try {
        IndexSchema schema = null == searcher ? core.getLatestSchema() : searcher.getSchema();
        // Get the field's analyzer
        if (fieldTypeName != null && schema.getFieldTypeNoEx(fieldTypeName) != null) {
            FieldType fieldType = schema.getFieldTypes().get(fieldTypeName);
            // Do index-time analysis using the given fieldType's analyzer
            RAMDirectory ramDir = new RAMDirectory();
            LogMergePolicy mp = new LogByteSizeMergePolicy();
            mp.setMergeFactor(300);
            IndexWriter writer = new IndexWriter(ramDir, new IndexWriterConfig(fieldType.getIndexAnalyzer()).setMaxBufferedDocs(150).setMergePolicy(mp).setOpenMode(IndexWriterConfig.OpenMode.CREATE));
            List<String> lines = core.getResourceLoader().getLines(sourceLocation, characterEncoding);
            for (String s : lines) {
                Document d = new Document();
                d.add(new TextField(WORD_FIELD_NAME, s, Field.Store.NO));
                writer.addDocument(d);
            }
            writer.forceMerge(1);
            writer.close();
            dictionary = new HighFrequencyDictionary(DirectoryReader.open(ramDir), WORD_FIELD_NAME, 0.0f);
        } else {
            // check if character encoding is defined
            if (characterEncoding == null) {
                dictionary = new PlainTextDictionary(core.getResourceLoader().openResource(sourceLocation));
            } else {
                dictionary = new PlainTextDictionary(new InputStreamReader(core.getResourceLoader().openResource(sourceLocation), characterEncoding));
            }
        }
    } catch (IOException e) {
        log.error("Unable to load spellings", e);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) IOException(java.io.IOException) Document(org.apache.lucene.document.Document) RAMDirectory(org.apache.lucene.store.RAMDirectory) FieldType(org.apache.solr.schema.FieldType) HighFrequencyDictionary(org.apache.lucene.search.spell.HighFrequencyDictionary) LogByteSizeMergePolicy(org.apache.lucene.index.LogByteSizeMergePolicy) IndexWriter(org.apache.lucene.index.IndexWriter) PlainTextDictionary(org.apache.lucene.search.spell.PlainTextDictionary) LogMergePolicy(org.apache.lucene.index.LogMergePolicy) TextField(org.apache.lucene.document.TextField) IndexSchema(org.apache.solr.schema.IndexSchema) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig)

Example 8 with LogMergePolicy

use of org.apache.lucene.index.LogMergePolicy in project lucene-solr by apache.

the class TestMergeSchedulerExternal method testSubclassConcurrentMergeScheduler.

public void testSubclassConcurrentMergeScheduler() throws IOException {
    MockDirectoryWrapper dir = newMockDirectory();
    dir.failOn(new FailOnlyOnMerge());
    Document doc = new Document();
    Field idField = newStringField("id", "", Field.Store.YES);
    doc.add(idField);
    IndexWriterConfig iwc = newIndexWriterConfig(new MockAnalyzer(random())).setMergeScheduler(new MyMergeScheduler()).setMaxBufferedDocs(2).setRAMBufferSizeMB(IndexWriterConfig.DISABLE_AUTO_FLUSH).setMergePolicy(newLogMergePolicy());
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    infoStream = new PrintStreamInfoStream(new PrintStream(baos, true, IOUtils.UTF_8));
    iwc.setInfoStream(infoStream);
    IndexWriter writer = new IndexWriter(dir, iwc);
    LogMergePolicy logMP = (LogMergePolicy) writer.getConfig().getMergePolicy();
    logMP.setMergeFactor(10);
    for (int i = 0; i < 20; i++) {
        writer.addDocument(doc);
    }
    try {
        ((MyMergeScheduler) writer.getConfig().getMergeScheduler()).sync();
    } catch (IllegalStateException ise) {
    // OK
    }
    writer.rollback();
    try {
        assertTrue(mergeThreadCreated);
        assertTrue(mergeCalled);
        assertTrue(excCalled);
    } catch (AssertionError ae) {
        System.out.println("TEST FAILED; IW infoStream output:");
        System.out.println(baos.toString(IOUtils.UTF_8));
        throw ae;
    }
    dir.close();
}
Also used : MockDirectoryWrapper(org.apache.lucene.store.MockDirectoryWrapper) PrintStream(java.io.PrintStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Document(org.apache.lucene.document.Document) Field(org.apache.lucene.document.Field) MockAnalyzer(org.apache.lucene.analysis.MockAnalyzer) IndexWriter(org.apache.lucene.index.IndexWriter) PrintStreamInfoStream(org.apache.lucene.util.PrintStreamInfoStream) LogMergePolicy(org.apache.lucene.index.LogMergePolicy) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig)

Aggregations

LogMergePolicy (org.apache.lucene.index.LogMergePolicy)8 IndexWriterConfig (org.apache.lucene.index.IndexWriterConfig)7 IndexWriter (org.apache.lucene.index.IndexWriter)4 IOException (java.io.IOException)2 MockAnalyzer (org.apache.lucene.analysis.MockAnalyzer)2 Document (org.apache.lucene.document.Document)2 ConcurrentMergeScheduler (org.apache.lucene.index.ConcurrentMergeScheduler)2 LogByteSizeMergePolicy (org.apache.lucene.index.LogByteSizeMergePolicy)2 MergePolicy (org.apache.lucene.index.MergePolicy)2 TieredMergePolicy (org.apache.lucene.index.TieredMergePolicy)2 Directory (org.apache.lucene.store.Directory)2 RAMDirectory (org.apache.lucene.store.RAMDirectory)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStreamReader (java.io.InputStreamReader)1 PrintStream (java.io.PrintStream)1 PostingsFormat (org.apache.lucene.codecs.PostingsFormat)1 Lucene70Codec (org.apache.lucene.codecs.lucene70.Lucene70Codec)1 Field (org.apache.lucene.document.Field)1 TextField (org.apache.lucene.document.TextField)1 FacetLabel (org.apache.lucene.facet.taxonomy.FacetLabel)1