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

Add records.search RPC function #3708

Merged
merged 14 commits into from
Aug 2, 2024
Merged

Add records.search RPC function #3708

merged 14 commits into from
Aug 2, 2024

Conversation

mathemancer
Copy link
Contributor

Fixes #3707

This adds a records.search RPC function.

Technical details

The function is documented as usual, and it should be possible to review this with no further explanation. If not, request a documentation improvement.

Screenshots

Checklist

  • My pull request has a descriptive title (not a vague title like Update index.md).
  • My pull request targets the develop branch of the repository
  • My commit messages follow best practices.
  • My code follows the established code style of the repository.
  • I added 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.

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.

@mathemancer mathemancer requested a review from Anish9901 July 25, 2024 09:29
@mathemancer mathemancer added this to the Beta milestone Jul 25, 2024
@mathemancer mathemancer added the pr-status: review A PR awaiting review label Jul 25, 2024
@mathemancer mathemancer changed the title Records search rank Add records.search RPC function Jul 25, 2024
@mathemancer mathemancer marked this pull request as draft July 25, 2024 09:31
@mathemancer
Copy link
Contributor Author

@Anish9901 This is ready for review, but I'm marking it as a draft to keep us from merging until #3700 is merged.

Base automatically changed from records_list_filter to develop July 26, 2024 08:46
@mathemancer mathemancer marked this pull request as ready for review July 26, 2024 09:16
@mathemancer mathemancer mentioned this pull request Aug 1, 2024
7 tasks
Copy link
Member

@Anish9901 Anish9901 left a comment

Choose a reason for hiding this comment

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

This looks great logic wise @mathemancer, there are some unhandled edge cases that break the function. Please see my specific comments.

db/records/operations/select.py Outdated Show resolved Hide resolved
Comment on lines +73 to +74
result = db_conn.exec_msar_func(
conn, 'search_records_from_table', table_oid, json.dumps(search), limit
Copy link
Member

Choose a reason for hiding this comment

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

I think we could avoid this function call when the search list is empty. Assuming frontend already has the records from records.list.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could, but I'd rather have the front end do that. I.e., if they want to avoid the call, they should just not send the request until there are letters in the array. For the completeness of this function I'd really rather treat it as a kind of "narrowing filter" concept. And for that, we should return unfiltered results whenever we get an empty search definition.

msar.search_records_from_table(
tab_id oid,
search_ jsonb,
limit_ integer
Copy link
Member

Choose a reason for hiding this comment

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

For some reason having NULL for limit_ here doesn't return anything, But works perfectly in list_records_from_table.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now it returns all matching records.

Comment on lines +3543 to +3544
search_ jsonb,
limit_ integer
Copy link
Member

Choose a reason for hiding this comment

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

SELECT msar.search_records_from_table(2254321, '[]'::jsonb, 4);
ERROR:  syntax error at or near ">"

Passing an empty json for search_ and a non null value for limit_ also breaks the function and results in a syntax error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Empty or null values for the search def now return unfiltered results.

Comment on lines 3578 to 3581
msar.get_score_expr(tab_id, search_),
limit_,
concat(
msar.get_score_expr(tab_id, search_),
Copy link
Member

Choose a reason for hiding this comment

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

Can we consider storing the result for this function into a variable instead of calling it twice?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did a quick experiment. The variable idea had no noticeable effect, but setting the get_score_expr function to STABLE did. So, I went with that.

@mathemancer mathemancer requested a review from Anish9901 August 2, 2024 06:08
@Anish9901 Anish9901 added this pull request to the merge queue Aug 2, 2024
Merged via the queue into develop with commit 7f67921 Aug 2, 2024
37 checks passed
@Anish9901 Anish9901 deleted the records_search_rank branch August 2, 2024 10:51
@kgodey kgodey modified the milestones: Beta, Pre-beta test build #1 Sep 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr-status: review A PR awaiting review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement records.search RPC method
3 participants