Skip to content
This repository has been archived by the owner on Jun 26, 2023. It is now read-only.

optionally post-process results before displaying them #50

Merged
merged 3 commits into from
Jul 23, 2021

Conversation

alastair
Copy link
Member

As described in trompamusic/ce-api#187, we sometimes have searches where the items that we want are returned as child objects of the main query, for example:

query {
  ItemList(identifier:"e91489d7-a776-40dd-8abf-0c934922bd99") {
    identifier
    name
    itemListElement(filter:{name_regexp:"(?i).*missa.*"}) {
      identifier
      name
    }
  }
}

The items that we want are actually the MusicCompositions returned in itemListElement. This query cannot be done any other way because we don't have reverse relationships saying that an item is part of a list.

This change adds optional preprocessQuery and processSearchResult methods to search types so that we can do a query such as the one above, and then post-process the results and return a list of the expected objects.

There is still a bug, where I don't understand the reasoning behind performing two queries in SearchConfig.performSearch - first it runs searchType.searchAllQuery and then searchType.searchQuery. In the example that I made, the first result runs fine, but then the second one filters out everything, I'm sure I'm missing something simple in the data flow.

I see that some ordering code appears to assume that there is a _searchScore property in some returned items, which might also not be the case here.

@ChristiaanScheermeijer
Copy link
Contributor

Hi @alastair,

Thanks for the PR!

The reason that the multimodal component performs two queries is to be able to show all possible filters and facets.

The searchType.searchAllQuery query returns all matches based on the given search phrase. From the results, we can build lists for each configured filter. This query should be as light as possible and cannot contain concrete type properties since the return type is SearchableInterface.

The searchType.searchQuery query does the actual filtering based on the searchAllQuery results. This query is also used to get all the properties needed to populate the UI.

README.md Outdated
To start the example demo, run

```bash
npm run start:example
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
npm run start:example
yarn start:example

const { data: { results } } = await client.query({
query : searchType.searchQuery,
variables: {
filter: generateFilter(query, allResults, filtersState, this.filter),
filter: generateFilter(query, processedAllResults, filtersState, this.filter),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When processSearchResult is not defined, the generateFilter function won't receive allResults anymore. Doesn't this break the query without the processing functions?

@alastair
Copy link
Member Author

I just tested this against prod and it gives me the expected results, thanks!

@alastair
Copy link
Member Author

One additional thought about this - because the data that we're extracting is a child of the main returned object, will the automatic filter building work? (I didn't try it in my example). Hopefully it will correctly use the result of processSearchResult, is that right?

@alastair
Copy link
Member Author

@ChristiaanScheermeijer can we merge this and get a new release made?

@ChristiaanScheermeijer ChristiaanScheermeijer merged commit 77f3225 into master Jul 23, 2021
@ChristiaanScheermeijer ChristiaanScheermeijer deleted the feat/postprocess-results branch July 23, 2021 08:05
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants