Skip to content

Commit

Permalink
feat: PPT-1396 Add search fields options to index endpoints (#387)
Browse files Browse the repository at this point in the history
* feat: PPT-1396 Add search fields options to index endpoints

* fix: make search fields an array of string

* fix: changes as suggested in review
  • Loading branch information
naqvis authored Jul 3, 2024
1 parent 35f098b commit ef829c7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion shard.lock
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ shards:

neuroplastic:
git: https://github.com/spider-gazelle/neuroplastic.git
version: 1.13.0
version: 1.13.1

office365:
git: https://github.com/placeos/office365.git
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/users_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module PlaceOS::Api
model.persisted?.should be_true
id = model.id.as(String)

params = HTTP::Params.encode({"q" => model.email.to_s})
params = HTTP::Params.encode({"q" => model.email.to_s, "fields" => "email,"})
path = "#{Users.base_route}?#{params}"

sleep 2
Expand Down
9 changes: 6 additions & 3 deletions src/placeos-rest-api/controllers/application.cr
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ module PlaceOS::Api
response.headers["Content-Range"] = "#{content_type} 0-#{size - 1}/#{size}"
end

getter! search_params : Hash(String, String)
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 @@ -87,12 +87,15 @@ module PlaceOS::Api
@[AC::Param::Info(description: "deprecated, the starting offset of the result set. Used to implement pagination")]
offset : UInt32 = 0_u32,
@[AC::Param::Info(description: "a token for accessing the next page of results, provided in the `Link` header")]
ref : String? = nil
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 : Array(String) = [] of String
)
search_params = {
"q" => query,
"limit" => limit.to_s,
"offset" => offset.to_s,
"fields" => fields,
}
search_params["ref"] = ref.not_nil! if ref.presence
@search_params = search_params
Expand Down

0 comments on commit ef829c7

Please sign in to comment.