1. Basho
  2. Untitled project
  3. wriaki

Commits

Bryan Fink  committed 18824ff

split search into words and join with OR for better results

  • Participants
  • Parent commits 38d2733
  • Branches default

Comments (0)

Files changed (1)

File apps/wriaki/src/wiki_resource.erl

View file
 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}] ->
             []
     end.
 
+split_search(Search) ->
+    Tokens = string:tokens(Search, " "),
+    string:join([ [<<"text:">>, T] || T <- Tokens ], " OR ").
+
 sanitize_search(RawSearch) ->
     [ whitespace_search_operator(C) || C <- RawSearch ].