Closed nozomione closed 1 year ago
I think this is moving in the right direction. Three comments for now:
search
query param for free text search and should have a fallback to redirect q
params to search
/ this could probably in the context of the search page for nowempty
num_downloadable_samplesgt: query.num_donloadable_samplesgt ? || 0
We will want to move to using the
search
query param for free text search and should have a fallback to redirectq
params tosearch
/ this could probably in the context of the search page for now
Currently(in refinebio-web, PRs created for the search terms), the key name search
is used for free text search as we briefly chatted to replace q
that is used in current refinebio.
I think we should move away from supporting the aliased
empty
Please take a look at the updated num_downloadable_samples__gt
description. This query string empty
is necessary to maintain the user-requested query. For instance, if users filtered the desired search results with non downloadable samples to bookmark the URL for future reference or to share with colleges, this query string enables them to do so (the same logic applies to limit
, offset
, ordering
- also updated the descriptions). Perhaps, we could use more descriptive key names or if there is a better approach to achieving this, that would be great π‘
Filters will be arrays of values, so toggling them should clone the array and either add or remove the value to that array
Please take a look at the updated filters
description. It's an object that contains nested object(s). The key of each object is one of the supported filter options and its value as an array of selected items (using the datatype object, since it prevents duplicate keys and easy to search π for specific filter options to add / remove items). And yes, those items are added or removed from filters
accordingly based on a user's selection (by checking / unchecking the checkbox β
in UI).
π @davidsmejia I updated the description for num_downloadable_samples__gt
and now rather than removing it, it uses the value "-1" to include the non-downloadable samples in API results. I also included the mobile solution (for toggleFilter
) and added a new method navigateToSearch
.
π @davidsmejia I updated the implementation so that it no longer uses the filters
state and any selected filters will be directly added to the search
state. The filterList
( for the available filter options that was defined in config/options) was also removed and now the config
state is used to store all the available filter options fetched from the latest API request.
Context
As with the existing refine.bio, when users perform searches within our application, we want to be able to manage their specified queries and provides accurate search results.
Problem or idea
Using the context API, we'll create a search manager context
SearchManagerContext
and implement its hookuseSearchManager
which includes methods that allow us to interact with the search query object and to update search results.The general strategy should be to have a single context that;
This context and its hook should manage the following:
Each exposed method of this manager should correspond to the behavior of the application and indirectly communicates with the API using the refinebio-js helper.
The implementation details and pseudocode is as follows:
❚ API Supported Query Parameters
(keys marked with * are required):
Common
limit*
offset*
ordering*
_score
(by default),-num_downloadable_samples
,num_downloadable_samples
,-soiurce_first_published
, andsource_first_published
. On the client side, the query string 'ordering=ORDER' (the currently specified sort order) will be appended to the browser's URL to preserve the sort order when refetching API results only if ORDER is not the default option.num_downloadable_samples__gt*
Filter options
downloadable_organism
platform
technology
has_publication
Search terms
search
Supported prefix:
These are prefixes for returning explicit search results for a specific category.
accession_code
e.g.) Search for "GSE116436"
A query string appended to the browse's URL:
?search=GSE116436
A query send to API:
(1st call)
?search=GSE116436&limit=10&offset=0&ordering=_score&num_downloadable_samples__gt=0
(2nd call)
?search=accession_code:GSE24528&search=alternate_accession_code:GSE24528
alternate_accession_code
description
platform_names
publication_authors
publication_doi
publication_title
pubmed_id
sample_keywords
sample_metadata_fields
submitter_institution
title
❚ State Management
Context State
The
SearchManagerContext
contains the following states that are shared across the application.config
: (an object) the latest data retrieved from the API (e.g, available facet names)setConfig
: an async method for settingconfig
search
: (an object) the currently defined search query objectsetSearch
: an async method for settingsearch
Local State
The following states are local to the search page component and are required to build the search results pagination, the sort order select menu, the page size select menu, and the common query parameters.
page
: (number) the currently selected page (1 by default)setPage
: an async method for settingpage
pageSize
: (number) the currently selected predefined page limit (10 by default)setPageSize
: an async method for settingpageSize
sortBy
: (string) the currently selected predefined sort order (_score
by default)setSortBy
: an async method for settingsortBy
❚ Method
The
useSearchManager
hook contains the helper methods that are necessary to perform searches and maintain the accuracy of the results. These methods are primarily called in the UI and each one corresponds to a specific application behavior.(Parameters marked with * are required).
Common
resetPage() return void
resets the current page number to the default valueupdatePage(newPage*) return void
p
with the given valueupdateSearchQuery
updatePageSize(newPageSize*) return void
size
with the given optionupdateSearchQuery
updateSortBy(newSortOrder*) return void
ordering
with the given valueupdateSearchQuery
Filters
clearAllFilters() return void
updateSearchQuery
hasAppliedFilters() return boolean
returns true if any currently applied filters, otherwise falseisFilterChecked(key*, value*) return boolean
returns true if the filter is selected, otherwise falsetoggleFilter(checked*, key*, val*, updateQuery = true) return void
updateSearchQuery
ifupdateQuery
is set to trueSearch Terms
updateSearchTerm(newTerm*) return void
search
with the given valueupdateSearchQuery
Other
formatFacetNames(facetNames*) return string[]
getSearchQueryParam(queryParams*) return object
returns client-only query parameters from URLnavigateToSearch(newQuery*) return void
handles search requests from non-search page and navigates a user to the search pageupdateSearchQuery(reset = false) return void
reset
is set to true, it resets the current page number to the default valueNOTE: The API requests are made in the search page component's
getInitialProps
using the application'sfetchSearch
helper which calls the refinebio-js helper'sget
method.Example:
Solution or next step
Based on the above requirements, implement the manager and its hook.