Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions include/iris/ngram/database.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ class database
store_.clear();
}

template<class DocumentID = document_id>
bool search(this auto const& db, search_query<CharT> const& query, search_result<DocumentID>& search_res)
template<class DocumentID, class HashT, class EqualT>
bool search(this auto const& db, search_query<CharT> const& query, search_result<DocumentID, HashT, EqualT>& search_res)
{
search_res.clear();
if (query.empty()) return false;
Expand Down
11 changes: 6 additions & 5 deletions include/iris/ngram/keyed_database.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
#include <iris/ngram/database.hpp>
#include <iris/ngram/id.hpp>

#include <iris/hash.hpp>

#include <format>
#include <unordered_map>
#include <stdexcept>
#include <memory>
Expand All @@ -25,7 +24,7 @@ class keyed_database : private database<CharT>
public:
using document_id_type = KeyT;

template<class KeyLikeT>
template<class KeyLikeT = KeyT>
requires std::is_constructible_v<KeyT, KeyLikeT>
void add_document(KeyLikeT&& key_like, std::basic_string_view<CharT> const doc_text)
{
Expand All @@ -34,8 +33,10 @@ class keyed_database : private database<CharT>
if (!inserted) {
if constexpr (std::is_pointer_v<KeyT>) {
throwf<std::invalid_argument>("key `{}` already exists in keyed_database", static_cast<void const*>(it->first));
} else {
} else if constexpr (std::formattable<KeyT, char>) {
throwf<std::invalid_argument>("key `{}` already exists in keyed_database", it->first);
} else {
throwf<std::invalid_argument>("key `???` already exists in keyed_database");
}
}
assert(doc_id_to_key_.size() == detail::to_index(doc_id));
Expand All @@ -48,7 +49,7 @@ class keyed_database : private database<CharT>
base_type::update_document(this->get_document_id(key_like), doc_text);
}

template<class KeyLikeT>
template<class KeyLikeT = KeyT>
requires std::is_constructible_v<KeyT, KeyLikeT>
void add_or_update_document(KeyLikeT&& key_like, std::basic_string_view<CharT> const doc_text)
{
Expand Down
6 changes: 4 additions & 2 deletions include/iris/ngram/search_result.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,13 @@ struct [[nodiscard]] search_word_match
std::vector<interval<int>> spans_;
};

template<class DocumentID = document_id>
template<class DocumentID = document_id, class HashT = std::hash<DocumentID>, class EqualT = std::equal_to<>>
struct [[nodiscard]] search_result
{
using document_id_type = DocumentID;
using map_type = std::unordered_map<DocumentID, std::vector<search_word_match>>;
using hash_type = HashT;
using equal_type = EqualT;
using map_type = std::unordered_map<DocumentID, std::vector<search_word_match>, HashT, EqualT>;

search_result() = default;

Expand Down
Loading