Skip to content

Commit

Permalink
split search into words and join with OR for better results
Browse files Browse the repository at this point in the history
  • Loading branch information
beerriot committed Oct 5, 2010
1 parent dc33fd9 commit b4889a7
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions apps/wriaki/src/wiki_resource.erl
Expand Up @@ -262,12 +262,11 @@ render_404(RD, Ctx) ->
search(Client, RawSearch) ->
case wriaki:search_enabled() of
true ->
Search = sanitize_search(RawSearch),
Search = split_search(sanitize_search(RawSearch)),
{ok, RawResults} =
wrc:mapred(Client,
{modfun, riak_search, mapred_search,
[<<"article">>,
iolist_to_binary([<<"text:">>, Search])]},
[<<"article">>, iolist_to_binary(Search)]},
[{map, {jsanon, ?SEARCH_FUN}, <<>>, true}]),
case RawResults of
[{0, RawKeys}] ->
Expand All @@ -280,6 +279,10 @@ search(Client, RawSearch) ->
[]
end.

split_search(Search) ->
Tokens = string:tokens(Search, " "),
string:join([ [<<"text:">>, T] || T <- Tokens ], " OR ").

sanitize_search(RawSearch) ->
[ whitespace_search_operator(C) || C <- RawSearch ].

Expand Down

0 comments on commit b4889a7

Please sign in to comment.