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; }
Matcher* PhraseCompiler_make_matcher(PhraseCompiler *self, SegReader *reader, bool_t need_score) { UNUSED_VAR(need_score); PhraseQuery *const parent = (PhraseQuery*)self->parent; VArray *const terms = parent->terms; uint32_t num_terms = VA_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, VTable_Get_Name(POSTINGLISTREADER)); if (!plist_reader) { return NULL; } // Look up each term. VArray *plists = VA_new(num_terms); for (uint32_t i = 0; i < num_terms; i++) { Obj *term = VA_Fetch(terms, i); PostingList *plist = PListReader_Posting_List(plist_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); } Matcher *retval = (Matcher*)PhraseScorer_new(sim, plists, (Compiler*)self); DECREF(plists); return retval; }