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

Remove search #209

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
"type":"maven",
"namespace":"",
"name":"foo",
"name":"Foo",
"version":"",
"qualifiers":"",
"subpath":"",
Expand Down Expand Up @@ -36,9 +36,9 @@
"source_packages":[],
"extra_data":{},
"dependencies":[],
"package_uid":"pkg:maven/foo?uuid=fixed-uid-done-for-testing-5642512d1758",
"package_uid":"pkg:maven/Foo?uuid=fixed-uid-done-for-testing-5642512d1758",
"datasource_id":null,
"purl":"pkg:maven/foo",
"purl":"pkg:maven/Foo",
"repository_homepage_url":null,
"repository_download_url":null,
"api_data_url":null,
Expand Down
6 changes: 3 additions & 3 deletions minecode/tests/testfiles/housekeeping/example_expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
"type":"maven",
"namespace":"",
"name":"foo",
"name":"Foo",
"version":"",
"qualifiers":"",
"subpath":"",
Expand Down Expand Up @@ -36,9 +36,9 @@
"source_packages":[],
"extra_data":{},
"dependencies":[],
"package_uid":"pkg:maven/foo?uuid=fixed-uid-done-for-testing-5642512d1758",
"package_uid":"pkg:maven/Foo?uuid=fixed-uid-done-for-testing-5642512d1758",
"datasource_id":null,
"purl":"pkg:maven/foo",
"purl":"pkg:maven/Foo",
"repository_homepage_url":null,
"repository_download_url":null,
"api_data_url":null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
"type":"maven",
"namespace":"",
"name":"foo",
"name":"Foo",
"version":"",
"qualifiers":"",
"subpath":"",
Expand Down Expand Up @@ -36,9 +36,9 @@
"source_packages":[],
"extra_data":{},
"dependencies":[],
"package_uid":"pkg:maven/foo?uuid=fixed-uid-done-for-testing-5642512d1758",
"package_uid":"pkg:maven/Foo?uuid=fixed-uid-done-for-testing-5642512d1758",
"datasource_id":null,
"purl":"pkg:maven/foo",
"purl":"pkg:maven/Foo",
"repository_homepage_url":null,
"repository_download_url":null,
"api_data_url":null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
"type":"maven",
"namespace":"",
"name":"foo",
"name":"Foo",
"version":"",
"qualifiers":"",
"subpath":"",
Expand Down Expand Up @@ -36,9 +36,9 @@
"source_packages":[],
"extra_data":{},
"dependencies":[],
"package_uid":"pkg:maven/foo?uuid=fixed-uid-done-for-testing-5642512d1758",
"package_uid":"pkg:maven/Foo?uuid=fixed-uid-done-for-testing-5642512d1758",
"datasource_id":null,
"purl":"pkg:maven/foo",
"purl":"pkg:maven/Foo",
"repository_homepage_url":null,
"repository_download_url":null,
"api_data_url":null,
Expand Down
14 changes: 0 additions & 14 deletions packagedb/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,19 +193,6 @@ def filter(self, qs, value):
return qs.filter(q)


class PackageSearchFilter(Filter):
def filter(self, qs, value):
try:
request = self.parent.request
except AttributeError:
return None

if not value:
return qs

return Package.objects.filter(search_vector=value)


class PackageFilter(FilterSet):
type = django_filters.CharFilter(
lookup_expr="iexact",
Expand All @@ -229,7 +216,6 @@ class PackageFilter(FilterSet):
help_text="Exact SHA1. Multi-value supported.",
)
purl = MultiplePackageURLFilter(label='Package URL')
search = PackageSearchFilter(label='Search')

