Search in sources :

Example 21 with MMapDirectory

use of org.apache.lucene.store.MMapDirectory in project Krill by KorAP.

the class TestBenchmarkSpans method checkBenchmarkClasses.

@Test
public void checkBenchmarkClasses() throws IOException {
    // [orth=Der]{1:[orth=Mann]{2:[orth=und]}}
    Properties prop = new Properties();
    InputStream fr = new FileInputStream(getClass().getResource("/krill.properties").getFile());
    prop.load(fr);
    // Get the real index
    KrillIndex ki = new KrillIndex(new MMapDirectory(Paths.get(prop.getProperty("krill.indexDir"))));
    // Create a container for virtual collections:
    KrillCollection kc = new KrillCollection(ki);
    long t1 = 0, t2 = 0;
    // Without classes
    String json = getString(getClass().getResource("/queries/benchmark5-ohne.jsonld").getFile());
    int rounds = 2000;
    Result kr = new Result();
    t1 = System.nanoTime();
    for (int i = 1; i <= rounds; i++) {
        kr = new Krill(json).apply(ki);
    }
    ;
    t2 = System.nanoTime();
    double seconds = (double) (t2 - t1) / 1000000000.0;
    // System.out.println("It took " + seconds + " seconds without classes");
    t1 = 0;
    t2 = 0;
    // With classes
    json = getString(getClass().getResource("/queries/benchmark5.jsonld").getFile());
    t1 = System.nanoTime();
    for (int i = 1; i <= rounds; i++) {
        kr = new Krill(json).apply(ki);
    }
    ;
    t2 = System.nanoTime();
    seconds = (double) (t2 - t1) / 1000000000.0;
    // System.out.println("It took " + seconds + " seconds with classes");
    t1 = 0;
    t2 = 0;
    // With submatch
    json = getString(getClass().getResource("/queries/benchmark5-submatch.jsonld").getFile());
    t1 = System.nanoTime();
    for (int i = 1; i <= rounds; i++) {
        kr = new Krill(json).apply(ki);
    }
    ;
    t2 = System.nanoTime();
    seconds = (double) (t2 - t1) / 1000000000.0;
// System.out.println("It took " + seconds + " seconds with submatches");
/**
 * HERE IS A BUG!
 */
// System.err.println(kr.toJsonString());
// System.err.println(kr.toJSON());
// System.err.println(kr.getMatch(3).getSnippetBrackets());
// 2000 rounds:
// It took 10.872934435 seconds without classes
// It took 22.581117396 seconds with classes
// It took 10.703933598 seconds without classes
// It took 19.354674517 seconds with classes
// It took 10.939948726 seconds without classes
// It took 16.998470662 seconds with classes
// It took 10.900975837 seconds without classes
// It took 14.902590949 seconds with classes
// It took 10.365989238 seconds without classes
// It took 13.833405885 seconds with classes
// It took 15.368675425 seconds without classes
// It took 18.347603186 seconds with classes
// It took 15.941057294 seconds with submatches
// It took 15.241253549 seconds without classes
// It took 17.30375624 seconds with classes
// It took 15.367171254 seconds with submatches
}
Also used : Krill(de.ids_mannheim.korap.Krill) KrillIndex(de.ids_mannheim.korap.KrillIndex) MMapDirectory(org.apache.lucene.store.MMapDirectory) KrillCollection(de.ids_mannheim.korap.KrillCollection) Result(de.ids_mannheim.korap.response.Result) Test(org.junit.Test)

Example 22 with MMapDirectory

use of org.apache.lucene.store.MMapDirectory in project Krill by KorAP.

the class TestBenchmarkSpans method checkBenchmark3.

@Test
public void checkBenchmark3() throws IOException {
    Properties prop = new Properties();
    InputStream fr = new FileInputStream(getClass().getResource("/krill.properties").getFile());
    prop.load(fr);
    // Get the real index
    KrillIndex ki = new KrillIndex(new MMapDirectory(Paths.get(prop.getProperty("krill.indexDir"))));
    // Create a container for virtual collections:
    KrillCollection kc = new KrillCollection(ki);
    long t1 = 0, t2 = 0;
    // / cosmas20.json!!!
    String json = getString(getClass().getResource("/queries/benchmark3.jsonld").getFile());
    int rounds = 500;
    Result kr = new Result();
    t1 = System.nanoTime();
    for (int i = 1; i <= rounds; i++) {
        kr = new Krill(json).apply(ki);
    }
    ;
    t2 = System.nanoTime();
    assertEquals("TotalResults", kr.getTotalResults(), 70229);
    // System.err.println(kr.toJSON());
    // long seconds = (long) (t2 - t1 / 1000) % 60 ;
    double seconds = (double) (t2 - t1) / 1000000000.0;
    System.out.println("It took " + seconds + " seconds");
// 500 times:
// 71.715862716 seconds
}
Also used : Krill(de.ids_mannheim.korap.Krill) KrillIndex(de.ids_mannheim.korap.KrillIndex) MMapDirectory(org.apache.lucene.store.MMapDirectory) KrillCollection(de.ids_mannheim.korap.KrillCollection) Result(de.ids_mannheim.korap.response.Result) Test(org.junit.Test)

Example 23 with MMapDirectory

use of org.apache.lucene.store.MMapDirectory in project Krill by KorAP.

the class Node method getIndex.

/**
 * Get the associuated {@link KrillIndex}.
 *
 * @return The associated {@link KrillIndex}.
 */
