Skip to content

Instantly share code, notes, and snippets.

@wardbekker
Created September 9, 2011 11:48
Show Gist options
  • Save wardbekker/1206014 to your computer and use it in GitHub Desktop.
Save wardbekker/1206014 to your computer and use it in GitHub Desktop.
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(
Partial,
[dict:fetch("Id", Attributes),
Score,
dict:fetch("Title", Attributes),
dict:fetch("Body", Attributes)
])
end,
Documents
),
Output = io_lib:format("<p><ol>~ts</ol></p>", [lists:append(Html)]),
Ws:send(["documents:", unicode:characters_to_binary(Output)]),
ok;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment