Example #1
0
File: ind.c Project: dustin/ferret
Index *index_new(Store *store, Analyzer *analyzer, HashSet *def_fields,
                 bool create)
{
    Index *self = ALLOC_AND_ZERO(Index);
    HashSetEntry *hse;
    /* FIXME: need to add these to the query parser */
    self->config = default_config;
    mutex_init(&self->mutex, NULL);
    self->has_writes = false;
    if (store) {
        REF(store);
        self->store = store;
    } else {
        self->store = open_ram_store();
        create = true;
    }
    if (analyzer) {
        self->analyzer = analyzer;
        REF(analyzer);
    } else {
        self->analyzer = mb_standard_analyzer_new(true);
    }

    if (create) {
        FieldInfos *fis = fis_new(STORE_YES, INDEX_YES,
                                  TERM_VECTOR_WITH_POSITIONS_OFFSETS);
        index_create(self->store, fis);
        fis_deref(fis);
    }

    /* options */
    self->key = NULL;
    self->id_field = intern("id");
    self->def_field = intern("id");
    self->auto_flush = false;
    self->check_latest = true;

    REF(self->analyzer);
    self->qp = qp_new(self->analyzer);
    for (hse = def_fields->first; hse; hse = hse->next) {
        qp_add_field(self->qp, (Symbol)hse->elem, true, true);
    }
    /* Index is a convenience class so set qp convenience options */
    self->qp->allow_any_fields = true;
    self->qp->clean_str = true;
    self->qp->handle_parse_errors = true;

    return self;
}
Example #2
0
static void sort_test_setup(Store *store)
{
    int i;
    IndexWriter *iw;
    FieldInfos *fis = fis_new(STORE_YES, INDEX_YES, TERM_VECTOR_YES);
    index_create(store, fis);
    fis_deref(fis);

    iw = iw_open(store, whitespace_analyzer_new(false), NULL);

    for (i = 0; i < NELEMS(data); i++) {
        add_sort_test_data(&data[i], iw);
    }
    iw_close(iw);
}
Example #3
0
void prepare_filter_index(Store *store)
{
    int i;
    IndexWriter *iw;
    FieldInfos *fis = fis_new(STORE_YES, INDEX_YES, TERM_VECTOR_NO);

    num      = intern("num");
    date     = intern("date");
    flipflop = intern("flipflop");

    struct FilterData data[FILTER_DOCS_SIZE] = {
        {"0", "20040601", "on"},
        {"1", "20041001", "off"},
        {"2", "20051101", "on"},
        {"3", "20041201", "off"},
        {"4", "20051101", "on"},
        {"5", "20041201", "off"},
        {"6", "20050101", "on"},
        {"7", "20040701", "off"},
        {"8", "20050301", "on"},
        {"9", "20050401", "off"}
    };

    index_create(store, fis);
    fis_deref(fis);

    iw = iw_open(store, whitespace_analyzer_new(false), NULL);
    for (i = 0; i < FILTER_DOCS_SIZE; i++) {
        Document *doc = doc_new();
        doc->boost = (float)(i+1);
        doc_add_field(doc, df_add_data(df_new(num), data[i].num));
        doc_add_field(doc, df_add_data(df_new(date), data[i].date));
        doc_add_field(doc, df_add_data(df_new(flipflop), data[i].flipflop));
        iw_add_doc(iw, doc);
        doc_destroy(doc);
    }
    iw_close(iw);
    return;
}
Example #4
0
static void sort_multi_test_setup(Store *store1, Store *store2)
{
    int i;
    FieldInfos *fis = fis_new(STORE_YES, INDEX_YES, TERM_VECTOR_YES);
    IndexWriter *iw;
    SortTestData data[] = {            /* len mod */
        {"findall","a","6","0.01"},    /*  4   0  */
        {"findall","c","5","0.1"},     /*  3   3  */
        {"findall","e","2","0.001"},   /*  5   1  */
        {"findall","g","1","1.0"},     /*  3   3  */
        {"findall","i","3","0.0001"},  /*  6   2  */
        {"findall","", "4","10.0"},    /*  4   0  */
        {"findall","h","5","0.00001"}, /*  7   3  */
        {"findall","f","2","100.0"},   /*  5   1  */
        {"findall","d","3","1000.0"},  /*  6   2  */
        {"findall","b","4","0.000001"} /*  8   0  */
    };

    index_create(store1, fis);
    index_create(store2, fis);
    fis_deref(fis);

    iw = iw_open(store1, whitespace_analyzer_new(false), NULL);

    for (i = 0; i < NELEMS(data)/2; i++) {
        add_sort_test_data(&data[i], iw);
    }
    iw_close(iw);

    iw = iw_open(store2, whitespace_analyzer_new(false), NULL);

    for (i = NELEMS(data)/2; i < NELEMS(data); i++) {
        add_sort_test_data(&data[i], iw);
    }
    iw_close(iw);
}
Example #5
0
static FieldInfos *create_fis()
{
    FieldInfos *fis = fis_new(STORE_YES, INDEX_YES,
                              TERM_VECTOR_WITH_POSITIONS_OFFSETS);
    return fis;
}
Example #6
0
File: writer.c Project: rwl/ferret
IndexWriter *
frjs_iw_init(bool create, bool create_if_missing, Store *store,
Analyzer *analyzer, FieldInfos *fis) {
	IndexWriter *iw = NULL;
	Config config = default_config;

//    rb_scan_args(argc, argv, "01", &roptions);
	/*if (argc > 0) {
	 Check_Type(roptions, T_HASH);

	 if ((rval = rb_hash_aref(roptions, sym_dir)) != Qnil) {
	 Check_Type(rval, T_DATA);
	 store = DATA_PTR(rval);
	 } else if ((rval = rb_hash_aref(roptions, sym_path)) != Qnil) {
	 StringValue(rval);
	 frb_create_dir(rval);
	 store = open_fs_store(rs2s(rval));
	 DEREF(store);
	 }

	 // Let ruby's garbage collector handle the closing of the store
	 // if (!close_dir) {
	 // close_dir = RTEST(rb_hash_aref(roptions, sym_close_dir));
	 // }

	 // use_compound_file defaults to true
	 config.use_compound_file =
	 (rb_hash_aref(roptions, sym_use_compound_file) == Qfalse)
	 ? false
	 : true;

	 if ((rval = rb_hash_aref(roptions, sym_analyzer)) != Qnil) {
	 analyzer = frb_get_cwrapped_analyzer(rval);
	 }

	 create = RTEST(rb_hash_aref(roptions, sym_create));
	 if ((rval = rb_hash_aref(roptions, sym_create_if_missing)) != Qnil) {
	 create_if_missing = RTEST(rval);
	 }
	 SET_INT_ATTR(chunk_size);
	 SET_INT_ATTR(max_buffer_memory);
	 SET_INT_ATTR(index_interval);
	 SET_INT_ATTR(skip_interval);
	 SET_INT_ATTR(merge_factor);
	 SET_INT_ATTR(max_buffered_docs);
	 SET_INT_ATTR(max_merge_docs);
	 SET_INT_ATTR(max_field_length);
	 }*/
	if (NULL == store) {
		store = open_ram_store();
		DEREF(store);
	}
	if (!create && create_if_missing && !store->exists(store, "segments")) {
		create = true;
	}
	if (create) {
		if (fis != NULL) {
			index_create(store, fis);
		} else {
			fis = fis_new(STORE_YES, INDEX_YES,
			TERM_VECTOR_WITH_POSITIONS_OFFSETS);
			index_create(store, fis);
			fis_deref(fis);
		}
	}

	iw = iw_open(store, analyzer, &config);
	return iw;
}