summaryrefslogtreecommitdiff
path: root/src/couchdb/couch_ft_query.erl
diff options
context:
space:
mode:
authorJan Lehnardt <jan@apache.org>2008-08-20 13:55:41 +0000
committerJan Lehnardt <jan@apache.org>2008-08-20 13:55:41 +0000
commit2bc4be3dbf9e8ea3b67c62f2d99087ff4b43c17b (patch)
tree9a961f6f3fb0acbd9d34abef40492bbe95cc3d94 /src/couchdb/couch_ft_query.erl
parentad6fd47a1f13e8d09eb5864c50e102825e28b75c (diff)
Merge runtimeconfig branch back into trunk
git-svn-id: https://svn.apache.org/repos/asf/incubator/couchdb/trunk@687336 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/couchdb/couch_ft_query.erl')
-rw-r--r--src/couchdb/couch_ft_query.erl32
1 files changed, 22 insertions, 10 deletions
diff --git a/src/couchdb/couch_ft_query.erl b/src/couchdb/couch_ft_query.erl
index 2d1b9fc5..67fa5948 100644
--- a/src/couchdb/couch_ft_query.erl
+++ b/src/couchdb/couch_ft_query.erl
@@ -13,14 +13,12 @@
-module(couch_ft_query).
-behaviour(gen_server).
--export([start_link/1, execute/2]).
+-export([start_link/0, execute/2]).
-export([init/1, terminate/2, handle_call/3, handle_cast/2, handle_info/2,code_change/3, stop/0]).
--define(ERR_HANDLE, {Port, {exit_status, Status}} -> {stop, {unknown_error, Status}, {unknown_error, Status}, Port}).
-
-start_link(QueryExec) ->
- gen_server:start_link({local, couch_ft_query}, couch_ft_query, QueryExec, []).
+start_link() ->
+ gen_server:start_link({local, couch_ft_query}, couch_ft_query, [], []).
stop() ->
exit(whereis(couch_ft_query), close).
@@ -28,15 +26,27 @@ stop() ->
execute(DatabaseName, QueryString) ->
gen_server:call(couch_ft_query, {ft_query, DatabaseName, QueryString}).
-init(QueryExec) ->
- Port = open_port({spawn, QueryExec}, [{line, 1000}, exit_status, hide]),
- {ok, Port}.
+init([]) ->
+ ok = couch_config:register(
+ fun({"Search", "QueryServer"}) ->
+ ?MODULE:stop()
+ end),
+
+ case couch_config:get({"Search", "QueryServer"}, none) of
+ none ->
+ {ok, none};
+ QueryExec ->
+ Port = open_port({spawn, QueryExec}, [{line, 1000}, exit_status, hide]),
+ {ok, Port}
+ end.
terminate(_Reason, _Server) ->
ok.
+handle_call({ft_query, _Database, _QueryText}, _From, none) ->
+ {reply, {error, no_full_test_query_specified_in_config}, none};
handle_call({ft_query, Database, QueryText}, _From, Port) ->
- %% send the database name
+ % send the database name
true = port_command(Port, Database ++ "\n"),
true = port_command(Port, QueryText ++ "\n"),
case get_line(Port) of
@@ -63,7 +73,9 @@ get_line(Port) ->
receive
{Port, {data, {eol, Line}}} ->
Line;
- ?ERR_HANDLE
+ % would love to use ?ERR_HANDLE here, but edoc doesn't like it.
+ % TODO: find a way to skip that.
+ {Port, {exit_status, Status}} -> {stop, {unknown_error, Status}, {unknown_error, Status}, Port}
end.
handle_cast(_Whatever, State) ->