Skip to content

Commit

Permalink
fix: make search fields an array of string
Browse files Browse the repository at this point in the history
  • Loading branch information
naqvis committed Jul 3, 2024
1 parent a6ddc87 commit 4410753
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/placeos-rest-api/controllers/application.cr
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ module PlaceOS::Api

getter! search_params : Hash(String, String | Array(String))

@[AC::Route::Filter(:before_action, only: [:index])]
@[AC::Route::Filter(:before_action, only: [:index], converters: {fields: ConvertStringArray})]
def build_search_params(
@[AC::Param::Info(name: "q", description: "returns results based on a [simple query string](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-simple-query-string-query.html)")]
query : String = "*",
Expand All @@ -89,16 +89,17 @@ module PlaceOS::Api
@[AC::Param::Info(description: "a token for accessing the next page of results, provided in the `Link` header")]
ref : String? = nil,
@[AC::Param::Info(description: "(Optional, comma separated array of strings) Array of fields you wish to search. Accepts wildcard expresssions and boost relevance score for matches for particular field using a caret ^ operator.")]
fields : String? = nil
fields : Array(String)? = nil
)
search_params = {
"q" => query,
"limit" => limit.to_s,
"offset" => offset.to_s,
"fields" => fields.try &.split(",") || [] of String,
"fields" => fields || [] of String,
}
search_params["ref"] = ref.not_nil! if ref.presence
@search_params = search_params
p! search_params
end

# Callbacks
Expand Down

0 comments on commit 4410753

Please sign in to comment.