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

fix: Fuzzy & operator usage when handling Intelligent Search API requests #2204

Merged
merged 12 commits into from
Feb 2, 2024

Conversation

hellofanny
Copy link
Contributor

@hellofanny hellofanny commented Jan 24, 2024

What's the purpose of this pull request?

This PR aims to correct fuzzy and operator usage when handling Intelligent Search API requests.

Previously, we specified a default value for fuzzy fuzzy=auto. But we shouldn’t include it on the first request to Search. According to the IS team, the correct behavior should let the search engine decide the best parameters for the search.

How it works?

At the beginning of a search, requests should not define fuzzy and operator parameters. The request response will return the parameters selected for this search.

Example:


Request
https://storeframework.vtexcommercestable.com.br/api/io/_v/api/intelligent-search/facets/trade-policy/1?page=1&count=12&query=awe&sort=&locale=en-US&hideUnavailableItems=false

Response
recordsFiltered 792,

Then, we should apply these parameters when refining the search result; in our context, it should cover two cases:

  • Pagination 
  • Filters Usage (facets, sort)

Request
https://storeframework.vtexcommercestable.com.br/api/io/_v/api/intelligent-search/product_search/trade-policy/1?page=1&count=12&query=awe&sort=&locale=en-US&hideUnavailableItems=false&fuzzy=auto&operator=and

The implemented approach here involves passing the necessary parameters, in the form of facets, after the initial request and using their structure.

How to test it?

Use this preview link to test the following scenarios:

** scenario 1: Search Catergory**

  1. Click on office category
  2. Open the inspector -> Network tab, filter for ClientProductGalleryQuery
  3. In the preview tab, search for the metadata field in data
  4. The fuzzy and logicalOperator values should correspond to the values in the url, ex: ?category-1=office&fuzzy=0&operator=and&
image
  1. Try adding another filter and add a new page (Load More Products button), the parameters should persist.

** scenario 2: Search for a term**

  1. In the SearchInput type awe and enter
  2. Repeat the steps from the previous scenario (start at step 2).

Starters Deploy Preview

https://sfj-320f502--starter.preview.vtex.app/

References

Copy link

vercel bot commented Jan 24, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
faststore-site ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 2, 2024 3:25pm

Copy link

codesandbox-ci bot commented Jan 24, 2024

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 54da0df:

Sandbox Source
Store UI Typescript Configuration

@hellofanny hellofanny marked this pull request as ready for review January 24, 2024 13:53
@hellofanny hellofanny requested a review from a team as a code owner January 24, 2024 13:53
@hellofanny hellofanny requested review from gvc and lucasfp13 and removed request for a team January 24, 2024 13:53
@hellofanny hellofanny marked this pull request as draft January 24, 2024 13:54
@hellofanny hellofanny changed the title Fix: Fuzzy & operator usage when handling Intelligent Search API requests fix: Fuzzy & operator usage when handling Intelligent Search API requests Jan 24, 2024
@hellofanny hellofanny marked this pull request as ready for review January 24, 2024 14:18
Copy link
Member

@eduardoformiga eduardoformiga left a comment

Choose a reason for hiding this comment

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

Looks Good! I'll test it in practice before approval, but I left some comments so far.

packages/api/src/platforms/vtex/clients/search/index.ts Outdated Show resolved Hide resolved
packages/api/src/platforms/vtex/clients/search/index.ts Outdated Show resolved Hide resolved
packages/api/src/platforms/vtex/clients/search/index.ts Outdated Show resolved Hide resolved
packages/core/src/sdk/product/useProductGalleryQuery.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@lucasfp13 lucasfp13 left a comment

Choose a reason for hiding this comment

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

LGTM 🚀
But I'll wait for the reply here, it makes sense to me but idk if in fact it does 😬

packages/api/src/platforms/vtex/clients/search/index.ts Outdated Show resolved Hide resolved
packages/api/src/platforms/vtex/clients/search/index.ts Outdated Show resolved Hide resolved
packages/api/src/platforms/vtex/clients/search/index.ts Outdated Show resolved Hide resolved
packages/api/src/platforms/vtex/clients/search/index.ts Outdated Show resolved Hide resolved
eduardoformiga

This comment was marked as duplicate.

Copy link
Contributor

@lucasfp13 lucasfp13 left a comment

Choose a reason for hiding this comment

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

LGTM!

@hellofanny hellofanny self-assigned this Feb 2, 2024
@hellofanny hellofanny merged commit dd049cd into main Feb 2, 2024
7 checks passed
@hellofanny hellofanny deleted the chore/correct-fuzzy-usage-IS-search-fs-1343 branch February 2, 2024 15:48
lariciamota added a commit that referenced this pull request May 10, 2024
## What's the purpose of this pull request?

Fix bugs related to the addition of fuzzy parameters to the URL on PLP
(category page and search page). See jira tasks on the references
section below.

