PageRenderTime 10ms CodeModel.GetById 1ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/ucengine/src/core/ucengine_app.erl

Relevant Search: With Applications for Solr and Elasticsearch

For more in depth reading about search, ranking and generally everything you could ever want to know about how lucene, elasticsearch or solr work under the hood I highly suggest this book. Easily one of the most interesting technical books I have read in a long time. If you are tasked with solving search relevance problems even if not in Solr or Elasticsearch it should be your first reference. Amazon Affiliate Link
http://github.com/AF83/ucengine
Erlang | 97 lines | 65 code | 14 blank | 18 comment | 0 complexity | e40fa2a8385ed0883d6afa995c176fe8 MD5 | raw file
 1%%
 2%%  U.C.Engine - Unified Collaboration Engine
 3%%  Copyright (C) 2011 af83
 4%%
 5%%  This program is free software: you can redistribute it and/or modify
 6%%  it under the terms of the GNU Affero General Public License as published by
 7%%  the Free Software Foundation, either version 3 of the License, or
 8%%  (at your option) any later version.
 9%%
10%%  This program is distributed in the hope that it will be useful,
11%%  but WITHOUT ANY WARRANTY; without even the implied warranty of
12%%  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13%%  GNU Affero General Public License for more details.
14%%
15%%  You should have received a copy of the GNU Affero General Public License
16%%  along with this program.  If not, see <http://www.gnu.org/licenses/>.
17%%
18-module(ucengine_app).
19
20-behaviour(application).
21
22-export([start/0]).
23
24%% application callback
25-export([start/2, stop/1]).
26
27-include("uce.hrl").
28
29start() ->
30    application:start(ucengine).
31
32start(_, _) ->
33    start_apps([sasl, crypto, metrics, gproc, ibrowse]),
34    mnesia:create_schema([node()|nodes()]),
35    application:start(mnesia, permanent),
36    error_logger:tty(false),
37
38    Arguments = init:get_arguments(),
39    [[ConfigurationPath]] = utils:get(Arguments, [c], [["etc/uce.cfg"]]),
40    ok = config:init(ConfigurationPath),
41    case uce_sup:start_link() of
42        {ok, Pid} ->
43            setup(),
44            {ok, Pid};
45        Error ->
46            {error, Error}
47    end.
48
49start_apps([]) ->
50    ok;
51start_apps([App|Apps]) ->
52    case application:start(App) of
53        ok ->
54            ok;
55        {error, {already_started, App}} ->
56            ok;
57        Error ->
58            io:format("error ~p~n", [Error])
59    end,
60    start_apps(Apps).
61
62setup() ->
63    save_pid(),
64    setup_search(),
65    setup_routes(),
66    ok.
67
68stop(State) ->
69    remove_pid(),
70    State.
71
72setup_search() ->
73    case config:get(search) of
74        solr ->
75            ChildSpec = {uce_solr_commiter,
76                         {uce_solr_commiter, start_link, []},
77                         permanent, brutal_kill, worker, [uce_solr_commiter]},
78            {ok, _Pid} = uce_sup:start_child(ChildSpec);
79        _ ->
80            []
81    end.
82
83setup_routes() ->
84    routes:init().
85
86save_pid() ->
87    Pid = os:getpid(),
88    PidFile = config:get(pidfile),
89    {ok, PidFileId} = file:open(PidFile, [read, write]),
90    io:fwrite(PidFileId, "~s", [Pid]),
91    file:close(PidFileId),
92    ok.
93
94remove_pid() ->
95    PidFile = config:get(pidfile),
96    file:delete(PidFile),
97    ok.