Skip to content

Instantly share code, notes, and snippets.

add_facet(Id, "Tags", AttributeValue) ->
{match, Captured} = re:run(AttributeValue, "<(.*?)>", [global, {capture, all_but_first, list}]),
lists:foreach( fun(Match) -> facet_ser:add_facet_value( "Tags", Match, Id) end, Captured);
add_facet(Id, "CreationDate", AttributeValue) ->
[ Date | _Time ] = string:tokens(AttributeValue, "T"),
facet_ser:add_facet_value("CreationDate", Date, Id);
add_facet(_,_,_) ->
ignore.
do_async_query(Terms, FacetCategories, Mod, Fun, Ref) ->
gen_server:cast(
?SERVER,
{ get_results, Terms, FacetCategories, Mod, Fun, Ref }
).
handle_cast({ get_results, Terms, FacetCategories, Mod, Fun, Ref }, State) ->
TermResults = keyword_ser:do_query(Terms),
{DocumentIds, Scores} = lists:unzip(TermResults),
Documents = gen_server:call(document_ser, {get_documents, DocumentIds}),
erlang:apply( Mod, Fun, [{docs, lists:zip(Scores, Documents) }, Ref]),
FacetResults = lists:map(
fun(Category) ->
{ Category, facet_ser:get_facets(Category, DocumentIds)}
end,
FacetCategories
term_document_score(NumberOfTimesTermAppearsInDocument, NumberOfDocumentsWithTerm, AverageDocumentLength, TotalNumberOfDocuments) ->
TermFrequency = term_frequency( NumberOfTimesTermAppearsInDocument, AverageDocumentLength),
Idf = important_document_frequency_of_term( TotalNumberOfDocuments, NumberOfDocumentsWithTerm ),
TermFrequency * Idf.
handle_websocket(Ws) ->
receive
{browser, Data} ->
Ws:send(["performing query'", Data, "'"]),
query_ser:do_async_query(
string:tokens(Data, " "),
["Tags", "CreationDate"],
?MODULE,
query_results,
[Ws]
query_results({docs, Documents}, [Ws]) ->
%% create a nice list of results with scores.
Ws:send(["got doc results"]),
Partial = "<li><strong>Id:</strong> ~p<br />
<strong>Score:</strong> ~p<br />
<strong>Title:</strong> ~ts<br />
<strong>Body:</strong> ~ts</li>",
Html = lists:map(
fun({Score, Attributes}) ->
io_lib:format(
query_results({facet_results, [{"Tags", Tags}, {"CreationDate", _CreationDate}]}, [Ws]) ->
Html = lists:map(
fun({[Tag], Count}) ->
io_lib:format(
"<li>~ts ( ~p ) </li>",
[Tag, Count]
)
end,
Tags
),
-module(user_default).
-author('[email protected]').
%% Compile this file and use this line in your ~/.erlang file (with
%% correct path, of course!) to where the user_default.beam file is stored.
%%
%% code:load_abs("/home/fritchie/erlang/user_default").
-export([help/0,dbgtc/1, dbgon/1, dbgon/2,
dbgadd/1, dbgadd/2, dbgdel/1, dbgdel/2, dbgoff/0,
@wardbekker
wardbekker / .emacs
Created March 13, 2012 07:47
highlight lines with trailing spaces, lines longer than 80 chars and tabs
;; taken from http://www.emacswiki.org/emacs/EightyColumnRule by http://www.emacswiki.org/emacs/TimOCallaghan
(custom-set-faces
'(my-tab-face ((((class color)) (:background "grey10"))) t)
'(my-trailing-space-face ((((class color)) (:background "gray10"))) t)
'(my-long-line-face ((((class color)) (:background "gray10"))) t))
(add-hook 'font-lock-mode-hook
(function
(lambda ()
(setq font-lock-keywords
@wardbekker
wardbekker / compression.md
Created May 1, 2012 19:03
D-GAP and elias Gamma coding combination lib