phrases: only allow for index fields

This commit is contained in:
djcb
2017-10-27 18:42:58 +03:00
parent fe18603843
commit 6ce7c89488
4 changed files with 16 additions and 6 deletions

View File

@ -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 */
bool phrase;
};
@ -128,6 +129,9 @@ operator<< (std::ostream& os, const std::unique_ptr<Data>& v)
const auto bval = dynamic_cast<Value*> (v.get());
os << ' ' << quote(v->field) << ' '
<< quote(utf8_flatten(bval->value));
if (bval->phrase)
os << " (ph)";
break;
}
case Data::Type::Range: {

View File

@ -68,7 +68,8 @@ value (const ProcIface::FieldInfoVec& fields, const std::string& v,
return Tree({Node::Type::Value,
std::make_unique<Value>(
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<Value>(
item.field, item.prefix, item.id,
proc->process_value(item.field, val))}));
proc->process_value(item.field, val),
item.supports_phrase)}));
return tree;
}

View File

@ -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<FieldInfo>;
@ -102,7 +103,7 @@ struct DummyProc: public ProcIface { // For testing
std::vector<FieldInfo>
process_field (const std::string& field) const override {
return {{ field, "x", 0 }};
return {{ field, "x", false, 0 }};
}
std::string

View File

@ -52,6 +52,9 @@ static Xapian::Query
xapian_query_value (const Mux::Tree& tree)
{
const auto v = dynamic_cast<Value*> (tree.node.data.get());
if (!v->phrase)
return Xapian::Query(v->prefix + v->value);
const auto parts = split (v->value, " ");
std::vector<Xapian::Query> phvec;