예제 #1
0
파일: TermQuery.c 프로젝트: apache/lucy
Matcher*
TermCompiler_Make_Matcher_IMP(TermCompiler *self, SegReader *reader,
                              bool need_score) {
    TermCompilerIVARS *const ivars = TermCompiler_IVARS(self);
    TermQueryIVARS *const parent_ivars
        = TermQuery_IVARS((TermQuery*)ivars->parent);
    PostingListReader *plist_reader
        = (PostingListReader*)SegReader_Fetch(
              reader, Class_Get_Name(POSTINGLISTREADER));
    PostingList *plist = plist_reader
                         ? PListReader_Posting_List(plist_reader,
                                                    parent_ivars->field,
                                                    parent_ivars->term)
                         : NULL;

    if (plist == NULL || PList_Get_Doc_Freq(plist) == 0) {
        DECREF(plist);
        return NULL;
    }
    else {
        Matcher *retval = PList_Make_Matcher(plist, ivars->sim,
                                             (Compiler*)self, need_score);
        DECREF(plist);
        return retval;
    }
}
예제 #2
0
Matcher*
PhraseCompiler_make_matcher(PhraseCompiler *self, SegReader *reader,
                            bool_t need_score)
{
    PostingsReader *const post_reader = (PostingsReader*)SegReader_Fetch(
        reader, POSTINGSREADER.name);
    PhraseQuery *const parent = (PhraseQuery*)self->parent;
    VArray  *const terms      = parent->terms;
    u32_t    num_terms        = VA_Get_Size(terms);
    Schema  *schema           = SegReader_Get_Schema(reader);
    Posting *posting          = Schema_Fetch_Posting(schema, parent->field);
    VArray  *plists;
    Matcher *retval;
    u32_t i;
    UNUSED_VAR(need_score);

    /* Bail if there are no terms. */
    if (!num_terms) return NULL;

    /* Bail unless field is valid and posting type supports positions. */
    if (posting == NULL || !OBJ_IS_A(posting, SCOREPOSTING)) return NULL;

    /* Bail if there's no PostingsReader for this segment. */
    if (!post_reader) { return NULL; }

    /* Look up each term. */
    plists = VA_new(num_terms);
    for (i = 0; i < num_terms; i++) {
        Obj *term = VA_Fetch(terms, i);
        PostingList *plist 
            = PostReader_Posting_List(post_reader, parent->field, term);

        /* Bail if any one of the terms isn't in the index. */
        if (!plist || !PList_Get_Doc_Freq(plist)) {
            DECREF(plist);
            DECREF(plists);
            return NULL;
        }
        VA_Push(plists, (Obj*)plist);
    }

    retval = (Matcher*)PhraseScorer_new(
        Compiler_Get_Similarity(self),
        plists, 
        (Compiler*)self
    );
    DECREF(plists);

    return retval;
}
예제 #3
0
Matcher*
PhraseCompiler_Make_Matcher_IMP(PhraseCompiler *self, SegReader *reader,
                                bool need_score) {
    UNUSED_VAR(need_score);
    PhraseCompilerIVARS *const ivars = PhraseCompiler_IVARS(self);
    PhraseQueryIVARS *const parent_ivars
        = PhraseQuery_IVARS((PhraseQuery*)ivars->parent);
    Vector *const      terms     = parent_ivars->terms;
    uint32_t           num_terms = Vec_Get_Size(terms);

    // Bail if there are no terms.
    if (!num_terms) { return NULL; }

    // Bail unless field is valid and posting type supports positions.
    Similarity *sim     = PhraseCompiler_Get_Similarity(self);
    Posting    *posting = Sim_Make_Posting(sim);
    if (posting == NULL || !Obj_is_a((Obj*)posting, SCOREPOSTING)) {
        DECREF(posting);
        return NULL;
    }
    DECREF(posting);

    // Bail if there's no PostingListReader for this segment.
    PostingListReader *const plist_reader
        = (PostingListReader*)SegReader_Fetch(
              reader, Class_Get_Name(POSTINGLISTREADER));
    if (!plist_reader) { return NULL; }

    // Look up each term.
    Vector  *plists = Vec_new(num_terms);
    for (uint32_t i = 0; i < num_terms; i++) {
        Obj *term = Vec_Fetch(terms, i);
        PostingList *plist
            = PListReader_Posting_List(plist_reader, parent_ivars->field, term);

        // Bail if any one of the terms isn't in the index.
        if (!plist || !PList_Get_Doc_Freq(plist)) {
            DECREF(plist);
            DECREF(plists);
            return NULL;
        }
        Vec_Push(plists, (Obj*)plist);
    }

    Matcher *retval
        = (Matcher*)PhraseMatcher_new(sim, plists, (Compiler*)self);
    DECREF(plists);
    return retval;
}