summaryrefslogtreecommitdiffstats
path: root/searchsummary
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@online.no>2022-09-08 14:58:22 +0200
committerTor Egge <Tor.Egge@online.no>2022-09-08 14:58:22 +0200
commit158f73e70dd7bd7a1f8a134f3ad2f765e5d41bc0 (patch)
treecb01487767ea96943390a424d6088a184f78acb5 /searchsummary
parent69adaa32ce4e1d9c0698c8868ca3dc06acd4486e (diff)
Ignore summary field type in MatchedElementsFilterDFW and move
filtering of matched elements to SummaryFieldConverter.
Diffstat (limited to 'searchsummary')
-rw-r--r--searchsummary/src/vespa/searchsummary/docsummary/matched_elements_filter_dfw.cpp29
-rw-r--r--searchsummary/src/vespa/searchsummary/docsummary/matched_elements_filter_dfw.h2
-rw-r--r--searchsummary/src/vespa/searchsummary/docsummary/summaryfieldconverter.cpp20
-rw-r--r--searchsummary/src/vespa/searchsummary/docsummary/summaryfieldconverter.h9
4 files changed, 18 insertions, 42 deletions
diff --git a/searchsummary/src/vespa/searchsummary/docsummary/matched_elements_filter_dfw.cpp b/searchsummary/src/vespa/searchsummary/docsummary/matched_elements_filter_dfw.cpp
index 6f53c0b1c84..fe06212bcd2 100644
--- a/searchsummary/src/vespa/searchsummary/docsummary/matched_elements_filter_dfw.cpp
+++ b/searchsummary/src/vespa/searchsummary/docsummary/matched_elements_filter_dfw.cpp
@@ -62,38 +62,13 @@ MatchedElementsFilterDFW::create(const std::string& input_field_name,
MatchedElementsFilterDFW::~MatchedElementsFilterDFW() = default;
-namespace {
-
-void
-filter_matching_elements_in_input_field_while_converting_to_slime(const FieldValue& input_field_value,
- const std::vector<uint32_t>& matching_elems,
- vespalib::slime::Inserter& target)
-{
- // This is a similar conversion that happens in proton::DocumentStoreAdapter.
- // Only difference is that we filter matched elements on the fly.
- auto converted = SummaryFieldConverter::convert_field_with_filter(false, input_field_value, matching_elems);
- // This should hold as we also have asserted that (type == ResType::RES_JSONSTRING);
- assert(converted->isLiteral());
- auto& literal = static_cast<const LiteralFieldValueB&>(*converted);
- vespalib::stringref buf = literal.getValueRef();
- if (buf.empty()) {
- return;
- }
- Slime input_field_as_slime;
- BinaryFormat::decode(vespalib::Memory(buf.data(), buf.size()), input_field_as_slime);
- inject(input_field_as_slime.get(), target);
-}
-
-}
-
void
MatchedElementsFilterDFW::insertField(uint32_t docid, const IDocsumStoreDocument* doc, GetDocsumsState *state,
- ResType type, vespalib::slime::Inserter& target) const
+ ResType, vespalib::slime::Inserter& target) const
{
- assert(type == ResType::RES_JSONSTRING);
auto field_value = doc->get_field_value(_input_field_name);
if (field_value) {
- filter_matching_elements_in_input_field_while_converting_to_slime(*field_value, get_matching_elements(docid, *state), target);
+ SummaryFieldConverter::insert_summary_field_with_filter(*field_value, target, get_matching_elements(docid, *state));
}
}
diff --git a/searchsummary/src/vespa/searchsummary/docsummary/matched_elements_filter_dfw.h b/searchsummary/src/vespa/searchsummary/docsummary/matched_elements_filter_dfw.h
index 09f989d5121..18d608440d3 100644
--- a/searchsummary/src/vespa/searchsummary/docsummary/matched_elements_filter_dfw.h
+++ b/searchsummary/src/vespa/searchsummary/docsummary/matched_elements_filter_dfw.h
@@ -35,7 +35,7 @@ public:
~MatchedElementsFilterDFW() override;
bool IsGenerated() const override { return false; }
void insertField(uint32_t docid, const IDocsumStoreDocument* doc, GetDocsumsState *state,
- ResType type, vespalib::slime::Inserter& target) const override;
+ ResType, vespalib::slime::Inserter& target) const override;
};
}
diff --git a/searchsummary/src/vespa/searchsummary/docsummary/summaryfieldconverter.cpp b/searchsummary/src/vespa/searchsummary/docsummary/summaryfieldconverter.cpp
index 5bfe41ed1b0..d09f23251e7 100644
--- a/searchsummary/src/vespa/searchsummary/docsummary/summaryfieldconverter.cpp
+++ b/searchsummary/src/vespa/searchsummary/docsummary/summaryfieldconverter.cpp
@@ -554,7 +554,7 @@ public:
SlimeFiller(Inserter &inserter, bool tokenize)
: _inserter(inserter),
_tokenize(tokenize),
- _matching_elems()
+ _matching_elems(nullptr)
{}
SlimeFiller(Inserter& inserter, bool tokenize, const std::vector<uint32_t>* matching_elems)
@@ -603,22 +603,24 @@ SummaryFieldConverter::convertSummaryField(bool markup,
return SummaryFieldValueConverter(markup, subConv).convert(value);
}
-FieldValue::UP
-SummaryFieldConverter::convert_field_with_filter(bool markup,
- const document::FieldValue& value,
- const std::vector<uint32_t>& matching_elems)
+void
+SummaryFieldConverter::insert_summary_field(const FieldValue& value, vespalib::slime::Inserter& inserter)
{
- SlimeConverter sub_conv(markup, matching_elems);
- return SummaryFieldValueConverter(markup, sub_conv).convert(value);
+ CheckUndefinedValueVisitor check_undefined;
+ value.accept(check_undefined);
+ if (!check_undefined.is_undefined()) {
+ SlimeFiller visitor(inserter, false);
+ value.accept(visitor);
+ }
}
void
-SummaryFieldConverter::insert_summary_field(const FieldValue& value, vespalib::slime::Inserter& inserter)
+SummaryFieldConverter::insert_summary_field_with_filter(const FieldValue& value, vespalib::slime::Inserter& inserter, const std::vector<uint32_t>& matching_elems)
{
CheckUndefinedValueVisitor check_undefined;
value.accept(check_undefined);
if (!check_undefined.is_undefined()) {
- SlimeFiller visitor(inserter, false);
+ SlimeFiller visitor(inserter, false, &matching_elems);
value.accept(visitor);
}
}
diff --git a/searchsummary/src/vespa/searchsummary/docsummary/summaryfieldconverter.h b/searchsummary/src/vespa/searchsummary/docsummary/summaryfieldconverter.h
index 23d20b23c1f..2408e3c5b68 100644
--- a/searchsummary/src/vespa/searchsummary/docsummary/summaryfieldconverter.h
+++ b/searchsummary/src/vespa/searchsummary/docsummary/summaryfieldconverter.h
@@ -16,16 +16,15 @@ class SummaryFieldConverter
public:
static document::FieldValue::UP convertSummaryField(bool markup, const document::FieldValue &value);
- /**
- * Converts the given field value to slime, only keeping the elements that are contained in the matching elements vector.
- *
- * Filtering occurs when the field value is an ArrayFieldValue or MapFieldValue.
- */
static document::FieldValue::UP convert_field_with_filter(bool markup,
const document::FieldValue& value,
const std::vector<uint32_t>& matching_elems);
static void insert_summary_field(const document::FieldValue& value, vespalib::slime::Inserter& inserter);
+ /**
+ * Insert the given field value, but only the elements that are contained in the matching_elems vector.
+ */
+ static void insert_summary_field_with_filter(const document::FieldValue& value, vespalib::slime::Inserter& inserter, const std::vector<uint32_t>& matching_elems);
};
}