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); }
TopDocs* PolySearcher_Top_Docs_IMP(PolySearcher *self, Query *query, uint32_t num_wanted, SortSpec *sort_spec) { PolySearcherIVARS *const ivars = PolySearcher_IVARS(self); Schema *schema = PolySearcher_Get_Schema(self); VArray *searchers = ivars->searchers; I32Array *starts = ivars->starts; HitQueue *hit_q = sort_spec ? HitQ_new(schema, sort_spec, num_wanted) : HitQ_new(NULL, NULL, num_wanted); uint32_t total_hits = 0; Compiler *compiler = Query_Is_A(query, COMPILER) ? ((Compiler*)INCREF(query)) : Query_Make_Compiler(query, (Searcher*)self, Query_Get_Boost(query), false); for (uint32_t i = 0, max = VA_Get_Size(searchers); i < max; i++) { Searcher *searcher = (Searcher*)VA_Fetch(searchers, i); int32_t base = I32Arr_Get(starts, i); TopDocs *top_docs = Searcher_Top_Docs(searcher, (Query*)compiler, num_wanted, sort_spec); VArray *sub_match_docs = TopDocs_Get_Match_Docs(top_docs); total_hits += TopDocs_Get_Total_Hits(top_docs); S_modify_doc_ids(sub_match_docs, base); for (uint32_t j = 0, jmax = VA_Get_Size(sub_match_docs); j < jmax; j++) { MatchDoc *match_doc = (MatchDoc*)VA_Fetch(sub_match_docs, j); if (!HitQ_Insert(hit_q, INCREF(match_doc))) { break; } } DECREF(top_docs); } VArray *match_docs = HitQ_Pop_All(hit_q); TopDocs *retval = TopDocs_new(match_docs, total_hits); DECREF(match_docs); DECREF(compiler); DECREF(hit_q); return retval; }
PolyCompiler* PolyCompiler_init(PolyCompiler *self, PolyQuery *parent, Searcher *searcher, float boost) { PolyCompilerIVARS *const ivars = PolyCompiler_IVARS(self); PolyQueryIVARS *const parent_ivars = PolyQuery_IVARS(parent); const size_t num_kids = Vec_Get_Size(parent_ivars->children); Compiler_init((Compiler*)self, (Query*)parent, searcher, NULL, boost); ivars->children = Vec_new(num_kids); // Iterate over the children, creating a Compiler for each one. for (size_t i = 0; i < num_kids; i++) { Query *child_query = (Query*)Vec_Fetch(parent_ivars->children, i); float sub_boost = boost * Query_Get_Boost(child_query); Compiler *child_compiler = Query_Make_Compiler(child_query, searcher, sub_boost, true); Vec_Push(ivars->children, (Obj*)child_compiler); } return self; }
Highlighter* Highlighter_init(Highlighter *self, Searcher *searcher, Obj *query, String *field, uint32_t excerpt_length) { HighlighterIVARS *const ivars = Highlighter_IVARS(self); ivars->query = Searcher_Glean_Query(searcher, query); ivars->searcher = (Searcher*)INCREF(searcher); ivars->field = Str_Clone(field); ivars->excerpt_length = excerpt_length; ivars->slop = excerpt_length / 3; ivars->pre_tag = Str_new_from_trusted_utf8("<strong>", 8); ivars->post_tag = Str_new_from_trusted_utf8("</strong>", 9); if (Query_Is_A(ivars->query, COMPILER)) { ivars->compiler = (Compiler*)INCREF(ivars->query); } else { ivars->compiler = Query_Make_Compiler(ivars->query, searcher, Query_Get_Boost(ivars->query), false); } return self; }