## How it works?

By using the `replace` function instead of `push` we are able to update
the URL adding the fuzzy parameters to it without triggering the
navigation. Thus, it doesn't re-render the page and it doesn't affect
the back button to previous page.
It happens because the `replace` doesn't add the new URL as a new entry
on the `history` stack.

## How to test it?

Test a category page (example: `/office`) and test search also. Both
pages should have its URL updated to add the fuzzy and operator params,
but shouldn't re-render. Also, if you click the browser return button
you should go to the previous page (Home, for example, if you were on
the Home page and then went to the category page) normally.

### Starters Deploy Preview

<!--- Add a link to a deploy preview from `gatsby.store` AND
`nextjs.store` with this branch being used. --->

<!--- Tip: You can get an installable version of this branch from the
CodeSandbox generated when this PR is created. --->

## References
- #2204
- [[Jira task] Fuzzy bug: return to previous
page](https://vtex-dev.atlassian.net/jira/software/c/projects/SFS/boards/1051?selectedIssue=SFS-802)
- [[Jira task] Fuzzy bug:
re-render](https://vtex-dev.atlassian.net/browse/SFS-515)
- [History:
`replaceState`](https://developer.mozilla.org/en-US/docs/Web/API/History/replaceState)
- [Next router: `replace`
function](https://nextjs.org/docs/pages/api-reference/functions/use-router#routerreplace)
eduardoformiga added a commit that referenced this pull request Aug 29, 2024
eduardoformiga added a commit that referenced this pull request Sep 3, 2024
## What's the purpose of this pull request?

This PR reverts the following PRs:
- #2307
- #2204

Also, it resolves the conflicts from the current main branch.

## How it works?

We are removing the reload issue caused by the use of fuzzy logic and
operators in handling IS requests.

The team will try another approach to address the usage of fuzzy logic
and operators in IS requests allowing the search engine decide the best
parameters for the search.

## How to test it?

You can run the project locally and double-check if the PLP/Search page
just loads once.
Also, you can use the preview URL from starter PR:
PLP: https://sfj-728d5af--starter.preview.vtex.app/office
Search:
https://sfj-728d5af--starter.preview.vtex.app/s?q=shirt&sort=score_desc&page=0

### Starters Deploy Preview

- vtex-sites/starter.store#517

## References

<!--- Spread the knowledge: is there any content you used to create this
PR that is worth sharing? --->

<!--- Extra tip: adding references to related issues or mentioning
people important to this PR may be good for the documentation and
reviewing process --->
hellofanny added a commit that referenced this pull request Nov 21, 2024
## What's the purpose of this pull request?

This PR aims to correct fuzzy and operator usage when handling
Intelligent Search API requests.

Previously, we specified a default value for fuzzy `fuzzy=auto`. But we
shouldn’t include it on the first request to Search. According to the IS
team, the correct behavior should let the search engine decide the best
parameters for the search.

Re-applies changes made from #2204
without adding the blink effect added previously.


- [x] Adds fuzzy & operator parameters in the query
- [x] Avoid re-rendering the page
- [x] Check search PLP (blink issue)
- [x] Check category PLP (blink issue)
- [x] Check duplicate `search.query` event to IS

## How it works?

More details on #2204 description.

## How to test it?

Run the project locally or test though this [preview
link](https://sfj-8636169--starter.preview.vtex.app)

### Testing search PLP

1. Search for `apple` using the input search field
2. Open the `Network Tab` and filter for `ClientProductGalleryQuery`
- In the first request ->`Response` tab: look for `metadata` object, the
`fuzzy` and `logicalOperator` values
<img width="1489" alt="image"
src="https://github.com/user-attachments/assets/3bc1ccf5-65f9-454a-bddf-8fac768007a9">

- Check if the same values is being set in `selectedFacets`
<img width="1227" alt="image"
src="https://github.com/user-attachments/assets/383fcf0b-a616-472f-8266-478e145ebaf0">

- You shouldn't see any blink effect in the page in this scenario:


https://github.com/user-attachments/assets/c92aec29-d089-45d0-a1d0-8bc991c97bb1

### Testing in Category PLP
1. Click on `Technology` category
2. You shouldn't see any blink effect in the page in this scenario

### Duplicate Search event in PLP
1. Search for `apple` using the input search field (at once)
2. Open the `Network Tab` and filter for `event`
3. You shouldn't be able to see the event (with the same url and term)
being send twice
<img width="1574" alt="image"
src="https://github.com/user-attachments/assets/7f0607ac-02cf-4c1d-b201-1cddc5000677">


### Starters Deploy Preview

vtex-sites/starter.store#617

## References

#2204

---------

Co-authored-by: Fanny Chien <[email protected]>
Co-authored-by: Fanny Chien <[email protected]>
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.

3 participants