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

Changed "exact match boost" implementation to use a match_phrase query in should #4978

Merged
merged 17 commits into from
Sep 23, 2024

Conversation

dryruffian
Copy link
Contributor

Fixes

Fixes #4960 by @sarayourfriend

Description

This pull request changes the usage of simple_query_string to match_phrase as suggested by @sarayourfriend. This will bypass simple query string altogether for this, saving some parsing cycles in Elasticsearch. It will also make our intention much clearer in code (and in the generated query) by using match_phrase directly.

Checklist

  • My pull request has a descriptive title (not a vague title likeUpdate index.md).
  • My pull request targets the default branch of the repository (main) or a parent feature branch.
  • My commit messages follow best practices.
  • My code follows the established code style of the repository.
  • I added or updated tests for the changes I made (if applicable).
  • I added or updated documentation (if applicable).
  • I tried running the project locally and verified that there are no visible errors.
  • I ran the DAG documentation generator (ov just catalog/generate-docs for catalog
    PRs) or the media properties generator (ov just catalog/generate-docs media-props
    for the catalog or ov just api/generate-docs for the API) where applicable.

Developer Certificate of Origin

Developer Certificate of Origin
Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.


Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.

dryruffian and others added 16 commits September 22, 2024 23:11
dd Sutori to the "Made with Openverse" page.
Fixed commit message to be more precise and include the issue number
Fixed commit message to be more precise and include the issue number
I added the suggestion from @sarayourfriend.

Co-authored-by: sarayourfriend <[email protected]>
… in should #4960

I have added support for "match_pharse"
and also removed variable quotes_stripped it's not needed now.
…in should #4960

I have added support for "match_pharse"
and also removed variable quotes_stripped it's not needed now.
and also removed variable quotes_stripped it's not needed now.
@dryruffian dryruffian requested a review from a team as a code owner September 23, 2024 18:28
@dryruffian dryruffian requested review from krysal and sarayourfriend and removed request for a team September 23, 2024 18:28
@openverse-bot openverse-bot added 🧱 stack: api Related to the Django API 🟩 priority: low Low priority and doesn't need to be rushed ✨ goal: improvement Improvement to an existing user-facing feature 💻 aspect: code Concerns the software code in the repository labels Sep 23, 2024
@dryruffian
Copy link
Contributor Author

hi @sarayourfriend,
Can you please take a look at my PR. Passed all the API test on my machine. There is some formatting can you guide me through that.

@sarayourfriend
Copy link
Collaborator

Sure! You should run ov just lint on the latest commit of the branch and then commit any changes that appear. Typically we rely on the git pre-commit hook to run the linter for us before we commit changes. Are your git hooks set up? You can check by running cat .git/hooks/pre-commit and confirm it looks like this:

#! /usr/bin/env bash

export TERM=xterm

./ov hook pre-commit "$@"

ov init from our getting started documentation should have installed the hooks for you. You can run ov just install-hooks to re-run ov's hook installation.

@dryruffian
Copy link
Contributor Author

Hey @sarayourfriend, thanks for your help getting this PR to work. I really appreciate it. Can you please take a look at the PR and suggest any changes that might be needed?

Copy link
Collaborator

@sarayourfriend sarayourfriend left a comment

Choose a reason for hiding this comment

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

Thanks again @dryruffian!

"flags": DEFAULT_SQS_FLAGS,
"match_phrase": {
"title": {
"query": '"The cutest cat"',
Copy link
Collaborator

Choose a reason for hiding this comment

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

For other reviewers who notice this double-quoting. It's preserved from the input string. It shouldn't be a problem, it seems that (at least with our current analyser configuration for title) match_phrase filters our non-alphanumeric tokens in search. For example, a query for "house cat photo" (with the quotes) ends up as this, for the match_phrase part of the scoring, and is identical if I drop the quotes in the query string.

{
  "value": 10000,
  "description": "weight(title:\"hous cat photo\" in 95) [PerFieldSimilarity], result of:",
  "details": [
    {
      "value": 10000,
      "description": "score(BooleanWeight), computed from:",
      "details": [
        {
          "value": 10000,
          "description": "boost, query boost",
          "details": []
        }
      ]
    }
  ]
}

@sarayourfriend sarayourfriend merged commit 7a0e4eb into WordPress:main Sep 23, 2024
47 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💻 aspect: code Concerns the software code in the repository ✨ goal: improvement Improvement to an existing user-facing feature 🟩 priority: low Low priority and doesn't need to be rushed 🧱 stack: api Related to the Django API
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Change "exact match boost" implementation to use a match_phrase query in should
3 participants