public static KrillIndex getIndex() {
    // Index already instantiated
    if (index != null)
        return index;
    try {
        // Get a temporary index
        if (path == null) {
            // Temporary index
            index = new KrillIndex();
        } else // Get a MMap directory index
        {
            Path file = Paths.get(path);
            log.info("Loading index from {}", path);
            if (!file.toFile().exists()) {
                log.error("Index not found at {}", path);
                return null;
            }
            ;
            // Set real index
            index = new KrillIndex(new MMapDirectory(file));
        }
        ;
        return index;
    } catch (IOException e) {
        log.error("Index not loadable at {}: {}", path, e.getMessage());
    }
    ;
    return null;
}
Also used : Path(java.nio.file.Path) KrillIndex(de.ids_mannheim.korap.KrillIndex) MMapDirectory(org.apache.lucene.store.MMapDirectory)

Example 24 with MMapDirectory

use of org.apache.lucene.store.MMapDirectory in project cxf by apache.

the class TikaLuceneContentExtractorTest method setUp.

@Before
public void setUp() throws Exception {
    final Analyzer analyzer = new StandardAnalyzer();
    tempDirectory = Files.createTempDirectory("lucene");
    directory = new MMapDirectory(tempDirectory);
    IndexWriterConfig config = new IndexWriterConfig(analyzer);
    writer = new IndexWriter(directory, config);
    writer.commit();
    parser = new FiqlParser<>(SearchBean.class);
    extractor = new TikaLuceneContentExtractor(new PDFParser());
}
Also used : IndexWriter(org.apache.lucene.index.IndexWriter) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) PDFParser(org.apache.tika.parser.pdf.PDFParser) SearchBean(org.apache.cxf.jaxrs.ext.search.SearchBean) Analyzer(org.apache.lucene.analysis.Analyzer) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) MMapDirectory(org.apache.lucene.store.MMapDirectory) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig) Before(org.junit.Before)

Example 25 with MMapDirectory

use of org.apache.lucene.store.MMapDirectory in project crate by crate.

the class FsDirectoryFactoryTests method testPreload.

@Test
public void testPreload() throws IOException {
    doTestPreload();
    doTestPreload("nvd", "dvd", "tim");
    doTestPreload("*");
    Settings build = Settings.builder().put(IndexModule.INDEX_STORE_TYPE_SETTING.getKey(), IndexModule.Type.HYBRIDFS.name().toLowerCase(Locale.ROOT)).putList(IndexModule.INDEX_STORE_PRE_LOAD_SETTING.getKey(), "dvd", "bar").build();
    try (Directory directory = newDirectory(build)) {
        assertTrue(FsDirectoryFactory.isHybridFs(directory));
        FsDirectoryFactory.HybridDirectory hybridDirectory = (FsDirectoryFactory.HybridDirectory) directory;
        assertTrue(hybridDirectory.useDelegate("foo.dvd"));
        assertTrue(hybridDirectory.useDelegate("foo.nvd"));
        assertTrue(hybridDirectory.useDelegate("foo.tim"));
        assertTrue(hybridDirectory.useDelegate("foo.tip"));
        assertTrue(hybridDirectory.useDelegate("foo.cfs"));
        assertTrue(hybridDirectory.useDelegate("foo.dim"));
        assertFalse(hybridDirectory.useDelegate("foo.bar"));
        MMapDirectory delegate = hybridDirectory.getDelegate();
        assertThat(delegate, Matchers.instanceOf(FsDirectoryFactory.PreLoadMMapDirectory.class));
        FsDirectoryFactory.PreLoadMMapDirectory preLoadMMapDirectory = (FsDirectoryFactory.PreLoadMMapDirectory) delegate;
        assertTrue(preLoadMMapDirectory.useDelegate("foo.dvd"));
        assertTrue(preLoadMMapDirectory.useDelegate("foo.bar"));
    }
}
Also used : MMapDirectory(org.apache.lucene.store.MMapDirectory) Settings(org.elasticsearch.common.settings.Settings) IndexSettings(org.elasticsearch.index.IndexSettings) MMapDirectory(org.apache.lucene.store.MMapDirectory) Directory(org.apache.lucene.store.Directory) SimpleFSDirectory(org.apache.lucene.store.SimpleFSDirectory) NIOFSDirectory(org.apache.lucene.store.NIOFSDirectory) Test(org.junit.Test)

Aggregations

MMapDirectory (org.apache.lucene.store.MMapDirectory)25 Directory (org.apache.lucene.store.Directory)10 NIOFSDirectory (org.apache.lucene.store.NIOFSDirectory)8 SimpleFSDirectory (org.apache.lucene.store.SimpleFSDirectory)8 KrillIndex (de.ids_mannheim.korap.KrillIndex)6 Test (org.junit.Test)6 Krill (de.ids_mannheim.korap.Krill)5 KrillCollection (de.ids_mannheim.korap.KrillCollection)5 Result (de.ids_mannheim.korap.response.Result)5 Path (java.nio.file.Path)5 FSDirectory (org.apache.lucene.store.FSDirectory)5 Settings (org.elasticsearch.common.settings.Settings)5 IndexSettings (org.elasticsearch.index.IndexSettings)5 Document (org.apache.lucene.document.Document)4 MockAnalyzer (org.apache.lucene.analysis.MockAnalyzer)3 Field (org.apache.lucene.document.Field)3 FeatureExtractors (io.anserini.ltr.feature.FeatureExtractors)2 RerankerCascade (io.anserini.rerank.RerankerCascade)2 Rm3Reranker (io.anserini.rerank.rm3.Rm3Reranker)2 Qrels (io.anserini.util.Qrels)2