Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework static filters #201

Merged
merged 4 commits into from Aug 11, 2022
Merged

Rework static filters #201

merged 4 commits into from Aug 11, 2022

Conversation

nmanu1
Copy link
Collaborator

@nmanu1 nmanu1 commented Aug 11, 2022

This PR reworks static filters to provide a better developer experience. A new StaticFilters model is added that replaces the existing CombinedFilter. Filter is renamed to FieldValueFilter in order to more accurately describe what the object represents. Now static filters can be either a field value filter or a nested object that is composed by combining field value filters. Also, I added Jest tests for some edge cases when serializing static filters.

J=SLAP-2325
TEST=auto, manual

See that the new and existing Jest tests pass. Spin up the test-site and see that requests can be successfully fired when specifying simple or nested static filters and the correct response is received.

@nmanu1 nmanu1 requested a review from a team as a code owner August 11, 2022 15:57
@coveralls
Copy link

coveralls commented Aug 11, 2022

Pull Request Test Coverage Report for Build 2842092570

  • 13 of 13 (100.0%) changed or added relevant lines in 3 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.4%) to 90.244%

Totals Coverage Status
Change from base Build 2804161214: 0.4%
Covered Lines: 213
Relevant Lines: 230

💛 - Coveralls

@@ -39,7 +38,7 @@ export interface VerticalSearchRequest extends SearchRequest {
/** Enables session tracking. */
sessionTrackingEnabled?: boolean,
/** The static filters to apply to the search. */
staticFilters?: CombinedFilter | Filter,
staticFilters?: StaticFilter,
Copy link
Contributor

Choose a reason for hiding this comment

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

This feels a bit odd, the attribute name is plural, but we only allow a singular value.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I agree, this looks a little weird. Although, this was the case before also where we accepted a single value (either a Filter or a CombinedFilter) for the plural staticFilters. It was just slightly obscured because of the union type.
Would it make sense to rename the attribute to staticFilter? Because that's what the user is giving us; it's just that they can combine a bunch of field value filters together if they want to in their one static filter

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, renaming to static filter sounds good!

src/models/searchservice/request/StaticFilter.ts Outdated Show resolved Hide resolved
src/serializers/serializeStaticFilters.ts Outdated Show resolved Hide resolved
src/serializers/serializeStaticFilters.ts Show resolved Hide resolved
@oshi97
Copy link
Contributor

oshi97 commented Aug 11, 2022

Are the main changes

  1. a kind discriminator for filters, either fieldValue or combination
  2. renaming associated with the above

?

@nmanu1
Copy link
Collaborator Author

nmanu1 commented Aug 11, 2022

Are the main changes

  1. a kind discriminator for filters, either fieldValue or combination
  2. renaming associated with the above

?

yes, the main things we wanted were

  1. a single interface for static filters instead of having it explicitly split up into 2 types based on how we represent them for the API
  2. the kind discriminator to make type checking easier for consumers of the Headless static filters state
  3. renaming Filter to FieldValueFilter to make it more clear, because facets and static filters are filters too
  4. and then the renaming associated with the above changes

Copy link
Contributor

@oshi97 oshi97 left a comment

Choose a reason for hiding this comment

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

this lgtm! not sure if other people have gotten to take a look

@nmanu1 nmanu1 merged commit facc939 into develop Aug 11, 2022
@nmanu1 nmanu1 deleted the dev/static-filters-rework branch August 11, 2022 18:56
@yen-tt yen-tt mentioned this pull request Sep 6, 2022
yen-tt added a commit that referenced this pull request Sep 8, 2022
## Version 2.0.0

### Changes
- `additionalQueryParameter` is now a public field in `SearchConfig` models (#217)

### Breaking Changes
- Updated default and sandbox URL endpoints from `../answers/..` to `../search/..` as part of rebranding process (#196 )
- Restructured StaticFilters models for better developer experience and enforce proper restriction in the kind of combinations of filters supported by the backend
  - Now, static filters can be either a field value filter or a nested object that is composed by combining field value filters. (#201 )
  - `ConjunctionStaticFilter` and `DisjunctionStaticFilter` models were created to reflect such limitation. For example, ANDs of ORs combination is allowed, ORs of ANDs combination is not allowed.  (#204 )
- Updated `FieldValueDirectAnswer` model to properly handle different `value` types. Previously, FieldValueDirectAnswer interface enforces that the `value` field will always be of type `string`. Now, `FieldValueDirectAnswer` is a union type of predefined interfaces with known `value` type and `UnknownFieldValueDirectAnswer` with a generic `value` type for other `fieldType` outside of `BuiltInFieldType`. (#200 #202 )
   - The newly added built-in interfaces can be found in the document page [**here**](https://github.com/yext/search-core/blob/develop/docs/search-core.fieldvaluedirectanswer.md)  (#206 #208 #210 #211 #205 #209 #203 #220 )
- Narrow down `FeaturedSnippetDirectAnswer` TypeScript model to be a union type of   `MultiLineTextSnippetDirectAnswer` and `RichTextSnippetDirectAnswer` as a featured snippet direct answer can only be of fieldType `multi_line_text` or `rich_text`. (#207 #212 )
- All exports marked as `@deprecated` in previous version(s) as part of the rebranding process is now removed in V2 (#216 )
  - For more details, the deprecated identifiers are listed in [v1.8 release notes](https://github.com/yext/search-core/releases/tag/v1.8.0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants