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

full-text search for query text, name, description #1400

Closed
wants to merge 1 commit into from

Conversation

washort
Copy link

@washort washort commented Nov 16, 2016

Adds a tsvector field to queries and a trigger to automatically fill it when the query text or metadata changes.

db.database.execute_sql("CREATE INDEX tsv_idx ON queries USING gin(tsv)")
db.database.execute_sql("UPDATE queries SET tsv = setweight(to_tsvector(coalesce(name, '')), 'A') || setweight(to_tsvector(coalesce(description, '')), 'B') || setweight(to_tsvector(coalesce(query, '')), 'C')")
db.database.execute_sql("""
CREATE FUNCTION query_search_trigger() RETURNS trigger AS $f$
Copy link
Member

Choose a reason for hiding this comment

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

The migration will work for existing deployments. But what about new ones? Have you considered an before_save/after_save hook instead of a DB trigger?

Also, did you check if it's too much of a performance hit if we do the calculation of the vector in "realtime" instead of storing it?

Copy link
Member

Choose a reason for hiding this comment

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

Also, need to update all existing queries, right?

Copy link
Author

Choose a reason for hiding this comment

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

Good points. Might be worth leaving this off until after #1417 is done.

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good to me. 👍

Copy link
Author

Choose a reason for hiding this comment

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

Ready for re-review.

@washort
Copy link
Author

washort commented Dec 24, 2016

Updated to use alembic, tested upgrade with some sample queries. I didn't benchmark it but I'm fine with not adding the queries.tsv field if you'd rather leave it out.

@arikfr
Copy link
Member

arikfr commented Dec 29, 2016

I will review this (and other pending pull requests) after master is stable and v1 is released. Just don't have the bandwidth to do both :(

@jezdez
Copy link
Member

jezdez commented Oct 5, 2017

@arikfr Hey there, I'd like to help out with this feature and wondered if there is anything blocking from your side for the feature in general. Since I've got time to spend on this, please let me know how we can proceed.

In terms of general direction of the feature I'd like to propose to move in a different direct than this PR and adopt SQLAlchemy-Searchable since it solves the full text search problem on top of PostgreSQL more complete, e.g. flask-sqlalchemy integration, advanced search queries with search operators (AND, OR, paratheses, negatives etc) and alembic integration.

If that direction makes sense to you, I'd be happy to work on a PR to get the ball rolling again.
Otherwise I'm ready to pick this PR up and finish it as well. What do you prefer?

@arikfr
Copy link
Member

arikfr commented Oct 5, 2017

Hi @jezdez 👋

SQLAlchemy-Searchable looks good and seems to make implementation much easier! Should I close this PR then?

In the future it will be nice to have a unified search experience for all objects (queries, dashboards, alerts, users). I was wondering whether we should have a single table with the search vectors for all of them. But realized that we can continue with the current approach (each table has its own vector), but later create a view the unifies them.

Thanks!

@jezdez
Copy link
Member

jezdez commented Oct 5, 2017

@arikfr Hello :) Thanks for your quick reply!

I think it's fair to close the PR, I'll keep an eye on it when I work on the implementation based on SQLAlchemy-Searchable so there are no surprises for the review. I'd like to suggest to collect some experience with the package with the queries first and then work from there to add a unified search, especially since there is likely some work to be done from the UX perspective to get the search results rendering right, since the objects are quite different in terms of what people may want to search for.

@arikfr
Copy link
Member

arikfr commented Oct 5, 2017

I'd like to suggest to collect some experience with the package with the queries first and then work from there to add a unified search

Agreed. 👍

@arikfr arikfr closed this Oct 5, 2017
@arikfr
Copy link
Member

arikfr commented Oct 5, 2017

@washort thank you for "paving" the way 👏

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.

3 participants