Пример #1
0
IndexLoader::IndexLoader(const std::string& path, const LoadingOptions& options)
    : m_meaningDictionary(path + "/" + MEANING_DICTIONARY_FILE) {

    // we need the two databases to include hits
    if (options.includeHits) {
        auto formulaDb = new LevFormulaDb();
        m_formulaDb = unique_ptr<FormulaDb>(formulaDb);
        formulaDb->open((path + "/" + FORMULA_DB_FILE).c_str());
        PRINT_LOG("Loaded FormulaDb\n");

        auto crawlDb = new LevCrawlDb();
        m_crawlDb = unique_ptr<CrawlDb>(crawlDb);
        crawlDb->open((path + "/" + CRAWL_DB_FILE).c_str());
        PRINT_LOG("Loaded CrawlDb\n");

        m_dbQueryManager =
            unique_ptr<DbQueryManager>(new DbQueryManager(crawlDb, formulaDb));
    }

    if (memsector_load(&m_memsectorHandler,
                       (path + "/" + INDEX_MEMSECTOR_FILE).c_str()) !=
        0) {
        throw runtime_error("Error while loading memsector " + path + "/" +
                            INDEX_MEMSECTOR_FILE);
    }
    PRINT_LOG("Loaded Index\n");

    m_index.ms = m_memsectorHandler.ms;
    m_index.root = memsector_get_root(&m_memsectorHandler);
}
Пример #2
0
static inline
int query_engine_tester(mws::MwsIndexNode* data,
                        encoded_formula_t* query,
                        result_callback_t cb,
                        void *cb_handle) {

    const char* ms_path = TMPFILE_PATH;
    memsector_writer_t mswr;
    memsector_handle_t ms;

    /* ensure the file does not exist */
    FAIL_ON(unlink(TMPFILE_PATH) != 0 && errno != ENOENT);

    FAIL_ON(memsector_create(&mswr, ms_path, TMPFILE_SIZE) != 0);
    printf("Memsector %s created\n", ms_path);

    data->exportToMemsector(&mswr);
    printf("Index exported to memsector\n");
    printf("Space used: %d\n", memsector_size_inuse(&mswr.ms_header->alloc_header));

    FAIL_ON(memsector_save(&mswr) != 0);
    printf("Memsector saved\n");

    FAIL_ON(memsector_load(&ms, ms_path) != 0);
    printf("Memsector loaded\n");

    if (query_engine_run(&ms.index, query, cb, cb_handle)
            == QUERY_ERROR) {
        goto fail;
    }
    printf("Query successfull\n");

    FAIL_ON(memsector_remove(&ms) != 0);
    printf("Memsector removed\n");

    return EXIT_SUCCESS;

fail:
    if (data) delete data;
    return EXIT_FAILURE;
}