Ejemplo n.º 1
0
Matcher*
NOTCompiler_make_matcher(NOTCompiler *self, SegReader *reader,
                         bool need_score) {
    NOTCompilerIVARS *const ivars = NOTCompiler_IVARS(self);
    Compiler *negated_compiler
        = (Compiler*)CERTIFY(VA_Fetch(ivars->children, 0), COMPILER);
    Matcher *negated_matcher
        = Compiler_Make_Matcher(negated_compiler, reader, false);
    UNUSED_VAR(need_score);

    if (negated_matcher == NULL) {
        float weight = NOTCompiler_Get_Weight(self);
        int32_t doc_max = SegReader_Doc_Max(reader);
        return (Matcher*)MatchAllMatcher_new(weight, doc_max);
    }
    else if (Obj_Is_A((Obj*)negated_matcher, MATCHALLMATCHER)) {
        DECREF(negated_matcher);
        return NULL;
    }
    else {
        int32_t doc_max = SegReader_Doc_Max(reader);
        Matcher *retval = (Matcher*)NOTMatcher_new(negated_matcher, doc_max);
        DECREF(negated_matcher);
        return retval;
    }
}
Ejemplo n.º 2
0
void
DefDelWriter_Delete_By_Query_IMP(DefaultDeletionsWriter *self, Query *query) {
    DefaultDeletionsWriterIVARS *const ivars = DefDelWriter_IVARS(self);
    Compiler *compiler = Query_Make_Compiler(query, (Searcher*)ivars->searcher,
                                             Query_Get_Boost(query), false);

    for (uint32_t i = 0, max = VA_Get_Size(ivars->seg_readers); i < max; i++) {
        SegReader *seg_reader = (SegReader*)VA_Fetch(ivars->seg_readers, i);
        BitVector *bit_vec = (BitVector*)VA_Fetch(ivars->bit_vecs, i);
        Matcher *matcher = Compiler_Make_Matcher(compiler, seg_reader, false);

        if (matcher) {
            int32_t doc_id;
            int32_t num_zapped = 0;

            // Iterate through matches, marking each doc as deleted.
            while (0 != (doc_id = Matcher_Next(matcher))) {
                num_zapped += !BitVec_Get(bit_vec, doc_id);
                BitVec_Set(bit_vec, doc_id);
            }
            if (num_zapped) { ivars->updated[i] = true; }

            DECREF(matcher);
        }
    }

    DECREF(compiler);
}
Ejemplo n.º 3
0
Archivo: ORQuery.c Proyecto: kidaa/lucy
Matcher*
ORCompiler_Make_Matcher_IMP(ORCompiler *self, SegReader *reader,
                            bool need_score) {
    ORCompilerIVARS *const ivars = ORCompiler_IVARS(self);
    uint32_t num_kids = Vec_Get_Size(ivars->children);

    if (num_kids == 1) {
        // No need for an ORMatcher wrapper.
        Compiler *only_child = (Compiler*)Vec_Fetch(ivars->children, 0);
        return Compiler_Make_Matcher(only_child, reader, need_score);
    }
    else {
        Vector *submatchers = Vec_new(num_kids);
        uint32_t num_submatchers = 0;

        // Accumulate sub-matchers.
        for (uint32_t i = 0; i < num_kids; i++) {
            Compiler *child = (Compiler*)Vec_Fetch(ivars->children, i);
            Matcher *submatcher
                = Compiler_Make_Matcher(child, reader, need_score);
            Vec_Push(submatchers, (Obj*)submatcher);
            if (submatcher != NULL) {
                num_submatchers++;
            }
        }

        if (num_submatchers == 0) {
            // No possible matches, so return null.
            DECREF(submatchers);
            return NULL;
        }
        else {
            Similarity *sim    = ORCompiler_Get_Similarity(self);
            Matcher    *retval = need_score
                                 ? (Matcher*)ORScorer_new(submatchers, sim)
                                 : (Matcher*)ORMatcher_new(submatchers);
            DECREF(submatchers);
            return retval;
        }
    }
}
Ejemplo n.º 4
0
Matcher*
NOTCompiler_make_matcher(NOTCompiler *self, SegReader *reader, 
                         bool_t need_score)
{
    Matcher *negated_matcher 
        = Compiler_Make_Matcher(VA_Fetch(self->children, 0), reader, false);
    UNUSED_VAR(need_score);

    if (negated_matcher == NULL) {
        float weight = Compiler_Get_Weight(self);
        return (Matcher*)MatchAllScorer_new(weight, SegReader_Doc_Max(reader));
    }
    else if (OBJ_IS_A(negated_matcher, MATCHALLSCORER)) {
        DECREF(negated_matcher);
        return NULL;
    }
    else {
        Matcher *retval 
            = (Matcher*)NOTScorer_new(negated_matcher, SegReader_Doc_Max(reader));
        DECREF(negated_matcher);
        return retval;
    }
}