mirror of
https://github.com/typesense/typesense.git
synced 2025-05-24 15:50:42 +08:00
Add filter_result_iterator_t::contains_atleast_one
.
This commit is contained in:
parent
4d0c7b5112
commit
a7719d7b30
@ -2,6 +2,7 @@
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include "posting_list.h"
|
||||
#include "index.h"
|
||||
|
||||
class filter_result_iterator_t {
|
||||
@ -92,4 +93,6 @@ public:
|
||||
/// Advances the iterator until the doc value reaches or just overshoots id. The iterator may become invalid during
|
||||
/// this operation.
|
||||
void skip_to(uint32_t id);
|
||||
|
||||
bool contains_atleast_one(const void* obj);
|
||||
};
|
||||
|
@ -502,3 +502,45 @@ Option<bool> filter_result_iterator_t::init_status() {
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
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