From 4db8dcbf3395fd92b1348155142b85df5a754289 Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Sun, 15 May 2022 00:41:35 +0200 Subject: Revert "Revert "Collapse vsm into streamingvisitors"" --- .../src/vespa/vsm/searcher/strchrfieldsearcher.cpp | 56 ++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 streamingvisitors/src/vespa/vsm/searcher/strchrfieldsearcher.cpp (limited to 'streamingvisitors/src/vespa/vsm/searcher/strchrfieldsearcher.cpp') diff --git a/streamingvisitors/src/vespa/vsm/searcher/strchrfieldsearcher.cpp b/streamingvisitors/src/vespa/vsm/searcher/strchrfieldsearcher.cpp new file mode 100644 index 00000000000..1c4ff78ff4a --- /dev/null +++ b/streamingvisitors/src/vespa/vsm/searcher/strchrfieldsearcher.cpp @@ -0,0 +1,56 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#include "strchrfieldsearcher.h" +#include + +using search::streaming::QueryTerm; +using search::streaming::QueryTermList; + +namespace vsm { + +void StrChrFieldSearcher::prepare(QueryTermList & qtl, const SharedSearcherBuf & buf) +{ + FieldSearcher::prepare(qtl, buf); +} + +void StrChrFieldSearcher::onValue(const document::FieldValue & fv) +{ + const document::LiteralFieldValueB & sfv = static_cast(fv); + vespalib::stringref val = sfv.getValueRef(); + FieldRef fr(val.data(), std::min(maxFieldLength(), val.size())); + matchDoc(fr); +} + +bool StrChrFieldSearcher::matchDoc(const FieldRef & fieldRef) +{ + bool retval(true); + if (_qtl.size() > 1) { + size_t mintsz = shortestTerm(); + if (fieldRef.size() >= mintsz) { + _words += matchTerms(fieldRef, mintsz); + } else { + _words += countWords(fieldRef); + } + } else { + for(QueryTermList::iterator it=_qtl.begin(), mt=_qtl.end(); it != mt; it++) { + QueryTerm & qt = **it; + if (fieldRef.size() >= qt.termLen()) { + _words += matchTerm(fieldRef, qt); + } else { + _words += countWords(fieldRef); + } + } + } + return retval; +} + +size_t StrChrFieldSearcher::shortestTerm() const +{ + size_t mintsz(_qtl.front()->termLen()); + for(QueryTermList::const_iterator it=_qtl.begin()+1, mt=_qtl.end(); it != mt; it++) { + const QueryTerm & qt = **it; + mintsz = std::min(mintsz, qt.termLen()); + } + return mintsz; +} + +} -- cgit v1.2.3