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

For searches with no results, retry if Swiftype thinks there is a spelling error #451

Merged
merged 2 commits into from
May 11, 2021

Conversation

danswick
Copy link
Contributor

@danswick danswick commented May 10, 2021

Adds to the default Swiftype connector configuration to handle possible spelling errors in search queries. The Swiftype API supports a "spelling" option, but it is not supported out of the box in the elastic search-ui library we use for our search. However, search-ui has a beforeSearchCall hook that can append arbitrary options before a search call is made.

There are three options for how we could handle spelling issues:

  1. strict: Returns a spelling correction value when there are no results matching the submitted query
  2. always: Returns a possible spelling correction even if there are query matched results
  3. retry: Automatically retries the search request with the spelling corrected value if there are no results, but there is a spelling correction. Note that retry can lead to a slight decline in performance as a result of running 2 queries.

retry is going to be the simplest to implement today to improve users' experience with empty search results. There may be a performance hit as noted in the Swiftype notes, but 1) the retry happens entirely on Swiftype's side and is opaque to the end user 2) Swiftype is already a little on the slow side and the difference doesn't appear to be significant during local testing 3) a retry only ever happens for queries that wouldn't have returned results anyway, so I'm not sure any performance downside is terribly meaningful. The one significant risk with this option is the potential to return nonsense for some queries.

strict is probably the best bet to contain any performance issues that might crop up while giving users a bit more control over what they see. With this option, Swiftype will return spelling suggestions when there are no matching results, but it only returns the suggested new search term and doesn't include any actual results. This means we would need to build out some UI to 1) present the suggestion to the user and 2) give them the option to try the suggestion instead.

always could be useful if a query only returns a few (maybe less than a page?) results. In those cases, we could do something vaguely Google-esque and say, "Your search only matched a few results. Did you mean blah? Here are some matches for blah:" while falling back to the suggestion right away if there are 0 matching results. I noticed that some typos return surprising results, especially if the query contains multiple words. However, Swiftype does a pretty ok job here! For example, if you search for "access toked," the default response will just include any page that scores high for access and it will just ignore toked. However, Swiftype will also include a spelling suggestion if it doesn't have a high confidence in the results. For the "access toked" example, even though some results were returned, it still adds spelling_suggestion: { text: "access token" } to the result's info property.

I strongly favor retry for now. I think it will be great to make an improvement now and come back to other options later if we get more feedback or just want to iterate on our search UI.

Here's an example of how a typo search might work with retry:

  1. User tries to search for "geocode," but accidentally types "geocord".
  2. We send the following request to Swiftype:
{
  "engine_key": "abc123",
  "per_page": 10,
  "page": 1,
  "facets": {...},
  "q": "geocord",
  "spelling": "retry"
}
  1. Swiftype finds no matches for "geocord," but thinks the user might mean to type "geocode." The following results are sent back:
{
  "record_count": 10,
  "records": {...},
  "info": {
    "page": {
      "query": "geocode",
      "current_page": 1,
      "num_pages": 13,
      "per_page": 10,
      "total_result_count": 127,
      "facets": {...}
    }
  },
  "errors": {}
}

How to test

  • Pull down this branch, install, and npm start.
  • Open the test cases page, navigate to the Search component, and type some mangled search terms. Geocord, spprt, morker, "gs jl", etc.

QA checklist

  • No errors logged to console.
  • Accessibility score in Chrome DevTools Audit/Lighthouse is 100% with Lighthouse version: 7.2.0.
  • Component is accessible at mobile-size viewport.
  • Component is accessible at tablet-size viewport.
  • Component is accessible at laptop-size viewport.
  • Component is accessible at big-monitor-size viewport.

Open the test cases app locally on:

  • Chrome, no errors logged to console.
  • Firefox, no errors logged to console.
  • Safari, no errors logged to console.
  • Edge, no errors logged to console.
  • Mobile Safari, no errors logged to console.
  • Android Chrome, no errors logged to console.

Before merge

  • Add entry to CHANGELOG.md to describe changes.
  • If updating dependencies or creating a release, run npx browserslist@latest --update-db to update the browser data and commit any changes to package-lock.json.

@danswick danswick requested a review from katydecorah May 10, 2021 23:37
Copy link
Contributor

@katydecorah katydecorah left a comment

Choose a reason for hiding this comment

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

Lurks gourd to me!

(Seriously, thanks for explaining the options and why you chose retry. This will be a huge improvement.)

