From: Steinar H. Gunderson Date: Sat, 3 Oct 2020 08:49:10 +0000 (+0200) Subject: Fix searching for very short (1 or 2 bytes) queries. X-Git-Tag: 1.0.0~63 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=d5f6c3c0a4419f48ac62beca86e28c9e6aea2412;p=plocate Fix searching for very short (1 or 2 bytes) queries. plocate had assumptions about the layout of the file, that no longer held. Use the pad field to simplify things. This requires a database rebuild, but only for short queries. Normal queries will continue to work, so there's no version bump. --- diff --git a/db.h b/db.h index cb0a7a8..ca8b3ea 100644 --- a/db.h +++ b/db.h @@ -8,7 +8,7 @@ struct Header { uint32_t version; // 0. uint32_t hashtable_size; uint32_t extra_ht_slots; - uint32_t pad; // Unused. + uint32_t num_docids; uint64_t hash_table_offset_bytes; uint64_t filename_index_offset_bytes; }; diff --git a/plocate-build.cpp b/plocate-build.cpp index 658aea2..c680449 100644 --- a/plocate-build.cpp +++ b/plocate-build.cpp @@ -377,6 +377,7 @@ void do_build(const char *infile, const char *outfile, int block_size) } corpus.flush_block(); dprintf("Read %zu files from %s\n", corpus.num_files, infile); + hdr.num_docids = corpus.filename_blocks.size(); // Stick an empty block at the end as sentinel. corpus.filename_blocks.push_back(ftell(outfp)); diff --git a/plocate.cpp b/plocate.cpp index fa70f76..fc8c4be 100644 --- a/plocate.cpp +++ b/plocate.cpp @@ -188,12 +188,7 @@ void Corpus::get_compressed_filename_block(uint32_t docid, function &needles, string_view compressed,