Permalink
Browse files

split search into words and join with OR for better results

  • Loading branch information...
1 parent dc33fd9 commit b4889a7d9f778424d2210ab6be33577e4bd53264 Bryan Fink committed Oct 5, 2010
Showing with 6 additions and 3 deletions.
  1. +6 −3 apps/wriaki/src/wiki_resource.erl
@@ -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}] ->
@@ -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 ].

0 comments on commit b4889a7

Please sign in to comment.