From 2bc4be3dbf9e8ea3b67c62f2d99087ff4b43c17b Mon Sep 17 00:00:00 2001 From: Jan Lehnardt Date: Wed, 20 Aug 2008 13:55:41 +0000 Subject: Merge runtimeconfig branch back into trunk git-svn-id: https://svn.apache.org/repos/asf/incubator/couchdb/trunk@687336 13f79535-47bb-0310-9956-ffa450edef68 --- src/couchdb/couch_ft_query.erl | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) (limited to 'src/couchdb/couch_ft_query.erl') 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) -> -- cgit v1.2.3