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 some search functionality #1406

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

add some search functionality #1406

wants to merge 3 commits into from

Conversation

nilsding
Copy link
Member

@nilsding nilsding commented Oct 22, 2023

super early WIP, resolves #13

this requires Meilisearch to be installed. it's ridiculously fast and super easy to use. eats up a lot of disk space however but i guess that's what it takes to have a decent search.

to set it up locally (macOS):

brew install meilisearch

to enable search functionality:

SEARCH_ENABLED=true foreman start -f Procfile.dev

to import data to meilisearch:

SEARCH_ENABLED=true bundle exec rails runner '[Answer, Question].map(&:reindex!)'

what's still left to be done:

  • decide how we want to present the search results (maybe each type in a tab? multisearch, while fast, seems a bit wonky)
  • decide whether we want search to be done by signed in users only (i'd say yes)
  • decide what questions to include in the index (answer count >= 1? non-anonymous ones? definitely skip the generated ones though)
  • pagination
  • clean up the UI in general (this includes maybe a search bar or button in the navbar)
  • set it up to index stuff in a sidekiq worker (see also https://github.com/meilisearch/meilisearch-rails?tab=readme-ov-file#queues--background-jobs)
  • perhaps introduce some /@user/questions/search / /@user/search pages too which only searches for the user's qustions/answers
  • add some gradual rollout so we can keep an eye on how it behaves
  • deal with extra user flags (exclude from search results)
  • introduce a flag for enabling/disabling search globally
  • introduce a flag that overrides the user's choice of being present in the search results (the idea is to not display results from spammers or some other problematic people)
  • (for prod): set up machines for meilisearch

this commit is an attempt at building a search functionality using only
the stuff provided by postgresql

it is, unfortunately, painfully slow:

    PgSearch::Document Load (7869.1ms)  SELECT "pg_search_documents".* FROM "pg_search_documents" INNER JOIN (SELECT "pg_search_documents"."id" AS pg_search_id, (ts_rank((to_tsvector('simple', coalesce("pg_search_documents"."content"::text, ''))), (to_tsquery('simple', ''' ' || 'awoo' || ' ''')), 0)) AS rank FROM "pg_search_documents" WHERE ((to_tsvector('simple', coalesce("pg_search_documents"."content"::text, ''))) @@ (to_tsquery('simple', ''' ' || 'awoo' || ' ''')))) AS pg_search_ce9b9dd18c5c0023f2116f ON "pg_search_documents"."id" = pg_search_ce9b9dd18c5c0023f2116f.pg_search_id ORDER BY pg_search_ce9b9dd18c5c0023f2116f.rank DESC, "pg_search_documents"."id" ASC LIMIT $1  [["LIMIT", 10]]
this thing is way too fast!  only downside is that indexing takes a bit
longer, and the search indexes are big (16Gi for 2.7 million records)

i have no idea how to properly integrate it in the UI, but it seems
promising :^)
@results = if params[:multi_search] == "1"
multi_search_experiment
else
[*Answer.search(@query), *Question.search(@query)]
Copy link
Member Author

@nilsding nilsding Oct 22, 2023

Choose a reason for hiding this comment

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

doesn't take too long tbh (~2.7m documents)

19:52:10 search.1 | [2023-10-22T17:52:10Z INFO  actix_web::middleware::logger] ::1 "POST /indexes/Answer/search HTTP/1.1" 200 959 "-" "Meilisearch Rails (v0.10.1);Meilisearch Ruby (v0.25.1)" 0.023072
19:52:10 search.1 | [2023-10-22T17:52:10Z INFO  actix_web::middleware::logger] ::1 "POST /indexes/Question/search HTTP/1.1" 200 933 "-" "Meilisearch Rails (v0.10.1);Meilisearch Ruby (v0.25.1)" 0.011066

return if @query.blank?

@results = if params[:multi_search] == "1"
multi_search_experiment
Copy link
Member Author

Choose a reason for hiding this comment

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

here's the same thing (~2.7m documents), but combined in the same request:

19:52:44 search.1 | [2023-10-22T17:52:44Z INFO  actix_web::middleware::logger] ::1 "POST /multi-search HTTP/1.1" 200 2787 "-" "Meilisearch Rails (v0.10.1);Meilisearch Ruby (v0.25.1)" 0.002295

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
1 participant