add sphinx search stats

This commit is contained in:
Kevin Lynx 2013-07-31 22:06:18 +08:00
parent 1d27f2416b
commit 1d870e2e42
2 changed files with 14 additions and 6 deletions

View File

@ -116,11 +116,14 @@ do_search(Keyword) ->
Tip ++ Body.
do_search_sphinx(Keyword, Page) ->
Rets = db_frontend:search_by_sphinx(Keyword, Page, ?COUNT_PER_PAGE + 1),
{Stats, Rets} = db_frontend:search_by_sphinx(Keyword, Page, ?COUNT_PER_PAGE + 1),
{SphinxTime, DBTime} = Stats,
ThisPage = lists:sublist(Rets, ?COUNT_PER_PAGE),
StatsDesc = ?TEXT("<h4>search ~s, sphinx ~f ms, db ~f ms</h4>",
[Keyword, SphinxTime / 1000, DBTime / 1000]),
BodyList = format_search_result(ThisPage),
Body = ?TEXT("<ol>~s</ol>", [lists:flatten(BodyList)]),
Body ++ append_page_nav(Keyword, Page, Rets).
StatsDesc ++ Body ++ append_page_nav(Keyword, Page, Rets).
append_page_nav(Key, Page, ThisRet) ->
Nav = case length(ThisRet) of
@ -131,7 +134,7 @@ append_page_nav(Key, Page, ThisRet) ->
Size when Page > 0 ->
format_page_nav(Key, Page - 1, "Prev") ++
if Size > ?COUNT_PER_PAGE ->
"|" ++ format_page_nav(Key, Page + 1, "Next");
"&nbsp;" ++ format_page_nav(Key, Page + 1, "Next");
true -> []
end;
Size ->

View File

@ -14,13 +14,18 @@ search(Conn, Key, Offset, Count) ->
Q2 = giza_query:port(Q1, ?PORT),
Q3 = giza_query:offset(Q2, Offset),
Q4 = giza_query:limit(Q3, Count),
case catch giza_request:send(Q4) of
T1 = now(),
{T2, TDocs} = case catch giza_request:send(Q4) of
{'EXIT', R} ->
?W(?FMT("sphinx search error ~p", [R])),
[];
{ok, Ret} ->
decode_search_ret(Conn, Ret)
end.
T = now(),
{T, decode_search_ret(Conn, Ret)}
end,
T3 = now(),
Stats = {timer:now_diff(T2, T1), timer:now_diff(T3, T2)},
{Stats, TDocs}.
decode_search_ret(Conn, Ret) ->
Hashes = [translate_hash(Item) || Item <- Ret],