Open jkuester opened 2 weeks ago
const getIdsPage = (context: DataContext) => (qualifier: ContactTypeQualifier | FreetextQualifier, cursor: Nullable
, limit: number) => Promise<Page >
@jkuester For the Contact's getIdsPage
API, for both cases when the qualifier is either ContactTypeQualifier
or FreetextQualifier
, is the goal to just search using Lucene's q
search parameter?
For now, I think you can just follow the existing logic in shared-libs/search
which calls through to either the medic-client/contacts_by_freetext
or the medic-client/contacts_by_type_freetext
view queries. (Unless I missed something and @m5r has the Lucene integration ready to go...)
Unfortunately, the shared-libs/search
logic flow is a bit disjointed and tricky to follow. Let me know if it would be helpful to go through it together. But, ultimately, the contact search logic should end up hitting one of these indexes
My goal here is to have these cht-datasource changes be decoupled from the other search efforts (at least for the time being). That way we can ship your work here without waiting on Lucene or offline views. If I am correct, it should not really be any extra work to wait and integrate the Lucene/offline stuff when it is actually ready to go....
I've pushed the skeleton code for this. Can you review if that's the pattern we're looking for?
@sugat009 Could you be a bit more specific about the pattern you would like me to review? 😅 In general, the code in your PR looks to be headed in a great direction!
I wanted you to review the latest commit for implementation of /api/v1/contact/id
API. The specific thing to be reviewed is the qualifier
value, which can be ContactTypeQualifier | FreetextQualifier
as per the description of this ticket. Those interfaces seem different from each other in terms of use cases and I was confused on whether to do a search based on both depending on what type of value is passed or do different stuff depending on type. Right now I've implemented the pagination-based search that we did on other entities like person and place which is just by passing the key
field with the value from the qualifier
as the value. This is somewhat based on the current shared-libs/search
implementation where the key
is set as the passed freetext search keyword. However, I did not implement the other part of implementation for now where the passed in freetext search keyword is being used as startkey
and endkey
.
The specific thing to be reviewed is the qualifier value, which can be ContactTypeQualifier | FreetextQualifier as per the description of this ticket. Those interfaces seem different from each other in terms of use cases and I was confused on whether to do a search based on both depending on what type of value is passed or do different stuff depending on type.
Basically, if the provided qualifier is both a ContactTypeQualifier
and a FreetextQualifier
we should hit the medic-client/contacts_by_type_freetext
index. If it is just a FreetextQualifier
we should hit the medic-client/contacts_by_freetext
index. If it is just a ContactTypeQualifier
we should just hit the medic-client/contacts_by_type
index.
Spinning this off into its own ticket (from https://github.com/medic/cht-core/issues/9544) since it can stand alone.
What feature do you want to improve? As a part of updating our freetext search implementation, we can take the opportunity to implement the search logic in cht-datasource. This will provide a more clean interface for cht-code code to perform searches of contacts and reports as well as resulting in the creation of new REST endpoints for the same searching.
Describe the improvement you'd like
shared-libs/cht-datasource
qualifier.ts
contact.ts
report.ts
person.ts/place.ts
Update the
Person/PlaceWithLineage
interfaces to useContactWithLineage
as theparent
(instead ofPlaceWithLineage
). Pending https://github.com/medic/cht-core/issues/9584 it is probably not safe to assume that a contact parent will always be a place.Need to do more research regarding the
Place.contact
value...shared-libs/search
Update search logic to call through to the cht-datasource functions when doing freetext searches (or the basic contact_by_type search). For the multi-view searches, we will need to just stream in all pages.
Design details
As mentioned here (https://github.com/medic/cht-core/issues/9544#issuecomment-2430462690) the local adapter will need to account for Nouveau logic (though depending on the progress of that implementation, this PR might just port the same online/offline logic from
shared-libs/search
that was created by https://github.com/medic/cht-core/issues/9544).In general we should strive to align to the patterns/code used for implementing the person/place-by-type flows in cht-datasource. All the paging logic should basically be the same.
Describe alternatives you've considered
Additional context