phrases: only allow for index fields
This commit is contained in:
@ -104,11 +104,12 @@ struct Value: public Data {
|
|||||||
* @param _value the value
|
* @param _value the value
|
||||||
*/
|
*/
|
||||||
Value (const std::string& _field, const std::string& _prefix,
|
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),
|
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<Data>& v)
|
|||||||
const auto bval = dynamic_cast<Value*> (v.get());
|
const auto bval = dynamic_cast<Value*> (v.get());
|
||||||
os << ' ' << quote(v->field) << ' '
|
os << ' ' << quote(v->field) << ' '
|
||||||
<< quote(utf8_flatten(bval->value));
|
<< quote(utf8_flatten(bval->value));
|
||||||
|
if (bval->phrase)
|
||||||
|
os << " (ph)";
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Data::Type::Range: {
|
case Data::Type::Range: {
|
||||||
|
|||||||
@ -68,7 +68,8 @@ value (const ProcIface::FieldInfoVec& fields, const std::string& v,
|
|||||||
return Tree({Node::Type::Value,
|
return Tree({Node::Type::Value,
|
||||||
std::make_unique<Value>(
|
std::make_unique<Value>(
|
||||||
item.field, item.prefix, item.id,
|
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:"
|
// 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,
|
tree.add_child (Tree({Node::Type::Value,
|
||||||
std::make_unique<Value>(
|
std::make_unique<Value>(
|
||||||
item.field, item.prefix, item.id,
|
item.field, item.prefix, item.id,
|
||||||
proc->process_value(item.field, val))}));
|
proc->process_value(item.field, val),
|
||||||
|
item.supports_phrase)}));
|
||||||
return tree;
|
return tree;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -41,6 +41,7 @@ struct ProcIface {
|
|||||||
struct FieldInfo {
|
struct FieldInfo {
|
||||||
const std::string field;
|
const std::string field;
|
||||||
const std::string prefix;
|
const std::string prefix;
|
||||||
|
bool supports_phrase;
|
||||||
unsigned id;
|
unsigned id;
|
||||||
};
|
};
|
||||||
using FieldInfoVec = std::vector<FieldInfo>;
|
using FieldInfoVec = std::vector<FieldInfo>;
|
||||||
@ -102,7 +103,7 @@ struct DummyProc: public ProcIface { // For testing
|
|||||||
|
|
||||||
std::vector<FieldInfo>
|
std::vector<FieldInfo>
|
||||||
process_field (const std::string& field) const override {
|
process_field (const std::string& field) const override {
|
||||||
return {{ field, "x", 0 }};
|
return {{ field, "x", false, 0 }};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string
|
std::string
|
||||||
|
|||||||
@ -52,6 +52,9 @@ static Xapian::Query
|
|||||||
xapian_query_value (const Mux::Tree& tree)
|
xapian_query_value (const Mux::Tree& tree)
|
||||||
{
|
{
|
||||||
const auto v = dynamic_cast<Value*> (tree.node.data.get());
|
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, " ");
|
const auto parts = split (v->value, " ");
|
||||||
|
|
||||||
std::vector<Xapian::Query> phvec;
|
std::vector<Xapian::Query> phvec;
|
||||||
|
|||||||
Reference in New Issue
Block a user