From 6ce7c89488842c4810576f11e567ef491111672a Mon Sep 17 00:00:00 2001 From: djcb Date: Fri, 27 Oct 2017 18:42:58 +0300 Subject: [PATCH] phrases: only allow for index fields --- lib/parser/data.hh | 10 +++++++--- lib/parser/parser.cc | 6 ++++-- lib/parser/proc-iface.hh | 3 ++- lib/parser/xapian.cc | 3 +++ 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/parser/data.hh b/lib/parser/data.hh index 513db514..123aea49 100644 --- a/lib/parser/data.hh +++ b/lib/parser/data.hh @@ -104,11 +104,12 @@ struct Value: public Data { * @param _value the value */ Value (const std::string& _field, const std::string& _prefix, - unsigned _id, const std::string& _value): + unsigned _id, const std::string& _value, bool _phrase = false): Data(Value::Type::Value, _field, _prefix, _id), - value(_value) {} + value(_value), phrase(_phrase) {} - std::string value; /**< the value */ + std::string value; /**< the value */ + bool phrase; }; @@ -128,6 +129,9 @@ operator<< (std::ostream& os, const std::unique_ptr& v) const auto bval = dynamic_cast (v.get()); os << ' ' << quote(v->field) << ' ' << quote(utf8_flatten(bval->value)); + if (bval->phrase) + os << " (ph)"; + break; } case Data::Type::Range: { diff --git a/lib/parser/parser.cc b/lib/parser/parser.cc index cf4ac25a..f416c19f 100644 --- a/lib/parser/parser.cc +++ b/lib/parser/parser.cc @@ -68,7 +68,8 @@ value (const ProcIface::FieldInfoVec& fields, const std::string& v, return Tree({Node::Type::Value, std::make_unique( item.field, item.prefix, item.id, - proc->process_value(item.field, val))}); + proc->process_value(item.field, val), + item.supports_phrase)}); } // a 'multi-field' such as "recip:" @@ -77,7 +78,8 @@ value (const ProcIface::FieldInfoVec& fields, const std::string& v, tree.add_child (Tree({Node::Type::Value, std::make_unique( item.field, item.prefix, item.id, - proc->process_value(item.field, val))})); + proc->process_value(item.field, val), + item.supports_phrase)})); return tree; } diff --git a/lib/parser/proc-iface.hh b/lib/parser/proc-iface.hh index f6633dd2..a57e4b0d 100644 --- a/lib/parser/proc-iface.hh +++ b/lib/parser/proc-iface.hh @@ -41,6 +41,7 @@ struct ProcIface { struct FieldInfo { const std::string field; const std::string prefix; + bool supports_phrase; unsigned id; }; using FieldInfoVec = std::vector; @@ -102,7 +103,7 @@ struct DummyProc: public ProcIface { // For testing std::vector process_field (const std::string& field) const override { - return {{ field, "x", 0 }}; + return {{ field, "x", false, 0 }}; } std::string diff --git a/lib/parser/xapian.cc b/lib/parser/xapian.cc index 229c9ce5..b95ff569 100644 --- a/lib/parser/xapian.cc +++ b/lib/parser/xapian.cc @@ -52,6 +52,9 @@ static Xapian::Query xapian_query_value (const Mux::Tree& tree) { const auto v = dynamic_cast (tree.node.data.get()); + if (!v->phrase) + return Xapian::Query(v->prefix + v->value); + const auto parts = split (v->value, " "); std::vector phvec;