/
elib1_indexer_results.erl
42 lines (36 loc) · 1.04 KB
/
elib1_indexer_results.erl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
%% Copyright (c) 2006-2009 Joe Armstrong
%% See MIT-LICENSE for licensing information.
-module(elib1_indexer_results).
-compile(export_all).
-import(elib1_misc, [time_fun/2]).
test() ->
q(medium, "hypot lists").
q(Name, Str) ->
time_fun("query",
fun() ->
Dets = atom_to_list(Name) ++ ".index",
{ok, result} = dets:open_file(result, {file,Dets}),
Words = string:tokens(Str, " "),
L1 = [q1(I) || I <- Words],
L2 = intersection(L1),
FileNames = [filename(I) || I <- L2],
dets:close(result),
io:format("~p~n",[FileNames])
end).
intersection(L) ->
sets:to_list(sets:intersection([sets:from_list(I) || I <- L])).
filename(I) ->
case dets:lookup(result, I) of
[] -> error;
[{I,X}] -> X
end.
q1(Str) ->
%% io:format("lookup:~p~n",[Str]),
Bin1 = list_to_binary(elib1_porter:stem(Str)),
L = case dets:lookup(result, Bin1) of
[] -> [];
[{_,Bin2}] ->
elib1_gamma:gamma_to_alist(Bin2)
end,
io:format("~s : ~p hits~n",[Str, length(L)]),
L.