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

Optimise search excerpt to highlight more relevant results #1075

Merged
merged 2 commits into from
Feb 8, 2023

Conversation

lookupdaily
Copy link
Contributor

Currently a search result excerpt is generated by searching for the index of each separate term and selecting the first match for the first word (or the first match for the second if it is not found). This means that when selecting the first excerpt from the page it may not be the most relevant to the user as it may contain the first term only when there is a result lower down the page which contains the full term. (Issue #1074 )

This change looks for an excerpt containing the full search term first, so a full match will be prioritised over one containing just one word.

A few considerations:

  • This doesn't work for special characters. However the search functionality itself does not find words with special characters in the search term (e.g. 'thoughtbot's' will not be found), so we might want to consider ignoring special characters as part of Search: optimise results #1030
  • This is only searching for the full search term, and then each separate term in isolation. If, for example, somebody searched with 3 terms it will look for an excerpt containing 3 terms together before falling back on each term in isolation rather than combinations (e.g. the first two terms) - but not sure that doing this will add much value.

Resolves issue #1074

@netlify
Copy link

netlify bot commented Feb 7, 2023

Deploy Preview for laughing-payne-b9fbd2 ready!

Name Link
🔨 Latest commit b3eafe4
🔍 Latest deploy log https://app.netlify.com/sites/laughing-payne-b9fbd2/deploys/63e3b711f0911f0007eec32d
😎 Deploy Preview https://deploy-preview-1075--laughing-payne-b9fbd2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@lookupdaily lookupdaily changed the title Add a full search term to getExcerpt Optimise search excerpt to highlight more relevant results Feb 7, 2023
@lookupdaily lookupdaily linked an issue Feb 7, 2023 that may be closed by this pull request
Copy link
Member

@yndajas yndajas left a comment

Choose a reason for hiding this comment

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

Nice! This seems to be doing the job - tested with the "flexible working example", comparing the excerpt in the sixth result with that on the live version of the playbook

I've included a suggestion for DRYing this up, but I think it's good to merge in principle

Before

image

After

image

src/assets/js/search.js Show resolved Hide resolved
Copy link
Member

@yndajas yndajas left a comment

Choose a reason for hiding this comment

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

Looks great to me! This is a nice DRY up. Just a few quick comments on superficial things, but otherwise I think it's good to go

The first two commits could probably be squashed, but it does tell a story as is, so I'm easy

src/assets/js/search.js Outdated Show resolved Hide resolved
src/assets/js/search.js Outdated Show resolved Hide resolved
src/assets/js/search.js Outdated Show resolved Hide resolved
@lookupdaily lookupdaily force-pushed the issue/1074-optimize-search-excerpt branch from e148669 to a55d57b Compare February 8, 2023 14:36
Currently a search excerpt is generated by searching for the index of each separate term and selecting the first match for the first word (or the first match for the second if it is not found).

Here have added a search for the full term, so that an excerpt containing a full match will be prioritized over one containing just one word. The function uses two variables: information for the first (if any) full match, and a list of information on the first match for each word in the search query. Even if a full match is found, the list of individual term matchers is used for highlighting terms in the excerpt display.
@lookupdaily lookupdaily force-pushed the issue/1074-optimize-search-excerpt branch from a55d57b to fdac5dc Compare February 8, 2023 14:42
For consistency with the rest of file.
@lookupdaily lookupdaily merged commit 38e3baa into main Feb 8, 2023
@lookupdaily lookupdaily deleted the issue/1074-optimize-search-excerpt branch February 8, 2023 15:40
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.

Search: optimize excerpt
2 participants