anchor.diff:  %% @end
   -spec get_search(ReqData::tuple(), State::string()) -> {string(), tuple(), string()}.
   get_search(ReqData, State) ->
  -    case api_help:is_search(ReqData) of
  -        false -> 
  -            case wrq:get_qs_value("size",ReqData) of 
  -                    undefined ->
  -                        NrValues = 25;
  -                    Values ->
  -                        {NrValues, _} = string:to_integer(Values)
  -            end,
  -            case wrq:get_qs_value("stream_id",ReqData) of 
  -                    undefined ->
  -                        ErrorString = api_help:generate_error(<<"Invalid stream_id">>, 405),
  -                        {{halt, 405}, wrq:set_resp_body(ErrorString, ReqData), State};
  -                    StreamIds ->
  -                        IdList = string:tokens(StreamIds, ","),
  -                        {get_history(IdList, NrValues, "{\"history\":[]}"), ReqData, State}
  -            end;
  -        true ->
  -            {{halt, 501}, wrq:set_resp_body("Please use POST search instead.", ReqData), State}
  +    case openidc:auth_request(ReqData) of
  +        {error, Status, Msg} -> {{halt, Status}, wrq:set_resp_body(Msg, ReqData), State};
  +        {ok, _} ->
  +            case api_help:is_search(ReqData) of
  +                false ->
  +                    case wrq:get_qs_value("size",ReqData) of
  +                            undefined ->
  +                                NrValues = 25;
  +                            Values ->
  +                                {NrValues, _} = string:to_integer(Values)
  +                    end,
  +                    case wrq:get_qs_value("stream_id",ReqData) of
  +                            undefined ->
  +                                ErrorString = api_help:generate_error(<<"Invalid stream_id">>, 405),
  +                                {{halt, 405}, wrq:set_resp_body(ErrorString, ReqData), State};
  +                            StreamIds ->
  +                                IdList = string:tokens(StreamIds, ","),
  +                                {get_history(IdList, NrValues, "{\"history\":[]}"), ReqData, State}
  +                    end;
  +                true ->
  +                    {{halt, 501}, wrq:set_resp_body("Please use POST search instead.", ReqData), State}
  +            end
       end.
   
   %% @doc
  
positive.code: 	",\"query\" : {\"filtered\" : "++NewJson++
  	",\"filter\" : {\"bool\" : {\"must_not\" : {\"term\" : {\"private\" : \"true\"}}}}}}}";
  filter_json(Json, From, Size, Sort, true) ->
      case lib_json:get_field(Json, "sort") of 
          undefined -> 
              UseSort = "\"" ++ Sort ++ "\"", 
              SortJson = Json;
          SortValue when is_binary(SortValue) -> 
              UseSort = "\"" ++ binary_to_list(SortValue) ++ "\"",
              SortJson = lib_json:rm_field(Json, "sort");
          SortValue -> 
              UseSort = SortValue,
              SortJson = lib_json:rm_field(Json, "sort")
      end,
  
negative.code: %% @end
  -spec process_post(ReqData::tuple(), State::string()) -> {true, tuple(), string()}.
  process_post(ReqData, State) ->
      case openidc:auth_request(ReqData) of
          {error, Status, Msg} -> {{halt, Status}, wrq:set_resp_body(Msg, ReqData), State};
          {ok, _} ->
              erlang:display("search with json request"),
              case wrq:get_qs_value("size",ReqData) of
                  undefined ->
                      Size = "10";
                  SizeParam ->
                      Size = SizeParam
              end,
          	case wrq:get_qs_value("sort",ReqData) of
                  undefined ->
                      Sort = "user_ranking.average";
                  SortParam ->
                      Sort = SortParam
              end,
              case wrq:get_qs_value("from",ReqData) of
                  undefined ->
                      From = "0";
                  FromParam ->
                      From = FromParam
              end,
              case wrq:get_qs_value("location",ReqData) of
                  undefined ->
                      LocationParam = false;
                  "true" ->
                      LocationParam = true;
                  _ ->
                      LocationParam = false
              end,
              {Json,_,_} = api_help:json_handler(ReqData,State),
              FilteredJson = filter_json(Json, From, Size, Sort, LocationParam),
              case erlastic_search:search_json(#erls_params{},?INDEX, "stream", FilteredJson) of % Maybe wanna take more
                      {error, Reason1} ->
                          StreamSearch = {error, Reason1};
                      {ok,List1} ->
          			case lib_json:get_field(FilteredJson, "query.filtered.query.query_string.query") of
          				undefined ->
          					erlang:display("No query string text, cannot add a suggestion.");
          				QueryString ->
                              add_query_suggestion(QueryString)
          			end,
          			StreamSearch = lib_json:encode(List1) % May need to convert
              end,
              FilteredJson2 = filter_json(Json, From, Size, Sort, false),
              case erlastic_search:search_json(#erls_params{},?INDEX, "virtual_stream", lib_json:rm_field(FilteredJson2, "sort")) of % Maybe wanna take more
                      {error, Reason2} ->
                          VStreamSearch = {error, Reason2};
                      {ok,List2} ->
                          VStreamSearch = lib_json:encode(List2) % May need to convert
              end,
              case erlastic_search:search_json(#erls_params{},?INDEX, "user", lib_json:rm_field(FilteredJson2, "sort")) of % Maybe wanna take more
                      {error, Reason3} ->
                              UserSearch = {error, Reason3};
                      {ok,List3} ->
              			UserSearch = lib_json:encode(List3) % May need to convert
               end,
          	% check search-results for error
              case {StreamSearch, VStreamSearch, UserSearch} of
                  {{error, {Body, Code}},_,_} ->
                      ErrorString = api_help:generate_error(Body, Code),
                      {{halt, Code}, wrq:set_resp_body(ErrorString, ReqData), State};
                  {_,{error, {Body2, Code2}},_} ->
                      ErrorString = api_help:generate_error(Body2, Code2),
                      {{halt, Code2}, wrq:set_resp_body(ErrorString, ReqData), State};
                  {_,_,{error, {Body3, Code3}}} ->
                      ErrorString = api_help:generate_error(Body3, Code3),
                      {{halt, Code3}, wrq:set_resp_body(ErrorString, ReqData), State};
                  _ ->
                      SearchResults = "{\"streams\":"++ StreamSearch ++",\"vstreams\":"++ VStreamSearch ++",\"users\":"++ UserSearch ++"}",
                      {true,wrq:set_resp_body(SearchResults,ReqData),State}
              end
      end.
  
  
  %% @doc
  