Skip to content

Commit

Permalink
Add zscore to Project document mapping (#5252)
Browse files Browse the repository at this point in the history
Add zscore to `_project_docs` query to populate on reindex
  • Loading branch information
yeraydiazdiaz authored and ewdurbin committed Jan 6, 2019
1 parent 1656da5 commit 0475020
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
2 changes: 2 additions & 0 deletions tests/unit/packaging/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def test_build_search():
platform="any platform",
created=datetime.datetime(1956, 1, 31),
classifiers=["Alpha", "Beta"],
zscore=None,
)
obj = Project.from_db(release)

Expand All @@ -54,3 +55,4 @@ def test_build_search():
assert obj["platform"] == "any platform"
assert obj["created"] == datetime.datetime(1956, 1, 31)
assert obj["classifiers"] == ["Alpha", "Beta"]
assert obj["zscore"] is None
4 changes: 3 additions & 1 deletion warehouse/packaging/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import packaging.version

from elasticsearch_dsl import Date, Document, Keyword, Text, analyzer
from elasticsearch_dsl import Date, Document, Float, Keyword, Text, analyzer

from warehouse.search.utils import doc_type

Expand Down Expand Up @@ -49,6 +49,7 @@ class Project(Document):
platform = Keyword()
created = Date()
classifiers = Keyword(multi=True)
zscore = Float()

@classmethod
def from_db(cls, release):
Expand All @@ -71,5 +72,6 @@ def from_db(cls, release):
obj["platform"] = release.platform
obj["created"] = release.created
obj["classifiers"] = release.classifiers
obj["zscore"] = release.zscore

return obj
1 change: 1 addition & 0 deletions warehouse/search/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def _project_docs(db, project_name=None):
classifiers,
Project.normalized_name,
Project.name,
Project.zscore,
)
.select_from(releases_list)
.join(Release, Release.id == releases_list.c.id)
Expand Down

0 comments on commit 0475020

Please sign in to comment.