-
Notifications
You must be signed in to change notification settings - Fork 370
Add searchable field column to handle full text search #8544
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
Merged
Archaeopteryx
merged 9 commits into
mozilla:master
from
Netacci:set-full-text-search-using-search-vector
Apr 18, 2025
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d697d6b
create migration for removing previously applied search vector, add s…
Netacci 7f50f32
fix tests for search fields
Netacci d1a71f0
squash migrations
Netacci a7895ff
remove replace from migration, print statement from test and add Subs…
Netacci b0b8ca2
Retrigger GitHub Actions
Netacci 2c3e665
rebase and update migration
Netacci 563e6e8
update query to search both push and commit models
Netacci ea3f398
update test script
Netacci c4fb4fb
Remove debug print statement from push API.
Archaeopteryx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import datetime | ||
|
||
import pytest | ||
from django.contrib.postgres.search import SearchVector | ||
from django.urls import reverse | ||
|
||
from tests.conftest import IS_WINDOWS | ||
|
@@ -407,23 +408,28 @@ def test_push_search(client, test_repository): | |
Commit.objects.create( | ||
push=push1, revision="1234abcd", author="kaz <[email protected]>", comments="Initial commit" | ||
) | ||
|
||
Commit.objects.create( | ||
push=push2, revision="2234abcd", author="foo <[email protected]>", comments="Bug 12345567 - fix" | ||
) | ||
|
||
Commit.objects.create( | ||
push=push3, | ||
revision="3234abcd", | ||
author="quxzan <qux@bar>.com", | ||
comments="Bug 12345567 - Feature added", | ||
) | ||
|
||
Commit.objects.update( | ||
search_vector=SearchVector("revision", "author", "comments", config="english") | ||
) | ||
# Test search by comments | ||
resp = client.get( | ||
reverse("push-list", kwargs={"project": test_repository.name}) + "?search=bug" | ||
) | ||
assert resp.status_code == 200 | ||
|
||
results = resp.json()["results"] | ||
|
||
assert len(results) == 2 | ||
assert set([result["id"] for result in results]) == set([3, 2]) | ||
|
||
|
@@ -444,7 +450,7 @@ def test_push_search(client, test_repository): | |
assert resp.status_code == 200 | ||
|
||
results = resp.json()["results"] | ||
assert len(results) == 1 | ||
assert len(results) == 2 | ||
assert results[0]["id"] == push2.id | ||
|
||
# Test search by revision | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Generated by Django 5.1.5 on 2025-03-06 14:49 | ||
|
||
import django.contrib.postgres.indexes | ||
import django.contrib.postgres.search | ||
from django.contrib.postgres.search import SearchVector | ||
from django.db import migrations | ||
from django.db.models.functions import Substr | ||
|
||
|
||
def update_search_vector(apps, schema_editor): | ||
Commit = apps.get_model("model", "Commit") | ||
Commit.objects.update( | ||
search_vector=SearchVector("revision", "author", Substr("comments", 1, 100000), config="english") | ||
) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("model", "0040_alter_textlogerror_unique_together_and_more"), | ||
] | ||
|
||
operations = [ | ||
migrations.RemoveIndex( | ||
model_name="commit", | ||
name="search_vector_idx", | ||
), | ||
migrations.AddField( | ||
model_name="commit", | ||
name="search_vector", | ||
field=django.contrib.postgres.search.SearchVectorField(blank=True, null=True), | ||
), | ||
migrations.AddIndex( | ||
model_name="commit", | ||
index=django.contrib.postgres.indexes.GinIndex( | ||
fields=["search_vector"], name="search_vector_idx" | ||
), | ||
), | ||
migrations.RunPython(update_search_vector), | ||
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
debug code to remove
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea missed that :)