mirror of
https://github.com/typesense/typesense.git
synced 2025-05-20 21:52:23 +08:00
Removed redundant storage of length in offsets array.
This commit is contained in:
parent
c079b22cbd
commit
2a77a1ad66
2
TODO.md
2
TODO.md
@ -29,4 +29,4 @@
|
||||
**Refactoring**
|
||||
|
||||
- `token_count` in leaf is redundant: can be accessed from value
|
||||
- storing length in `offsets` is redundant: length can be found by looking up value of the next index in `offset_index`
|
||||
- ~~storing length in `offsets` is redundant: it can be found by looking up value of the next index in `offset_index`~~
|
||||
|
@ -366,7 +366,6 @@ static void add_document_to_leaf(const art_document *document, art_leaf *leaf) {
|
||||
uint32_t curr_index = leaf->values->offsets.getLength();
|
||||
leaf->values->offset_index.append_sorted(curr_index);
|
||||
|
||||
leaf->values->offsets.append_unsorted(document->offsets_len);
|
||||
for(uint32_t i=0; i<document->offsets_len; i++) {
|
||||
leaf->values->offsets.append_unsorted(document->offsets[i]);
|
||||
}
|
||||
|
@ -83,6 +83,10 @@ void Collection::search(std::string query, size_t max_results) {
|
||||
}
|
||||
}
|
||||
|
||||
if(token_leaves.size() == 0) {
|
||||
return ;
|
||||
}
|
||||
|
||||
//std::cout << "token_leaves.size = " << token_leaves.size() << std::endl;
|
||||
|
||||
Topster<100> topster;
|
||||
@ -138,11 +142,16 @@ void Collection::score_results(Topster<100> &topster, const std::vector<art_leaf
|
||||
for (art_leaf *token_leaf : query_suggestion) {
|
||||
std::__1::vector<uint16_t> positions;
|
||||
uint32_t doc_index = token_leaf->values->ids.indexOf(doc_id);
|
||||
uint32_t offset_index = token_leaf->values->offset_index.at(doc_index);
|
||||
uint32_t num_offsets = token_leaf->values->offsets.at(offset_index);
|
||||
for (auto offset_count = 1; offset_count <= num_offsets; offset_count++) {
|
||||
positions.push_back((uint16_t) token_leaf->values->offsets.at(offset_index + offset_count));
|
||||
uint32_t start_offset = token_leaf->values->offset_index.at(doc_index);
|
||||
uint32_t end_offset = (doc_index == token_leaf->values->ids.getLength() - 1) ?
|
||||
(token_leaf->values->offsets.getLength() - 1) :
|
||||
token_leaf->values->offset_index.at(doc_index+1);
|
||||
|
||||
while(start_offset <= end_offset) {
|
||||
positions.push_back((uint16_t) token_leaf->values->offsets.at(start_offset));
|
||||
start_offset++;
|
||||
}
|
||||
|
||||
token_positions.push_back(positions);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user