mirror of
https://github.com/typesense/typesense.git
synced 2025-05-24 07:40:35 +08:00
Add filter_result_iterator_t::contains_atleast_one
.
This commit is contained in:
parent
9ef9be516b
commit
ad41f2d5a8
@ -755,3 +755,45 @@ Option<bool> filter::parse_filter_query(const std::string& filter_query,
|
||||
|
||||
return Option<bool>(true);
|
||||
}
|
||||
|
||||
bool filter_result_iterator_t::contains_atleast_one(const void *obj) {
|
||||
if(IS_COMPACT_POSTING(obj)) {
|
||||
compact_posting_list_t* list = COMPACT_POSTING_PTR(obj);
|
||||
|
||||
size_t i = 0;
|
||||
while(i < list->length && valid()) {
|
||||
size_t num_existing_offsets = list->id_offsets[i];
|
||||
size_t existing_id = list->id_offsets[i + num_existing_offsets + 1];
|
||||
|
||||
if (existing_id == seq_id) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// advance smallest value
|
||||
if (existing_id < seq_id) {
|
||||
i += num_existing_offsets + 2;
|
||||
} else {
|
||||
skip_to(existing_id);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
auto list = (posting_list_t*)(obj);
|
||||
posting_list_t::iterator_t it = list->new_iterator();
|
||||
|
||||
while(it.valid() && valid()) {
|
||||
uint32_t id = it.id();
|
||||
|
||||
if(id == seq_id) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if(id < seq_id) {
|
||||
it.skip_to(seq_id);
|
||||
} else {
|
||||
skip_to(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user