我们有一个map、rules>; service_map
其中规则是
struct rules
{
boost::unordered_multimap<string, string> set_of_rules_1;
boost::unordered_multimap<string, string> set_of_rules_2;
}
在我的例子中,规则是来自http请求headers
和arguments
的对,例如在一个这样的unordered_multimap中我们可以找到Accept -语言:FR
和接受语言:US
。
每个boost::shared_ptr都是继承自service class
的类的实例。
我填写这张服务地图<->规则与服务和规则一起运行(来自一些共享库和一些带有规则的文本文件)。
现在,我得到了 data
的实例,
struct data
{
map<string, string> headers;
map<string, string> arguments;
}
对于每个给定的 data
对象,我需要从 service_map
中找到最相关的 service
并调用其 service->inherited_method();
这里所说的“相关”是指其规则最适合给定数据的规则。例如,如果我们在规则 Accept-Language : FR
和 Accept-Language : US
中,则如果数据包含对 Accept-Language : fr-FR,ru; q=0.8,en-US;q=0.6,en;q=0.4
我们认为这是相关的。
预处理我的 service_map 以实现更快的软搜索的最佳方法是什么,以及如何实现此类搜索?
We have a map<boost::shared_ptr<service>, rules> service_map
where rules is
struct rules
{
boost::unordered_multimap<string, string> set_of_rules_1;
boost::unordered_multimap<string, string> set_of_rules_2;
}
In my case of rules are pairs from of http request headers
and arguments
, for example in one such unordered_multimap we could find Accept-Language : FR
and Accept-Language : US
.
Each boost::shared_ptr<service>
is some instance of class that inherits from service class
.
I fill this map of servise <-> rules on fly with services and rules (from some shared libs and some text files with rules).
Now I am given instances of data
struct data
{
map<string, string> headers;
map<string, string> arguments;
}
For each given data
object I need to find most relevant service
from service_map
and call its service->inherited_method();
By relevant here we mean one whose rules fit to given data mostly. For example if we have in rules Accept-Language : FR
and Accept-Language : US
than if data contains pair Accept-Language : fr-FR,ru;q=0.8,en-US;q=0.6,en;q=0.4
we think it is relevant.
What would be best way to preprocess my service_map for faster soft search, and how to implement such search?
发布评论
评论(1)
这是一项艰巨的任务,您必须自己开发一些逻辑。不过,这里有一个框架解决方案:
1) 编写一个函数,根据规则与给定数据集的相关性对规则进行排名:
2) 对于每条数据,创建规则的排序排名。例如,您可以保留一堆迭代器。然后找到与最相关的规则集匹配的服务。
我假设您的所有规则都保存在
RuleCollection rc;
中,这是值类型rules
的一些容器。编辑:修复了 multimap 元素插入 - 由于显而易见的原因,multimap 没有
[]
访问运算符。This is a tall order, and you'll have to develop some of the logic yourself. However, here's a skeleton solution:
1) Write a function that ranks rules according to their relevance for a given set of data:
2) For each piece of data, create a sorted ranking of the rules. For instance, you could keep a bunch of iterators around. Then find the service that matches the most relevant rule set.
I'm supposing that all your rules are kept in
RuleCollection rc;
, some container of value typerules
.Edit: Fixed multimap element insertion -- multimap does not have a
[]
access operator for obvious reasons.