Skip to content

Commit

Permalink
Merge branch 'master' into fixes/riak_search
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Kempkens committed Apr 4, 2013
2 parents 1f21171 + ddd88ac commit 491c704
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/boss_db.erl
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions src/db_adapters/boss_db_adapter_mongodb.erl
Expand Up @@ -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}),

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 491c704

Please sign in to comment.