1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "imported_attribute_fixture.h"
#include "mock_gid_to_lid_mapping.h"
#include <vespa/searchlib/query/query_term_ucs4.h>
#include <vespa/vespalib/util/stringfmt.h>
#include <future>
namespace search {
namespace {
struct MockReadGuard : public IDocumentMetaStoreContext::IReadGuard {
virtual const search::IDocumentMetaStore &get() const override { abort(); }
};
}
IDocumentMetaStoreContext::IReadGuard::SP
MockDocumentMetaStoreContext::getReadGuard() const {
++get_read_guard_cnt;
return std::make_shared<MockReadGuard>();
}
}
namespace search::attribute {
using document::DocumentId;
using document::GlobalId;
using DocId = IAttributeVector::DocId;
using WeightedInt = IAttributeVector::WeightedInt;
using WeightedFloat = IAttributeVector::WeightedFloat;
using WeightedString = IAttributeVector::WeightedString;
using WeightedConstChar = IAttributeVector::WeightedConstChar;
using WeightedEnum = IAttributeVector::WeightedEnum;
using test::MockGidToLidMapperFactory;
std::shared_ptr<ReferenceAttribute> create_reference_attribute(vespalib::stringref name = "ref") {
return std::make_shared<ReferenceAttribute>(name, Config(BasicType::REFERENCE));
}
std::shared_ptr<MockDocumentMetaStoreContext>
create_target_document_meta_store() {
return std::make_shared<MockDocumentMetaStoreContext>();
}
std::shared_ptr<MockDocumentMetaStoreContext>
create_document_meta_store() {
return std::make_shared<MockDocumentMetaStoreContext>();
}
GlobalId dummy_gid(uint32_t doc_index) {
return DocumentId(vespalib::make_string("id:foo:bar::%u", doc_index)).getGlobalId();
}
std::unique_ptr<QueryTermSimple> word_term(vespalib::stringref term) {
return std::make_unique<QueryTermUCS4>(term, QueryTermSimple::Type::WORD);
}
void
ImportedAttributeFixture::map_reference(DocId from_lid, GlobalId via_gid, DocId to_lid) {
assert(from_lid < reference_attr->getNumDocs());
mapper_factory->_map[via_gid] = to_lid;
if (to_lid != 0) {
reference_attr->notifyReferencedPut(via_gid, to_lid);
} else {
reference_attr->notifyReferencedRemove(via_gid);
}
reference_attr->update(from_lid, via_gid);
reference_attr->commit();
}
std::shared_ptr<ImportedAttributeVector>
ImportedAttributeFixture::create_attribute_vector_from_members(vespalib::stringref name) {
return ImportedAttributeVectorFactory::create(name, reference_attr, document_meta_store, target_attr, target_document_meta_store, use_search_cache);
}
void
ImportedAttributeFixture::reset_with_new_target_attr(std::shared_ptr<AttributeVector> new_target) {
target_attr = std::move(new_target);
imported_attr = create_attribute_vector_from_members();
}
void
ImportedAttributeFixture::set_up_attribute_vectors_before_adding_mappings() {
// Make a sneaky assumption that no tests try to use a lid > 9
add_n_docs_with_undefined_values(*reference_attr, 10);
target_attr->addReservedDoc();
add_n_docs_with_undefined_values(*target_attr, 10);
}
ImportedAttributeFixture::ImportedAttributeFixture(bool use_search_cache_, FastSearchConfig fastSearch)
: use_search_cache(use_search_cache_),
target_attr(create_single_attribute<IntegerAttribute>(BasicType::INT32, fastSearch)),
target_document_meta_store(create_target_document_meta_store()),
reference_attr(create_reference_attribute()),
document_meta_store(create_document_meta_store()),
imported_attr(create_attribute_vector_from_members()),
mapper_factory(std::make_shared<MockGidToLidMapperFactory>())
{
reference_attr->setGidToLidMapperFactory(mapper_factory);
}
ImportedAttributeFixture::~ImportedAttributeFixture() = default;
bool has_active_enum_guards(AttributeVector &attr) {
return std::async(std::launch::async, [&attr] { return attr.hasActiveEnumGuards(); }).get();
}
}
|