Hi,
I am new to erlang, just started today, because we were advised to move some of
our views to native erlang views, I am trying to write a reduce function:
The Values its using seem to be in the form:
[[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1]]
so I have tried to do the following to get a count of all the 1's, but it only
gives me the count of the outermost lists (in the above case 3, instead of
60(ish))
My Reduce funtion:
fun(Keys, Values, ReReduce) -> lists:flatlength(Values) end.
My Map function looks like this:
fun({Doc}) ->
Emitter = fun(Doc) ->
Date = proplists:get_value(<<"publish_date">>, Doc),
Year = string:substr(erlang:bitstring_to_list(Date), 1, 4),
Emit(erlang:list_to_bitstring(Year), 1)
end,
HasRequiredFields = fun(Doc) ->
case {proplists:is_defined(<<"a_number">>, Doc),
proplists:is_defined(<<"publish">>, Doc),
proplists:is_defined(<<"publish_date">>, Doc)} of
{true, true, true} ->
Emitter(Doc);
_->
false
end
end,
HasRequiredFields(Doc)
end.
Cheers
Jeremy