On 8/7/10 at 7:37 AM, [email protected] (Sivan Greenberg) wrote:

As I am also using a JS filter and fear the performance and load
consequences, how does one go about writing an erlang filter?

-SIvan

I can't claim it to be idiomatic Erlang, but this is the one I am working on that accepts query argument from the client opening the change feed.

fun({Doc}, {Req}) ->
    {Query} = couch_util:get_value(<<"query">>, Req),
    ExcludedServer = couch_util:get_value(<<"excludeServer">>, Query),
case {couch_util:get_value(<<"docType">>, Doc), couch_util:get_value(<<"updatedOnServer">>, Doc)} of
        {<<"CS_MANIFEST">>, null} ->
CreatedOnServer = couch_util:get_value(<<"createdOnServer">>, Doc),
            CreatedOnServer =/= ExcludedServer;
        {<<"CS_MANIFEST">>, undefined} ->
            false;
        {<<CS_MANIFEST">>, UpdatedOnServer} ->
            UpdatedOnServer =/= ExcludedServer;
        _ ->
            false
    end
end.


BTW, since strings are represented as Binaries (<<>> syntax), string manipulation in Erlang map-reduce and filter functions is easy with Erlang's BIFs that manipulate binaries, like split_binary().

Matt

Reply via email to