build date index at startup

This commit is contained in:
Kevin Lynx 2013-08-06 20:50:49 +08:00
parent 648fe7f20d
commit ba64278d12
2 changed files with 5 additions and 2 deletions

View File

@ -32,6 +32,7 @@ init(Host, Port) ->
Conn.
init(Conn) ->
ensure_date_index(Conn),
case config:get(search_method, mongodb) of
mongodb ->
io:format("use mongod text search~n", []),
@ -163,10 +164,12 @@ ensure_search_index(Conn) ->
end).
ensure_date_index(Conn) ->
io:format("ensuring date index...", []),
Spec = {key, {created_at, 1}},
mongo_do(Conn, fun() ->
mongo:ensure_index(?COLLNAME, Spec)
end).
end),
io:format("done~n", []).
% not work
enable_text_search(Conn) ->

View File

@ -114,7 +114,7 @@ search_by_sphinx(Keyword, Page) ->
{TotalFound, CostTime, DBTime} = Stats,
US = http_common:list_to_utf_binary(Keyword),
?LOG_STR(?INFO, ?FMT("search /~s/ found ~p, cost ~b sp ms, ~b db ms",
[US, length(Rets), CostTime, DBTime])),
[US, TotalFound, CostTime, DBTime / 1000])),
Tip = ?TEXT("<h4>search ~s, ~b results, ~f seconds, db ~f seconds</h4>",
[Keyword, TotalFound, CostTime / 1000, DBTime / 1000 / 1000]),
BodyList = format_search_result(Rets),