diff options
| author | LV-426 <lv-426@taproot.org.il> | 2014-10-05 20:51:57 +0200 |
|---|---|---|
| committer | LV-426 <lv-426@taproot.org.il> | 2014-10-05 20:51:57 +0200 |
| commit | 82f927d4ca2ca671afccc3a5efd1e73e2e89e9ca (patch) | |
| tree | 3d4948c4af3898bb47d6908cf45c64e9e40e1909 /src-py | |
| parent | 78bf830f0a48fa3dd9d2e956b94eebf1d0eac7b2 (diff) | |
fix DBO_load_node_set_by_attribute filter query part construction
Diffstat (limited to 'src-py')
| -rw-r--r-- | src-py/db_controller.py | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/src-py/db_controller.py b/src-py/db_controller.py index 309ba823..04312eaa 100644 --- a/src-py/db_controller.py +++ b/src-py/db_controller.py @@ -146,17 +146,32 @@ class DBO_load_node_set_by_DB_id(DB_op): class DBO_load_node_set_by_attribute(DB_op): - def __init__(self, attr_name, attr_set): + def __init__(self, filter_attr_map): """ - load a set of nodes whose attr_name is in attr_set + load a set of nodes according to filter_attr_map + @param filter_attr_map: is a filter_key to filter_value_set map of + attributes to match against, eg.: + { 'id':[0,1], 'color: ['red','blue'] } @return: loaded node set or an empty set if no match was found """ - assert isinstance(attr_set, list) - + + # type sanity checks + assert isinstance(filter_attr_map, dict) + assert len(filter_attr_map) > 0 + for k, v in filter_attr_map.items(): + assert isinstance(k, basestring) + assert isinstance(v, list) + + filter_arr = [] + for k, v in filter_attr_map.items(): + f_attr = "n.{0} in {1}".format(k, v) + filter_arr.append(f_attr) + filter_str = "where {0}".format(' and '.join(filter_arr)) + super(DBO_load_node_set_by_attribute, self).__init__() - q = "match (n) where n.{0} in {{attr_set}} return n".format(attr_name) - self.add_statement(q, { 'attr_set': attr_set}) + q = "match (n) {0} return n".format(filter_str) + self.add_statement(q, { 'attr_set': filter_str}) def on_success(self, data): log.debug('loaded node set: ' + str(data)) |
