Skip to content

Commit

Permalink
Use const IDocsumEnvironment reference in DocsumFieldWriterFactory.
Browse files Browse the repository at this point in the history
  • Loading branch information
toregge committed Aug 30, 2022
1 parent 5e63e03 commit 067aba3
Show file tree
Hide file tree
Showing 30 changed files with 45 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class SummaryManager : public ISummaryManager

const search::IAttributeManager * getAttributeManager() const override { return _attributeMgr.get(); }
vespalib::string lookupIndex(const vespalib::string & s) const override { (void) s; return ""; }
juniper::Juniper * getJuniper() override { return _juniperConfig.get(); }
const juniper::Juniper * getJuniper() const override { return _juniperConfig.get(); }
};

private:
Expand Down
2 changes: 1 addition & 1 deletion searchsummary/src/tests/docsummary/positionsdfw_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ struct MyEnvironment : IDocsumEnvironment {

const IAttributeManager *getAttributeManager() const override { return attribute_man; }
string lookupIndex(const string &s) const override { return s; }
juniper::Juniper *getJuniper() override { return 0; }
const juniper::Juniper *getJuniper() const override { return nullptr; }
};

class MyAttributeContext : public IAttributeContext {
Expand Down
4 changes: 2 additions & 2 deletions searchsummary/src/tests/juniper/testenv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ PropertyMap::set(const char *name, const char *value)


const char *
PropertyMap::GetProperty(const char* name, const char* def)
PropertyMap::GetProperty(const char* name, const char* def) const
{
std::map<std::string, std::string>::iterator res = _map.find(std::string(name));
std::map<std::string, std::string>::const_iterator res = _map.find(std::string(name));
if (res != _map.end()) {
return res->second.c_str();
}
Expand Down
2 changes: 1 addition & 1 deletion searchsummary/src/tests/juniper/testenv.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class PropertyMap : public IJuniperProperties
PropertyMap();
~PropertyMap();
PropertyMap &set(const char *name, const char *value);
const char* GetProperty(const char* name, const char* def = NULL) override;
const char* GetProperty(const char* name, const char* def = nullptr) const override;
};


Expand Down
4 changes: 2 additions & 2 deletions searchsummary/src/vespa/juniper/IJuniperProperties.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class IJuniperProperties
* @param def A default value for the property if not found in configuration
* @return The value of the property or @param def if no such property is set
*/
virtual const char* GetProperty(const char* name, const char* def = nullptr) = 0;
virtual const char* GetProperty(const char* name, const char* def = nullptr) const = 0;

virtual ~IJuniperProperties() {};
virtual ~IJuniperProperties() = default;
};
2 changes: 1 addition & 1 deletion searchsummary/src/vespa/juniper/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace juniper
{

Config::Config(const char* config_name, Juniper & juniper) :
Config::Config(const char* config_name, const Juniper & juniper) :
_docsumparams(),
_matcherparams(),
_sumconf(nullptr),
Expand Down
4 changes: 2 additions & 2 deletions searchsummary/src/vespa/juniper/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Juniper;
class Config
{
public:
Config(const char* config_name, Juniper & juniper);
Config(const char* config_name, const Juniper & juniper);
~Config();
const char* GetProp(const char* name, const char* def);

Expand All @@ -26,7 +26,7 @@ class Config

private:
std::string _config_name;
Juniper & _juniper;
const Juniper& _juniper;

Config(Config &);
Config &operator=(Config &);
Expand Down
2 changes: 1 addition & 1 deletion searchsummary/src/vespa/juniper/juniperparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ size_t MatcherParams::StemMinLength() const { return _stem_min; }
size_t MatcherParams::StemMaxExtend() const { return _stem_extend; }


MatcherParams& MatcherParams::SetWordFolder(Fast_WordFolder* wordfolder)
MatcherParams& MatcherParams::SetWordFolder(const Fast_WordFolder* wordfolder)
{
_wordfolder = wordfolder;
return *this;
Expand Down
4 changes: 2 additions & 2 deletions searchsummary/src/vespa/juniper/juniperparams.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class MatcherParams
MatcherParams& SetStemMaxExtend(size_t stem_extend);
size_t StemMaxExtend() const;

MatcherParams& SetWordFolder(Fast_WordFolder* wordfolder);
MatcherParams& SetWordFolder(const Fast_WordFolder* wordfolder);
const Fast_WordFolder* WordFolder() const noexcept { return _wordfolder; }

MatcherParams& SetProximityFactor(double factor);
Expand All @@ -79,7 +79,7 @@ class MatcherParams
size_t _max_match_candidates;
size_t _stem_min;
size_t _stem_extend;
Fast_WordFolder* _wordfolder; // The wordfolder object needed as 1st parameter to folderfun
const Fast_WordFolder* _wordfolder; // The wordfolder object needed as 1st parameter to folderfun
double _proximity_factor;
};

Expand Down
2 changes: 1 addition & 1 deletion searchsummary/src/vespa/juniper/propreader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void PropReader::Process(const char* filename)
}


const char* PropReader::GetProperty(const char* name, const char* def)
const char* PropReader::GetProperty(const char* name, const char* def) const
{
const char* v = _keymap.Lookup(name, def);
LOG(debug, "Parameter lookup :%s: value :%s:", name, v);
Expand Down
2 changes: 1 addition & 1 deletion searchsummary/src/vespa/juniper/propreader.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class PropReader : public IJuniperProperties
{
public:
PropReader(const char* filename);
const char* GetProperty(const char* name, const char* def = NULL) override;
const char* GetProperty(const char* name, const char* def = nullptr) const override;
void UpdateProperty(const char* name, const char* value);
~PropReader() {}
protected:
Expand Down
4 changes: 2 additions & 2 deletions searchsummary/src/vespa/juniper/rpinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ Juniper::~Juniper()
{
}

std::unique_ptr<Config> Juniper::CreateConfig(const char* config_name)
std::unique_ptr<Config> Juniper::CreateConfig(const char* config_name) const
{
return std::unique_ptr<Config>(new Config(config_name, *this));
}

std::unique_ptr<QueryHandle> Juniper::CreateQueryHandle(const IQuery& fquery, const char* juniperoptions)
std::unique_ptr<QueryHandle> Juniper::CreateQueryHandle(const IQuery& fquery, const char* juniperoptions) const
{
return std::make_unique<QueryHandle>(fquery, juniperoptions, *_modifier);
}
Expand Down
8 changes: 4 additions & 4 deletions searchsummary/src/vespa/juniper/rpinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ class Juniper {
*/
~Juniper();

Fast_WordFolder & getWordFolder() { return *_wordfolder; }
IJuniperProperties & getProp() { return *_props; }
const Fast_WordFolder & getWordFolder() const noexcept { return *_wordfolder; }
const IJuniperProperties & getProp() const noexcept { return *_props; }
QueryModifier & getModifier() { return *_modifier; }

/** Create a result processing configuration of Juniper for subsequent use
Expand All @@ -111,7 +111,7 @@ class Juniper {
* NULL if an error occurred.
*/

std::unique_ptr<Config> CreateConfig(const char* config_name = "juniper");
std::unique_ptr<Config> CreateConfig(const char* config_name = "juniper") const;
/** Allocate a query handle for the given query for subsequent calls to Analyse
* for different hits. Performs the necessary per query processing for Juniper.
* @param query A query to start result processing for.
Expand All @@ -122,7 +122,7 @@ class Juniper {
* to the query language.
* @return A unique pointer to a QueryHandle.
*/
std::unique_ptr<QueryHandle> CreateQueryHandle(const IQuery& query, const char* juniperoptions);
std::unique_ptr<QueryHandle> CreateQueryHandle(const IQuery& query, const char* juniperoptions) const;

/** Add an rewriter for all terms that are prefixed with the given index.
* When Juniper encounter a term in the query tagged with this index,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ using vespalib::IllegalArgumentException;

namespace search::docsummary {

DocsumFieldWriterFactory::DocsumFieldWriterFactory(bool use_v8_geo_positions, IDocsumEnvironment& env)
DocsumFieldWriterFactory::DocsumFieldWriterFactory(bool use_v8_geo_positions, const IDocsumEnvironment& env)
: _use_v8_geo_positions(use_v8_geo_positions),
_env(env),
_matching_elems_fields(std::make_shared<MatchingElementsFields>())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ class IDocsumEnvironment;
class DocsumFieldWriterFactory : public IDocsumFieldWriterFactory
{
bool _use_v8_geo_positions;
IDocsumEnvironment& _env;
const IDocsumEnvironment& _env;
protected:
std::shared_ptr<MatchingElementsFields> _matching_elems_fields;
IDocsumEnvironment& getEnvironment() const noexcept { return _env; }
const IDocsumEnvironment& getEnvironment() const noexcept { return _env; }
bool has_attribute_manager() const noexcept;
public:
DocsumFieldWriterFactory(bool use_v8_geo_positions, IDocsumEnvironment& env);
DocsumFieldWriterFactory(bool use_v8_geo_positions, const IDocsumEnvironment& env);
~DocsumFieldWriterFactory() override;
std::unique_ptr<DocsumFieldWriter> create_docsum_field_writer(const vespalib::string& fieldName, const vespalib::string& overrideName, const vespalib::string& argument, bool& rc) override;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ class ResultConfig;
class DynamicDocsumConfig
{
public:
DynamicDocsumConfig(IDocsumEnvironment& env, DynamicDocsumWriter * writer) :
DynamicDocsumConfig(const IDocsumEnvironment& env, DynamicDocsumWriter * writer) :
_env(env),
_writer(writer)
{ }
virtual ~DynamicDocsumConfig() = default;
void configure(const vespa::config::search::SummarymapConfig &cfg);
protected:
using string = vespalib::string;
IDocsumEnvironment& getEnvironment() { return _env; }
const IDocsumEnvironment& getEnvironment() { return _env; }
const ResultConfig & getResultConfig() const;

virtual std::unique_ptr<IDocsumFieldWriterFactory> make_docsum_field_writer_factory();
private:
IDocsumEnvironment& _env;
const IDocsumEnvironment& _env;
DynamicDocsumWriter * _writer;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ JuniperQueryAdapter::Traverse(juniper::IQueryVisitor *v) const
return rc;
}

JuniperDFW::JuniperDFW(juniper::Juniper * juniper)
JuniperDFW::JuniperDFW(const juniper::Juniper * juniper)
: _input_field_name(),
_juniperConfig(),
_juniper(juniper)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class IDocsumEnvironment {
public:
virtual const search::IAttributeManager * getAttributeManager() const = 0;
virtual vespalib::string lookupIndex(const vespalib::string & s) const = 0;
virtual juniper::Juniper * getJuniper() = 0;
virtual const juniper::Juniper * getJuniper() const = 0;
virtual ~IDocsumEnvironment() = default;
};

Expand Down
8 changes: 4 additions & 4 deletions searchsummary/src/vespa/searchsummary/docsummary/juniperdfw.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ class JuniperDFW : public DocsumFieldWriter
const char *fieldName,
const vespalib::string& inputField);
protected:
explicit JuniperDFW(juniper::Juniper * juniper);
explicit JuniperDFW(const juniper::Juniper * juniper);
~JuniperDFW() override;

vespalib::string _input_field_name;
std::unique_ptr<juniper::Config> _juniperConfig;
juniper::Juniper *_juniper;
const juniper::Juniper *_juniper;
private:
bool IsGenerated() const override { return false; }
JuniperDFW(const JuniperDFW &);
Expand All @@ -39,7 +39,7 @@ class JuniperTeaserDFW : public JuniperDFW
bool Init(const char *fieldName,
const vespalib::string& inputField) override;
protected:
explicit JuniperTeaserDFW(juniper::Juniper * juniper) : JuniperDFW(juniper) { }
explicit JuniperTeaserDFW(const juniper::Juniper * juniper) : JuniperDFW(juniper) { }
};


Expand All @@ -49,7 +49,7 @@ class DynamicTeaserDFW : public JuniperTeaserDFW
vespalib::stringref input,
GetDocsumsState *state) const;
public:
explicit DynamicTeaserDFW(juniper::Juniper * juniper) : JuniperTeaserDFW(juniper) { }
explicit DynamicTeaserDFW(const juniper::Juniper * juniper) : JuniperTeaserDFW(juniper) { }

void insertField(uint32_t docid, const IDocsumStoreDocument* doc, GetDocsumsState *state,
ResType type, vespalib::slime::Inserter &target) const override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ JuniperProperties::configure(const JuniperrcConfig &cfg)
}

const char *
JuniperProperties::GetProperty(const char *name, const char *def)
JuniperProperties::GetProperty(const char *name, const char *def) const
{
auto it = _properties.find(name);
return it != _properties.end() ? it->second.c_str() : def;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class JuniperProperties : public IJuniperProperties {
/**
* Constructs a juniper property object with default values set.
*/
JuniperProperties(const vespa::config::search::summary::JuniperrcConfig &cfg);
explicit JuniperProperties(const vespa::config::search::summary::JuniperrcConfig &cfg);

~JuniperProperties() override;

Expand All @@ -38,7 +38,7 @@ class JuniperProperties : public IJuniperProperties {
void configure(const vespa::config::search::summary::JuniperrcConfig &cfg);

// Inherit doc from IJuniperProperties.
const char *GetProperty(const char *name, const char *def) override;
const char *GetProperty(const char *name, const char *def) const override;
};

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ bool useful(search::ParseItem::ItemCreator creator)
}


KeywordExtractor::KeywordExtractor(IDocsumEnvironment * env)
KeywordExtractor::KeywordExtractor(const IDocsumEnvironment * env)
: _env(env),
_legalPrefixes(),
_legalIndexes()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class KeywordExtractor

private:
typedef vespalib::hash_set<vespalib::string> Set;
IDocsumEnvironment *_env;
const IDocsumEnvironment *_env;
std::vector<IndexPrefix> _legalPrefixes;
Set _legalIndexes;

Expand All @@ -46,7 +46,7 @@ class KeywordExtractor
}
bool IsLegalIndexName(const char *idxName) const;
public:
explicit KeywordExtractor(IDocsumEnvironment * env);
explicit KeywordExtractor(const IDocsumEnvironment * env);
KeywordExtractor(const KeywordExtractor &) = delete;
KeywordExtractor& operator=(const KeywordExtractor &) = delete;
~KeywordExtractor();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

namespace search::docsummary {

class IDocsumEnvironment;

class RankFeaturesDFW : public SimpleDFW
{
public:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

namespace search::docsummary {

class IDocsumEnvironment;

class SummaryFeaturesDFW : public SimpleDFW
{
public:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void populate_fields(MatchingElementsFields& fields, VsmfieldsConfig& fields_con

}

DocsumFieldWriterFactory::DocsumFieldWriterFactory(bool use_v8_geo_positions, IDocsumEnvironment& env, const vespa::config::search::vsm::VsmfieldsConfig& vsm_fields_config)
DocsumFieldWriterFactory::DocsumFieldWriterFactory(bool use_v8_geo_positions, const IDocsumEnvironment& env, const vespa::config::search::vsm::VsmfieldsConfig& vsm_fields_config)
: search::docsummary::DocsumFieldWriterFactory(use_v8_geo_positions, env),
_vsm_fields_config(vsm_fields_config)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class DocsumFieldWriterFactory : public search::docsummary::DocsumFieldWriterFac
const vespa::config::search::vsm::VsmfieldsConfig& _vsm_fields_config;

public:
DocsumFieldWriterFactory(bool use_v8_geo_positions, search::docsummary::IDocsumEnvironment& env, const vespa::config::search::vsm::VsmfieldsConfig& vsm_fields_config);
DocsumFieldWriterFactory(bool use_v8_geo_positions, const search::docsummary::IDocsumEnvironment& env, const vespa::config::search::vsm::VsmfieldsConfig& vsm_fields_config);
~DocsumFieldWriterFactory() override;
std::unique_ptr<search::docsummary::DocsumFieldWriter>
create_docsum_field_writer(const vespalib::string& fieldName, const vespalib::string& overrideName, const vespalib::string& argument, bool& rc) override;
Expand Down
2 changes: 1 addition & 1 deletion streamingvisitors/src/vespa/vsm/vsm/docsumconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ using vespa::config::search::vsm::VsmfieldsConfig;

namespace vsm {

DynamicDocsumConfig::DynamicDocsumConfig(search::docsummary::IDocsumEnvironment& env, search::docsummary::DynamicDocsumWriter* writer, std::shared_ptr<VsmfieldsConfig> vsm_fields_config)
DynamicDocsumConfig::DynamicDocsumConfig(const search::docsummary::IDocsumEnvironment& env, search::docsummary::DynamicDocsumWriter* writer, std::shared_ptr<VsmfieldsConfig> vsm_fields_config)
: Parent(env, writer),
_vsm_fields_config(std::move(vsm_fields_config))
{
Expand Down
2 changes: 1 addition & 1 deletion streamingvisitors/src/vespa/vsm/vsm/docsumconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class DynamicDocsumConfig : public search::docsummary::DynamicDocsumConfig
private:
std::shared_ptr<VsmfieldsConfig> _vsm_fields_config;
public:
DynamicDocsumConfig(search::docsummary::IDocsumEnvironment& env, search::docsummary::DynamicDocsumWriter* writer, std::shared_ptr<VsmfieldsConfig> vsm_fields_config);
DynamicDocsumConfig(const search::docsummary::IDocsumEnvironment& env, search::docsummary::DynamicDocsumWriter* writer, std::shared_ptr<VsmfieldsConfig> vsm_fields_config);
private:
std::unique_ptr<search::docsummary::IDocsumFieldWriterFactory> make_docsum_field_writer_factory() override;
};
Expand Down
2 changes: 1 addition & 1 deletion streamingvisitors/src/vespa/vsm/vsm/vsm-adapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class DocsumTools : public IDocsumEnvironment
// inherit doc from IDocsumEnvironment
const search::IAttributeManager * getAttributeManager() const override { return nullptr; }
vespalib::string lookupIndex(const vespalib::string&) const override { return ""; }
juniper::Juniper * getJuniper() override { return _juniper.get(); }
const juniper::Juniper * getJuniper() const override { return _juniper.get(); }
};

typedef std::shared_ptr<DocsumTools> DocsumToolsPtr;
Expand Down

0 comments on commit 067aba3

Please sign in to comment.