Open davidsmejia opened 1 year ago
Some ideas 💡 : https://restdb.io/docs/querying-with-the-api https://autotask.net/help/developerhelp/content/apis/rest/API_Calls/REST_Basic_Query_Calls.htm https://www.baeldung.com/openapi-json-query-parameters
URL Encoding the advanced options might be a good idea because we can "append" the advanced query on top of the existing url parameters that get converted to the elastic search dsl. We would also be able to add another parameter to the documentation.
I think it would be nice to look for existing modules or libraries to help convert the JSON object to the logic that modifies the Search
object.
Context
We want to add more advanced search features to Search API endpoint. Advanced features will allow API users to be able to construct nested logical operators in their queries. There will be some restrictions on the client side for how these are applied but I think we should try to solve a general solution to this problem.
Problem or idea
Currently we support basic text search and selected faceted search parameters / filters that can be applied to the result. Each faceted filter is treated as an "AND" logical operator and multiple values for the same facet are treated as joined with "OR" logical operators.
Ex: Given the following query:
search?organism=DANIO_RERIO&organism=HOMO_SAPIENS&technology=microarray
This will be interpreted as:technology=MICROARRAY AND (organism=DANIO_RERIO OR organism=HOMO_SAPIENS)
Now consider a user wants to look at
(DANIO_RERIO AND microarray) OR (HOMO_SAPIENS AND rna-seq)
This is not supported out of the box. However we do have access to the
Search
object available from thesearch_dsl
module and override the defaultself.search
in the Search endpoint controller.In order to support this feature we will want to be able to answer the following questions:
GET
request it is now and the new advanced queries arePOST
requests where the payload is a json object that contains a complex query?POST
request can we still encode the request in the url to keep search pages shareable?django_elasticsearch_dsl_drf
so we can encapsulate all of the behavior?Solution or next step
I am currently leaning toward the
POST
json request. It would be trivial to encode the request with the freedom that is allowed for by JSON.Something where we define the operator in the parent and the child contains either a non logical value or another logical value that is arbitrarily nestable. This doesn't solve how we would generate this (how to choose different but equal ways to group the same logical expression), but the simple and expressive pattern here is what I am hoping to accomplish.
Then we would convert this using the Search Query and logical operators... Ex from
elasticsearch-ds
Sources:
Next steps would be to discuss and discover more questions needed to start implementation and answer existing questions.
Inquiries and comments are welcome below.