You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Norman Barker <no...@gmail.com> on 2010/07/17 21:15:50 UTC

geocouch

Hi,

I am using geocouch to index documents and it is working well, I have
had a couple of issues, firstly you can only emit one spatial key per
document and it is useful to emit more than one spatial key as you
parse the document (rather than creating a geojson geometry
collection).

Secondly, and perhaps more importantly, if you don't emit a spatial
key then the indexing fails.

In couch_spatial_updater I changed the spatial docs function as below,
but this should be considered a workaround, I see the bbox to
[[{{-181.0, -91.0, -181.0, -91.0}, [null]}]]; knowing that won't be
queried, really I would like to set it to the atom undefined and not
have it in the index when not emitted.

Final comment is that I was patching a 1.0 windows release, and the
only 1.0 branch files that are different are couch_view_group and
couch_query_servers and the changes were -export([hex_sig/1]). and
-export([get_os_process/1]). if they could get added to trunk then
perhaps geocouch could be kept as a separate plugin? I was able to put
the daemons in local.ini and it worked fine.

Good work though, this is cool and is really quick!.

spatial_docs(Proc, Docs) ->
    % send the documents
    Results = lists:map(
        fun(Doc) ->
            Json = couch_doc:to_json_obj(Doc, []),
            % NOTE vmx: perhaps should map_doc renamed to something more
            % general as it can be used for most indexers
            FunsResults = couch_query_servers:proc_prompt(Proc,
[<<"map_doc">>, Json]),
            % the results are a json array of function map yields like this:
            % [FunResults1, FunResults2 ...]
            % where funresults is are json arrays of key value pairs:
            % [[Key1, Value1], [Key2, Value2]]
            % Convert the key, value pairs to tuples like
            % [{Key1, Value1}, {Key2, Value2}]
            case FunsResults of
              [[]] ->
                 [[{{-181.0, -91.0, -181.0, -91.0}, [null]}]];
              _ ->
                lists:map(
                    fun(FunRs) ->
                        % do some post-processing of the result documents
                        FunRs2 = process_result(FunRs),
                        %JsonDoc = couch_query_servers:json_doc(Doc),
                        ?LOG_DEBUG("spatial_docs:~n~p~n~p", [FunRs, FunRs2]),
                        %[list_to_tuple(FunResult) || FunResult <- [FunRs]]
                        %[list_to_tuple(FunResult) || FunResult <- [FunRs2]]
                        [FunRs2]
                    end,
                FunsResults)
            end
        end,
        Docs),
    {ok, lists:filter(fun(X) -> X /= [[]] end, Results)}.

Norman

Re: geocouch

Posted by Volker Mische <vo...@gmail.com>.
Hi Norman,

On 07/17/2010 09:15 PM, Norman Barker wrote:
> Hi,
>
> I am using geocouch to index documents and it is working well, I have
> had a couple of issues, firstly you can only emit one spatial key per
> document and it is useful to emit more than one spatial key as you
> parse the document (rather than creating a geojson geometry
> collection).

If it's currently not possible to have several emit()s it's a bug. I 
really need a JavaScript test suite, not only Erlang tests for the vtree.

>
> Secondly, and perhaps more importantly, if you don't emit a spatial
> key then the indexing fails.
>
> In couch_spatial_updater I changed the spatial docs function as below,
> but this should be considered a workaround, I see the bbox to
> [[{{-181.0, -91.0, -181.0, -91.0}, [null]}]]; knowing that won't be
> queried, really I would like to set it to the atom undefined and not
> have it in the index when not emitted.


Kind of funny that so many people discovered this bug within a few days.
Normally if the code doesn't reach an emit() it won't show up in the 
index. I will fix it.

> Final comment is that I was patching a 1.0 windows release, and the
> only 1.0 branch files that are different are couch_view_group and
> couch_query_servers and the changes were -export([hex_sig/1]). and
> -export([get_os_process/1]). if they could get added to trunk then
> perhaps geocouch could be kept as a separate plugin? I was able to put
> the daemons in local.ini and it worked fine.

That's the plan. Though I haven't had the time yet. First step will be 
to move to trunk, and the reorganizing the code.

>
> Good work though, this is cool and is really quick!.

Thanks :)

Cheers,
   Volker

Re: geocouch

Posted by Norman Barker <no...@gmail.com>.
I have worked out how to attach these issues directly to geocouch,
great work Volker!

On Sat, Jul 17, 2010 at 1:15 PM, Norman Barker <no...@gmail.com> wrote:
> Hi,
>
> I am using geocouch to index documents and it is working well, I have
> had a couple of issues, firstly you can only emit one spatial key per
> document and it is useful to emit more than one spatial key as you
> parse the document (rather than creating a geojson geometry
> collection).
>
> Secondly, and perhaps more importantly, if you don't emit a spatial
> key then the indexing fails.
>
> In couch_spatial_updater I changed the spatial docs function as below,
> but this should be considered a workaround, I see the bbox to
> [[{{-181.0, -91.0, -181.0, -91.0}, [null]}]]; knowing that won't be
> queried, really I would like to set it to the atom undefined and not
> have it in the index when not emitted.
>
> Final comment is that I was patching a 1.0 windows release, and the
> only 1.0 branch files that are different are couch_view_group and
> couch_query_servers and the changes were -export([hex_sig/1]). and
> -export([get_os_process/1]). if they could get added to trunk then
> perhaps geocouch could be kept as a separate plugin? I was able to put
> the daemons in local.ini and it worked fine.
>
> Good work though, this is cool and is really quick!.
>
> spatial_docs(Proc, Docs) ->
>    % send the documents
>    Results = lists:map(
>        fun(Doc) ->
>            Json = couch_doc:to_json_obj(Doc, []),
>            % NOTE vmx: perhaps should map_doc renamed to something more
>            % general as it can be used for most indexers
>            FunsResults = couch_query_servers:proc_prompt(Proc,
> [<<"map_doc">>, Json]),
>            % the results are a json array of function map yields like this:
>            % [FunResults1, FunResults2 ...]
>            % where funresults is are json arrays of key value pairs:
>            % [[Key1, Value1], [Key2, Value2]]
>            % Convert the key, value pairs to tuples like
>            % [{Key1, Value1}, {Key2, Value2}]
>            case FunsResults of
>              [[]] ->
>                 [[{{-181.0, -91.0, -181.0, -91.0}, [null]}]];
>              _ ->
>                lists:map(
>                    fun(FunRs) ->
>                        % do some post-processing of the result documents
>                        FunRs2 = process_result(FunRs),
>                        %JsonDoc = couch_query_servers:json_doc(Doc),
>                        ?LOG_DEBUG("spatial_docs:~n~p~n~p", [FunRs, FunRs2]),
>                        %[list_to_tuple(FunResult) || FunResult <- [FunRs]]
>                        %[list_to_tuple(FunResult) || FunResult <- [FunRs2]]
>                        [FunRs2]
>                    end,
>                FunsResults)
>            end
>        end,
>        Docs),
>    {ok, lists:filter(fun(X) -> X /= [[]] end, Results)}.
>
> Norman
>