sort = OrderingFilter(fields=[
'type',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Generated by Django 4.1.2 on 2023-10-31 20:44

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("packagedb", "0078_alter_package_release_date"),
]

operations = [
migrations.RemoveIndex(
model_name="package",
name="packagedb_p_search__8d33bb_gin",
),
migrations.RemoveField(
model_name="package",
name="search_vector",
),
migrations.AlterField(
model_name="package",
name="name",
field=models.CharField(
blank=True, help_text="Name of the package.", max_length=100
),
),
migrations.AlterField(
model_name="package",
name="namespace",
field=models.CharField(
blank=True,
help_text="Package name prefix, such as Maven groupid, Docker image owner, GitHub user or organization, etc.",
max_length=255,
),
),
migrations.AlterField(
model_name="package",
name="qualifiers",
field=models.CharField(
blank=True,
help_text="Extra qualifying data for a package such as the name of an OS, architecture, distro, etc.",
max_length=1024,
),
),
migrations.AlterField(
model_name="package",
name="subpath",
field=models.CharField(
blank=True,
help_text="Extra subpath within a package, relative to the package root.",
max_length=200,
),
),
migrations.AlterField(
model_name="package",
name="type",
field=models.CharField(
blank=True,
help_text="A short code to identify the type of this package. For example: gem for a Rubygem, docker for a container, pypi for a Python Wheel or Egg, maven for a Maven Jar, deb for a Debian package, etc.",
max_length=16,
),
),
]
21 changes: 0 additions & 21 deletions packagedb/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
import uuid

from django.contrib.postgres.fields import ArrayField
from django.contrib.postgres.indexes import GinIndex
from django.contrib.postgres.search import SearchVectorField
from django.core.paginator import Paginator
from django.db import models
from django.utils import timezone
Expand Down Expand Up @@ -465,21 +463,6 @@ class Package(
uuid = models.UUIDField(
verbose_name=_("UUID"), default=uuid.uuid4, unique=True, editable=False
)
type = LowerCaseField(
max_length=16,
)
namespace = LowerCaseField(
max_length=255,
)
name = LowerCaseField(
max_length=100,
)
qualifiers = LowerCaseField(
max_length=1024,
)
subpath = LowerCaseField(
max_length=200,
)
mining_level = models.PositiveIntegerField(
default=0,
help_text=_('A numeric indication of the highest depth and breadth '
Expand Down Expand Up @@ -546,8 +529,6 @@ class Package(
),
)

search_vector = SearchVectorField(null=True)

objects = PackageQuerySet.as_manager()

# TODO: Think about ordering, unique together, indexes, etc.
Expand All @@ -565,8 +546,6 @@ class Meta:
)
]
indexes = [
# GIN index for search performance increase
GinIndex(fields=['search_vector']),
# multicolumn index for search on a whole `purl`
models.Index(fields=[
'type', 'namespace', 'name', 'version', 'qualifiers', 'subpath'
Expand Down
21 changes: 0 additions & 21 deletions packagedb/signals.py

This file was deleted.

34 changes: 4 additions & 30 deletions packagedb/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import json
import os

from django.contrib.postgres.search import SearchVector
from django.test import TestCase
from django.urls import reverse
from django.utils import timezone
Expand Down Expand Up @@ -363,7 +362,7 @@ def test_package_api_list_endpoint_filter(self):
def test_package_api_list_endpoint_filter_by_purl_fields_ignores_case(self):
for key, value in self.package_data.items():
# Skip non-purl fields
if key not in ['type', 'namespace', 'name', 'version', 'qualifiers', 'subpath']:
if key not in ['type', 'namespace', 'name']:
continue

response = self.client.get('/api/packages/?{}={}'.format(key, value.lower()))
Expand All @@ -374,31 +373,6 @@ def test_package_api_list_endpoint_filter_by_purl_fields_ignores_case(self):
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(1, response.data.get('count'))

def test_package_api_list_endpoint_search(self):
# Populate the search vector field. This is done via Django signals
# outside of the tests.
Package.objects.filter(uuid=self.package.uuid).update(
search_vector=SearchVector('namespace', 'name', 'version', 'download_url')
)

# Create a dummy package to verify search filter works.
Package.objects.create(
type='generic',
namespace='dummy-namespace',
name='dummy-name',
version='12.35',
download_url='https://dummy.com/dummy'
)

for key, value in self.package_data.items():
# Skip since we only search on one field
if key not in ['namespace', 'name', 'version', 'download_url']:
continue

response = self.client.get('/api/packages/?search={}'.format(value))
assert response.status_code == status.HTTP_200_OK
assert response.data.get('count') == 1

def test_package_api_retrieve_endpoint(self):
response = self.client.get('/api/packages/{}/'.format(self.package.uuid))
self.assertEqual(response.status_code, status.HTTP_200_OK)
Expand All @@ -410,7 +384,7 @@ def test_package_api_retrieve_endpoint(self):
continue

if key in ['type', 'namespace', 'name', 'version', 'qualifiers', 'subpath']:
self.assertEqual(value.lower(), getattr(self.package, key))
self.assertEqual(value, getattr(self.package, key))
continue

if key == 'history':
Expand Down Expand Up @@ -666,7 +640,7 @@ def test_reindex_package(self):
self.assertEqual('error', self.scannableuri.index_error)
self.assertEqual(self.scan_request_date, self.scannableuri.scan_request_date)
response = self.client.get(f'/api/packages/{self.package.uuid}/reindex_package/')
self.assertEqual('pkg:maven/sample/baz@90.12 has been queued for reindexing', response.data['status'])
self.assertEqual('pkg:maven/sample/Baz@90.12 has been queued for reindexing', response.data['status'])
self.scannableuri.refresh_from_db()
self.assertEqual(True, self.scannableuri.rescan_uri)
self.assertEqual(100, self.scannableuri.priority)
Expand All @@ -690,7 +664,7 @@ def test_reindex_packages_basic(self):
self.assertEqual('error', self.scannableuri2.index_error)
self.assertEqual(self.scan_request_date2, self.scannableuri2.scan_request_date)
existing_purls = [
'pkg:maven/sample/baz@90.12',
'pkg:maven/sample/Baz@90.12',
'pkg:npm/example/[email protected]',
]
nonexistent_purls = [
Expand Down
12 changes: 0 additions & 12 deletions packagedb/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,6 @@ def setUp(self):
self.created_package = Package.objects.create(**self.created_package_data)
self.inserted_package = Package.objects.insert(**self.inserted_package_data)

def test_package_creation(self):
test_package = Package.objects.get(download_url=self.created_package_download_url)
self.assertIsNotNone(test_package)
for key, val in self.created_package_data.items():
self.assertEqual(val.lower(), getattr(test_package, key))

def test_package_insertion(self):
test_package = Package.objects.get(download_url=self.inserted_package_download_url)
self.assertIsNotNone(test_package)
for key, val in self.inserted_package_data.items():
self.assertEqual(val.lower(), getattr(test_package, key))

def test_package_download_url_is_unique(self):
self.assertIsNone(Package.objects.insert(download_url=self.created_package_download_url))
self.assertIsNone(Package.objects.insert(download_url=self.inserted_package_download_url))
Expand Down
Loading
Loading