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

feat(plugin-search): added support for reindexing collections on demand #9391

Merged

Conversation

akhrarovsaid
Copy link
Contributor

@akhrarovsaid akhrarovsaid commented Nov 20, 2024

What?

This PR aims to add reindexing capabilities to plugin-search to allow users to reindex entire searchable collections on demand.

Why?

As it stands, end users must either perform document reindexing manually one-by-one or via bulk operations. Both of these approaches are undesirable because they result in new versions being published on existing documents. Consider the case when plugin-search is only added after the project has started and documents have been added to existing collections. It would be nice if users could simply click a button, choose the searchable collections to reindex, and have the custom endpoint handle the rest.

How?

This PR adds on to the existing plugin configuration, creating a custom endpoint and a custom beforeListTable component in the form of a popup button. Upon clicking the button, a dropdown/popup is opened with options to select which collection to reindex, as well as a useful All Collections option to run reindexing on all configured search collections. It also adds a reindexBatchSize option in the config to allow users to specify in what quantity to batch documents to sync with search.

Big shoutout to @paulpopus & @r1tsuu for the triple-A level support on this one!

Fixes #8902

See it in action:

chrome_2024-11-12_12-18-13.mp4

Notes:

  • Traditionally these kinds of long-running tasks would be better suited for a job. However, given how many users enjoy deploying to serverless environments, it would be problematic to offer this feature exclusive to jobs queues. I thought a significant amount about this and decided it would be best to ship the feature as-is with the intention of creating an opt-in method to use job queues in the future if/when this gets merged.
  • In my testing, the collection description somehow started to appear in the document views after the on-demand RSC merge. I haven't reproduced this, but this PR has an example of that problem. Super strange.

@JarrodMFlesch
Copy link
Contributor

@akhrarovsaid this looks great! We were wondering if you could modify this PR and place the reindex button in the actions slot for the list view instead of the beforeTable slot?

@akhrarovsaid
Copy link
Contributor Author

Hey @JarrodMFlesch,

Thank you! So that was actually my first thought too - it fits more naturally there. However, in my testing there was an issue with the actual dropdown/popup that shows up. I think due to overflow hidden somewhere higher in the dom, it cuts the popup off. I'll try again and report my findings, maybe somethings changed since then.

@akhrarovsaid
Copy link
Contributor Author

akhrarovsaid commented Nov 25, 2024

@JarrodMFlesch

There's something about the actions wrapper that does not agree here.

Search-Results---Payload.webm

Here's what I've tried:

  • Moving component as is to actions slot
  • Moving component as is but with relative wrapper and high z-index (10-999)
  • Doing the same but with absolute wrapper and high z-index
  • Same with fixed
  • Tried all of the above but moved styles directly to PopupList.ButtonGroup via classNames
  • Enforcing opacity 1 with and without !important
  • All of the above with isolation: isolate

It's strange, I'm doing exactly what the localizer is doing except the localizer isn't wrapped in the actions wrapper, so I'm thinking it must be something conflicting from higher up the dom. I can see the correct active class being applied in devtools on interaction though.

paulpopus added a commit that referenced this pull request Nov 26, 2024
…aks any popout elements (#9525)

Unblocks #9391

It was previously impossible to create popout, dropdown or other menus
from buttons added to the app-header component
@DanRibbens
Copy link
Contributor

Is this ready for review again?

@akhrarovsaid
Copy link
Contributor Author

@DanRibbens Yep, good to go

@paulpopus paulpopus changed the title feat(plugin-search): reindex collections feat(plugin-search): added support for reindexing collections on demand Nov 26, 2024
@paulpopus paulpopus enabled auto-merge (squash) November 26, 2024 22:07
The transaction is not needed since we execute
```ts
const totalDocs = await countDocuments(collection)
```
at the start and previous operations shouldn't affect this count
@paulpopus paulpopus merged commit defa13e into payloadcms:main Nov 26, 2024
53 checks passed
Copy link
Contributor

🚀 This is included in version v3.2.0

@PP-Tom
Copy link

PP-Tom commented Dec 4, 2024

Thanks for the PR, it's amazing and extremely useful.

I'm having issues with large datasets, if one item fails the entire reindexing fails in this case with { txnNumber: 3 }, with larger datasets (1,200 documents), it seems like the transaction is timing out?

[18:22:55] ERROR: Error finding search document.
    err: {
      "type": "MongoExpiredSessionError",
      "message": "Cannot use a session that has ended",

The other error I seem to be getting is

[18:22:54] ERROR: Error finding search document.
    err: {
      "type": "MongoServerError",
...
"errmsg": "Transaction with { txnNumber: 1 } has been aborted.",
"code": 251,
"codeName": "NoSuchTransaction",

I personally feel like there is some underlying issues with transactions that might not be related to this PR. But it is preventing it from functioning correctly.

jacobsfletch pushed a commit that referenced this pull request Dec 5, 2024
Adds documentation for the feature introduced with [plugin-search
collection reindexing](#9391).
This also fixes an invalid scss import in one of the examples.

Credit to @rilrom for the invalid css import find!
kendelljoseph pushed a commit that referenced this pull request Feb 21, 2025
…aks any popout elements (#9525)

Unblocks #9391

It was previously impossible to create popout, dropdown or other menus
from buttons added to the app-header component
kendelljoseph pushed a commit that referenced this pull request Feb 21, 2025
…nd (#9391)

### What?
This PR aims to add reindexing capabilities to `plugin-search` to allow
users to reindex entire searchable collections on demand.

### Why?
As it stands, end users must either perform document reindexing manually
one-by-one or via bulk operations. Both of these approaches are
undesirable because they result in new versions being published on
existing documents. Consider the case when `plugin-search` is only added
_after_ the project has started and documents have been added to
existing collections. It would be nice if users could simply click a
button, choose the searchable collections to reindex, and have the
custom endpoint handle the rest.

### How?
This PR adds on to the existing plugin configuration, creating a custom
endpoint and a custom `beforeListTable` component in the form of a popup
button. Upon clicking the button, a dropdown/popup is opened with
options to select which collection to reindex, as well as a useful `All
Collections` option to run reindexing on all configured search
collections. It also adds a `reindexBatchSize` option in the config to
allow users to specify in what quantity to batch documents to sync with
search.

Big shoutout to @paulpopus & @r1tsuu for the triple-A level support on
this one!

Fixes #8902 

See it in action:


https://github.com/user-attachments/assets/ee8dd68c-ea89-49cd-adc3-151973eea28b

Notes:
- Traditionally these kinds of long-running tasks would be better suited
for a job. However, given how many users enjoy deploying to serverless
environments, it would be problematic to offer this feature exclusive to
jobs queues. I thought a significant amount about this and decided it
would be best to ship the feature as-is with the intention of creating
an opt-in method to use job queues in the future if/when this gets
merged.
- In my testing, the collection description somehow started to appear in
the document views after the on-demand RSC merge. I haven't reproduced
this, but this PR has an example of that problem. Super strange.

---------

Co-authored-by: Sasha <64744993+r1tsuu@users.noreply.github.com>
Co-authored-by: Paul Popus <paul@nouance.io>
kendelljoseph pushed a commit that referenced this pull request Feb 21, 2025
Adds documentation for the feature introduced with [plugin-search
collection reindexing](#9391).
This also fixes an invalid scss import in one of the examples.

Credit to @rilrom for the invalid css import find!
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.

6 participants