Skip to content
This repository
Browse code

Merge branch 'master' into fixes/riak_search

  • Loading branch information...
commit 491c70447baff5e1877345421e042c5a066880d3 2 parents 1f21171 + ddd88ac
Daniel Kempkens authored April 04, 2013
4  src/boss_db.erl
@@ -401,7 +401,9 @@ normalize_conditions([{Key, 'eq', Value}|Rest], Acc) when is_atom(Key) ->
401 401
 normalize_conditions([{Key, 'ne', Value}|Rest], Acc) when is_atom(Key) ->
402 402
     normalize_conditions(Rest, [{Key, 'not_equals', Value}|Acc]);
403 403
 normalize_conditions([{Key, Operator, Value}|Rest], Acc) when is_atom(Key), is_atom(Operator) ->
404  
-    normalize_conditions(Rest, [{Key, Operator, Value}|Acc]).
  404
+    normalize_conditions(Rest, [{Key, Operator, Value}|Acc]);
  405
+normalize_conditions([{Key, Operator, Value, Options}|Rest], Acc) when is_atom(Key), is_atom(Operator), is_list(Options) ->
  406
+    normalize_conditions(Rest, [{Key, Operator, Value, Options}|Acc]).
405 407
 
406 408
 return_one(Result) ->
407 409
     case Result of
20  src/db_adapters/boss_db_adapter_mongodb.erl
@@ -196,6 +196,12 @@ build_conditions(Conditions, OrderBy) ->
196 196
 build_conditions1([], Acc) ->
197 197
     Acc;
198 198
 
  199
+build_conditions1([{Key, 'matches', Value, Options}|Rest], Acc) ->
  200
+    MongoOptions = mongo_regex_options_for_re_module_options(Options),
  201
+    build_conditions1(Rest, [{Key, {regex, list_to_binary(Value), list_to_binary(MongoOptions)}}|Acc]);
  202
+build_conditions1([{Key, 'not_matches', Value, Options}|Rest], Acc) ->
  203
+    MongoOptions = mongo_regex_options_for_re_module_options(Options),
  204
+    build_conditions1(Rest, [{Key, {'$not', {regex, list_to_binary(Value), list_to_binary(MongoOptions)}}}|Acc]);
199 205
 build_conditions1([{Key, Operator, Value}|Rest], Acc) ->
200 206
 %    ?LOG("Key, Operator, Value", {Key, Operator, Value}),
201 207
 
@@ -328,6 +334,20 @@ mongo_tuple_to_record(Type, Row) ->
328 334
         end, boss_record_lib:attribute_names(Type)),
329 335
     apply(Type, new, Args).
330 336
 
  337
+mongo_regex_options_for_re_module_options(Options) ->
  338
+    mongo_regex_options_for_re_module_options(Options, []).
  339
+
  340
+mongo_regex_options_for_re_module_options([], Acc) ->
  341
+    lists:reverse(Acc);
  342
+mongo_regex_options_for_re_module_options([caseless|Rest], Acc) ->
  343
+    mongo_regex_options_for_re_module_options(Rest, [$i|Acc]);
  344
+mongo_regex_options_for_re_module_options([dotall|Rest], Acc) ->
  345
+    mongo_regex_options_for_re_module_options(Rest, [$s|Acc]);
  346
+mongo_regex_options_for_re_module_options([extended|Rest], Acc) ->
  347
+    mongo_regex_options_for_re_module_options(Rest, [$x|Acc]);
  348
+mongo_regex_options_for_re_module_options([multiline|Rest], Acc) ->
  349
+    mongo_regex_options_for_re_module_options(Rest, [$m|Acc]).
  350
+
331 351
 % Boss and MongoDB have a different conventions to id attributes (id vs. '_id').
332 352
 attr_value(id, MongoDoc) ->
333 353
     proplists:get_value('_id', MongoDoc);

0 notes on commit 491c704

Please sign in to comment.
Something went wrong with that request. Please try again.