anchor.diff:  %% @doc == Module for creating, updating and retrieving suggestions ==
   %% @end
   -module(suggest).
  --export([init/1, 
  -	allowed_methods/2, 
  -	content_types_provided/2, 
  -	get_suggestion/2, 
  +-export([init/1,
  +	allowed_methods/2,
  +	content_types_provided/2,
  +	get_suggestion/2,
   	add_suggestion/2,
   	update_suggestion/1,
   	update_stream/2,
  
positive.code: 	case Streams of
  		undefined ->
  			StreamWeight = 0;
  		_ -> 
  			Fun = fun(Stream, Acc) -> 
  					scoring:calc(Stream,stream)+Acc
  			end,
  			StreamWeight = lists:foldr(Fun, 0, Streams)
  
negative.code: %% @end
  -spec get_suggestion(ReqData::term(),State::term()) -> {boolean(), term(), term()}.
  get_suggestion(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 ->
  							Size = "1";
  						SizeParam ->
  							Size = SizeParam
  					end,
  					case proplists:get_value('field', wrq:path_info(ReqData)) of
  						undefined ->
  							Field = "suggest";
  						FieldParam ->
  							Field = FieldParam ++ "_suggest"
  					end,
  					case proplists:get_value('term', wrq:path_info(ReqData)) of
  						undefined ->
  							{{halt, 400}, ReqData, State};
  						Term ->
  							Query = "{
  									\"testsuggest\" : {
  										\"text\" : \""++http_uri:decode(Term)++"\",
  										\"completion\" : {
  										\"field\" : \""++Field++"\",
  												\"size\" : "++ Size ++"
  										}
  									}
  								}",
  							case erlastic_search:suggest(?INDEX, Query) of
  								{error, {Code, Body}} ->
  									ErrorString = api_help:generate_error(Body, Code),
  									{{halt, Code}, wrq:set_resp_body(ErrorString, ReqData), State};
  								{ok,List} ->
  									EncodedList = lib_json:encode(List),
  									case re:run(EncodedList, "\"options\":\\[\\]", [{capture, first, list}]) of
  										{match, _} ->
  											Output = lib_json:set_attr("suggestions",[]);
  										_->
  											Output = lib_json:set_attr("suggestions",lib_json:get_field(List, "testsuggest[0].options")),
  																			erlang:display(Output)
  
  									end,
  									{lib_json:encode(Output),ReqData, State}
  							end
  					end;
  				true ->
  					case wrq:get_qs_value("query",ReqData) of
  						undefined ->
  							erlang:display("No query specified!");
  						QueryString ->
  							SuggestJson = "{\"suggestion\":{\"text\":\""++ QueryString ++"\",\"completion\":{\"field\":\"search_suggest\",\"fuzzy\":true}}}",
  							case erlastic_search:suggest(?INDEX, SuggestJson) of
  								{error, {Code, Body}} ->
  									ErrorString = api_help:generate_error(Body, Code),
  									{{halt, Code}, wrq:set_resp_body(ErrorString, ReqData), State};
  								{ok,List} ->
  									OutputJson = lib_json:set_attr("suggestions",lib_json:get_field(List, "suggestion[0].options")),
  									{OutputJson ,ReqData ,State}
  							end
  					end
  			end
  	end.
  
  
  
  %% @doc
  %% Creates a suggestion using a resource. This new suggestion contains only the metadata from the resource
  %% like manufacturer, tags, polling_frequency. It is expected to be updated with information about the
  %% streams when new streams are created for that resource.
  %% @end
  -spec add_suggestion(Resource::json(), RsourceId::binary()) -> ok | {error, no_model}.
  add_suggestion(Resource, ResourceId) ->
  	Manufacturer = lib_json:get_field(Resource, "manufacturer"),
  	Model = lib_json:get_field(Resource, "model"),
  	Tags = lib_json:get_field(Resource, "tags"),
  	Polling_freq = lib_json:get_field(Resource, "polling_freq"),
  	Weight = scoring:calc(Resource, resource),
  	case Model of
  		undefined ->
  			{error, no_model};
  		_ ->
  