@katydecorah katydecorah merged commit 8e7bca7 into 4.0.0 May 11, 2021
@katydecorah katydecorah deleted the search-typo-retry branch May 11, 2021 13:27
katydecorah pushed a commit that referenced this pull request May 11, 2021
* 4.0.0:
  Switch Sentry environment back to `main`
  4.0.0-alpha.10
  Fix Sentry test
  Update prettier
  Send search results with no queries to Sentry (#452)
  Update @sentry/browser
  Update caniuse-lite
  Update search-ui, downshift
  For searches with no results, retry if Swiftype thinks there is a spelling error (#451)
  Bump hosted-git-info from 2.7.1 to 2.8.9 (#450)
  Fix props on search toggle (#448)
  Bump lodash from 4.17.20 to 4.17.21 (#449)
  Bump underscore from 1.10.2 to 1.13.1 (#447)
katydecorah pushed a commit that referenced this pull request May 11, 2021
* Prepare 4.0.0 changelog

* Make code toggles in test cases interactive or label if they are not (#432)

* Update dependencies (#433)

* Update dependencies

* Update package-lock.json

* Update rehype-slug

* Fix links

* Update page-layout.md

* Update snapshots

* Replace stateless components with pure components (#414)

* Use PureComponent on stateless components

* Update package-lock.json

* 4.0.0-alpha.0

* Use PureComponents where components do not require rerenders

* 4.0.0-alpha.1

* prefer-const

* Update CHANGELOG.md

* Make more components pure

* 4.0.0-alpha.2

* 4.0.0-alpha.3

* Improve color contrast on code and anchor elements (#434)

* Expand a code color contrast improvement

* Increase color contrast on .color-gray code

* Increase color contrast for prism's .token.regex,.token.important

* Clean up test cases

* Update CHANGELOG.md

* Clean up test cases

* Clean up test cases

* Update docs/src/pages/guides/a11y.md

Co-authored-by: Colleen McGinnis <colleen.mcginnis@mapbox.com>

* Reduce changes

Co-authored-by: Colleen McGinnis <colleen.mcginnis@mapbox.com>

* 🔧 Run prettier

* Add eslint-plugin-jsx-a11y (#435)

* Add eslint-plugin-jsx-a11y

* Fix props

* Update CHANGELOG.md

* Update search.test.js.snap

* Update eslint

* Update eslint

* Create `prepareSitemap` Batfish helper to improve sitemap (#427)

* Create prepareSitemap Batfish helper

* Update CHANGELOG.md

* Clean up, add `docsPath`, and `outputDirectory`

* Exclude `splitPage` from sitemap

* Assert sitemap

* Extract urls

* Sort sitemap

* Remove snapshot

* Update sitemap.test.js

* Update batfish-helpers.md

* Update batfish-helpers.md

* Copyedit

* Update package-lock.json

* Replace `id` with `aria-label` in VimeoPlayImage (#438)

* Replace `id` with aria-label to prevent duplicated id

* Update CHANGELOG.md

* Make `filename` optional for `CodeSnippetTitle`

* Make "With token" `DemoIframe` a no render test case (#440)

* Make "With token" `DemoIframe` a no render test case

* Rename

* Use passive event listeners on `Search`, `NumberedCodeSnippet`, and `OnThisPage` to improve performance (#437)

* Use passive event listeners on `Search`, `NumberedCodeSnippet`, and `OnThisPage` to improve performance.

* Update CHANGELOG.md

* Reconfigure `Video` options to optimize for user's settings around autoplay (#276)

* show video controls on hover; show play button for browsers with disabled autoplay

* Merge branch 'main' into video-controls

* main:
  Add the catalog site  (#137)
  Delete dependabot.yml
  Only direct dependencies
  Create dependabot.yml (#296)
  Update Travis bad
  Update devDependencies (#294)

* Add example

* More comments

* Reduce changes

* eslint and fix button styles

* Clean up button

* Set playsInline to true if autoPlay is true; make `muted` a prop

* Update test cases description to indicate the autoplay state

* Update description

* Update snapshots

* Update CHANGELOG.md

* Create `playsInline` prop

* Append hash to src to enable preview on iOS

* Update video.js

* Adds optional `poster` prop

* Remove hack

* Add poster example

* Fix paths

* Update descriptions

* Apply suggestions from code review

* Load Search with a facade (#430)

* Load Search with a facade

* Add @loadable/babel-plugin

* Update CHANGELOG.md

* Fix logic

* Update search.test.js.snap

* Define development babel env to prevent `@loadable/babel-plugin` from loading on start (because it fails)

* Adjusting snapshots

* Revert "Adjusting snapshots"

This reverts commit d2e7fd9.

* Clean up props

* Comments

* Reduce changes

* Reduce changes

* Reduce changes

* Reduce changes

* Clean up props

* Use SearchInput in SearchBox

* Use SearchButton in SearchBox

* Reduce changes

* Add missing props

* Consolidate wrapper

* 4.0.0-alpha.4

* Try dynamic import

* Update package-lock.json

* 4.0.0-alpha.5

* Update package-lock.json

* Reduce changes

* Reorganize files

* 4.0.0-alpha.6

* Switch to noRenderCase

* Reduce changes

* Add passive event listener

* Allow autofocus

* Enable react/jsx-no-bind (#442)

* jsx-no-bind

* Update CHANGELOG.md

* Simplify, reduce changes

* The `NumberedCodeSnippet` prop `onCopy` is deprecated and will automatically send a track event to Segment

* Remove unused onCopy

* Simplify

* Add onCopy

* Create onCopy function

* Update src/components/code-snippet/on-copy.js

* Update dependencies

* Update caniuse

* Update devDependencies

* Update CHANGELOG.md

* Fix NavigationAccordion tests (#443)

* 4.0.0-alpha.7

* Fix prepareSitemap: append index.html to files ending in index.js (#444)

* 4.0.0-alpha.8

* Update batfish

* Update caniuse-lite

* Fix props on search toggle (#448)

* Fix props on search toggle

* 4.0.0-alpha.9

* For searches with no results, retry if Swiftype thinks there is a spelling error (#451)

* pass through swiftype API spelling option

* move prettier'd comment

* Update search-ui, downshift

* Update caniuse-lite

* Update @sentry/browser

* Send search results with no queries to Sentry (#452)

* Send search results with no queries to Sentry

* Update CHANGELOG.md

* Update prettier

* Fix Sentry test

* 4.0.0-alpha.10

* Switch Sentry environment back to `main`

* Fix Search/Sentry, only send when results change

* 4.0.0

* Clean up

Co-authored-by: Colleen McGinnis <colleen.mcginnis@mapbox.com>
Co-authored-by: Dan Swick <dan.swick@gmail.com>
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