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

Incident search filter improvements #1626

Merged
merged 9 commits into from
May 18, 2023
Merged

Conversation

chigby
Copy link
Contributor

@chigby chigby commented Apr 19, 2023

This pull request:

  1. Updates the incident SearchFilter to employ the IndexEntry model's pre-computed textsearch vectors for querying against. This improves performance since we are not having to calculate these ourselves. I did observe faster load times locally, but staging is the place to test this. I will note that the performance gains were dependent on the search term used, with the greatest gains coming when it was a term that appeared in many incidents.
  2. Updates the IncidentPage model to tell wagtail to index more fields into its overall searchable data. These fields are:
  • Body blocks
    • Rich text
    • Image captions
    • Image attributions
    • Text contained embedded tweetes
    • Blockquotes
    • Blockquote sources
    • Pull quotes
    • Video captions
    • Video attributions
  • City
  • State name
  • Introduction
  • Teaser
  • Primary/teaser image caption
  • Primary/teaser image attribution
  • Updates
    • Title
    • Body body blocks (same as above, where applicable)

I think this tends to make the search more useful.

Refs #1573

@SaptakS
Copy link
Contributor

SaptakS commented Apr 24, 2023

@chigby I can review the code, but like you mentioned, it mostly needs to be tested at a staging environment, so should we wait for it to be merged till the experimental staging gets available again?

@chigby
Copy link
Contributor Author

chigby commented Apr 24, 2023

@SaptakS That sounds reasonable to me

index.RelatedFields('updates', [
index.SearchField('title'),
index.SearchField('body'),
]),
Copy link
Contributor

Choose a reason for hiding this comment

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

I see that we are using only the title and body indexes in the search. Adding these fields is to future proof?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So how Wagtail's IndexEntry model works is not super well documented, but the title and body fields on the from your link are its built-in fields that contain searchable data (there is also a third one called autocomplete that allows for partial matches -- intended to be used for find-as-you-type varieties of searches). From how they are named, it might seem like there is a 1-to-1 correspondence between those fields and the fields of the model being indexed, but that's only true for title. The body field (on IndexEntry) includes all the search data that's not part of the title -- so all the fields that are listed in the search_fields attribute of IncidentPage will have their searchable text pulled in and indexed. You can actually test this out by performing a search based on, say, text in the introduction field and see that you will get results.

Copy link
Contributor

@SaptakS SaptakS left a comment

Choose a reason for hiding this comment

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

Codewise looks good to me. We definitely need to test it in staging (probably experimental?) to get a better idea of whether it improves the speed. I am approving the PR but I think should be merged once further testing has been done. Though I don't think it necessarily breaks anything.

@chigby chigby force-pushed the search-filter-performance branch from 714bfe7 to 1537016 Compare May 1, 2023 14:27
@chigby chigby force-pushed the search-filter-performance branch 2 times, most recently from 3a9f506 to 9752e26 Compare May 11, 2023 22:19
This adds some factories for all the blocks that make up the incident
page streamfield body.  Nice to be able to now test this field easily!
This permits:

1. Faster searches, since Wagtail's data is already computed
2. More fields to be searched, since Wagtail knows how to index just
the text from certain non-string DB fields.
@chigby chigby force-pushed the search-filter-performance branch from 9752e26 to a7ad545 Compare May 16, 2023 20:55
@SaptakS
Copy link
Contributor

SaptakS commented May 18, 2023

We can test this further in staging. Merging.

@SaptakS SaptakS merged commit 6f5a319 into develop May 18, 2023
@SaptakS SaptakS deleted the search-filter-performance branch May 18, 2023 12:33
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.

2 participants