Permalink
Browse files

Merge branch 'master' into fixes/riak_search

  • Loading branch information...
2 parents 1f21171 + ddd88ac commit 491c70447baff5e1877345421e042c5a066880d3 @nifoc nifoc committed Apr 4, 2013
Showing with 23 additions and 1 deletion.
  1. +3 −1 src/boss_db.erl
  2. +20 −0 src/db_adapters/boss_db_adapter_mongodb.erl
View
@@ -401,7 +401,9 @@ normalize_conditions([{Key, 'eq', Value}|Rest], Acc) when is_atom(Key) ->
normalize_conditions([{Key, 'ne', Value}|Rest], Acc) when is_atom(Key) ->
normalize_conditions(Rest, [{Key, 'not_equals', Value}|Acc]);
normalize_conditions([{Key, Operator, Value}|Rest], Acc) when is_atom(Key), is_atom(Operator) ->
- normalize_conditions(Rest, [{Key, Operator, Value}|Acc]).
+ normalize_conditions(Rest, [{Key, Operator, Value}|Acc]);
+normalize_conditions([{Key, Operator, Value, Options}|Rest], Acc) when is_atom(Key), is_atom(Operator), is_list(Options) ->
+ normalize_conditions(Rest, [{Key, Operator, Value, Options}|Acc]).
return_one(Result) ->
case Result of
@@ -196,6 +196,12 @@ build_conditions(Conditions, OrderBy) ->
build_conditions1([], Acc) ->
Acc;
+build_conditions1([{Key, 'matches', Value, Options}|Rest], Acc) ->
+ MongoOptions = mongo_regex_options_for_re_module_options(Options),
+ build_conditions1(Rest, [{Key, {regex, list_to_binary(Value), list_to_binary(MongoOptions)}}|Acc]);
+build_conditions1([{Key, 'not_matches', Value, Options}|Rest], Acc) ->
+ MongoOptions = mongo_regex_options_for_re_module_options(Options),
+ build_conditions1(Rest, [{Key, {'$not', {regex, list_to_binary(Value), list_to_binary(MongoOptions)}}}|Acc]);
build_conditions1([{Key, Operator, Value}|Rest], Acc) ->
% ?LOG("Key, Operator, Value", {Key, Operator, Value}),
@@ -328,6 +334,20 @@ mongo_tuple_to_record(Type, Row) ->
end, boss_record_lib:attribute_names(Type)),
apply(Type, new, Args).
+mongo_regex_options_for_re_module_options(Options) ->
+ mongo_regex_options_for_re_module_options(Options, []).
+
+mongo_regex_options_for_re_module_options([], Acc) ->
+ lists:reverse(Acc);
+mongo_regex_options_for_re_module_options([caseless|Rest], Acc) ->
+ mongo_regex_options_for_re_module_options(Rest, [$i|Acc]);
+mongo_regex_options_for_re_module_options([dotall|Rest], Acc) ->
+ mongo_regex_options_for_re_module_options(Rest, [$s|Acc]);
+mongo_regex_options_for_re_module_options([extended|Rest], Acc) ->
+ mongo_regex_options_for_re_module_options(Rest, [$x|Acc]);
+mongo_regex_options_for_re_module_options([multiline|Rest], Acc) ->
+ mongo_regex_options_for_re_module_options(Rest, [$m|Acc]).
+
% Boss and MongoDB have a different conventions to id attributes (id vs. '_id').
attr_value(id, MongoDoc) ->
proplists:get_value('_id', MongoDoc);

0 comments on commit 491c704

Please sign in to comment.