-
Notifications
You must be signed in to change notification settings - Fork 21
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
Person suggest #1972
Open
yattias
wants to merge
3
commits into
master
Choose a base branch
from
person-suggest
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Person suggest #1972
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 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 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 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 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 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,49 @@ | ||
from django_elasticsearch_dsl_drf.filter_backends import ( | ||
OrderingFilterBackend, | ||
SuggesterFilterBackend, | ||
) | ||
from django_elasticsearch_dsl_drf.pagination import LimitOffsetPagination | ||
from django_elasticsearch_dsl_drf.viewsets import DocumentViewSet | ||
|
||
from search.backends.multi_match_filter import MultiMatchSearchFilterBackend | ||
from search.documents.person import PersonDocument | ||
from search.serializers.person import PersonDocumentSerializer | ||
from utils.permissions import ReadOnly | ||
|
||
|
||
class PersonSuggesterDocumentView(DocumentViewSet): | ||
document = PersonDocument | ||
permission_classes = [ReadOnly] | ||
serializer_class = PersonDocumentSerializer | ||
pagination_class = LimitOffsetPagination | ||
lookup_field = "id" | ||
filter_backends = [ | ||
MultiMatchSearchFilterBackend, | ||
SuggesterFilterBackend, | ||
OrderingFilterBackend, | ||
] | ||
|
||
ordering = ("-author_score",) | ||
ordering_fields = { | ||
"id": "id", | ||
"full_name": "full_name", | ||
"author_score": "author_score", | ||
} | ||
|
||
filter_fields = { | ||
"full_name": {"field": "full_name", "lookups": ["match"]}, | ||
} | ||
|
||
multi_match_search_fields = { | ||
"full_name": {"field": "full_name", "boost": 1}, | ||
} | ||
|
||
suggester_fields = { | ||
"suggestion_phrases": { | ||
"field": "suggestion_phrases", | ||
"suggesters": ["completion"], | ||
"options": { | ||
"size": 25, | ||
}, | ||
}, | ||
} |
This file contains 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 |
---|---|---|
|
@@ -117,6 +117,39 @@ | |
f"{university_city}" | ||
) | ||
|
||
def build_headline(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move this method from serializer to model so that it can be used by elasticsearch |
||
from collections import Counter | ||
|
||
if self.headline: | ||
return self.headline | ||
|
||
try: | ||
all_topics = [] | ||
authored_papers = self.authored_papers.all() | ||
|
||
for p in authored_papers: | ||
unified_document = p.unified_document | ||
all_topics += list(unified_document.topics.all()) | ||
|
||
topic_counts = Counter(all_topics) | ||
|
||
# Sort topics by frequency | ||
sorted_topics = sorted( | ||
topic_counts.items(), key=lambda x: x[1], reverse=True | ||
) | ||
|
||
# Extract topics from sorted list | ||
sorted_topics = [topic for topic, _ in sorted_topics] | ||
|
||
if not sorted_topics: | ||
return None | ||
|
||
return { | ||
"title": "Author with expertise in " + sorted_topics[0].display_name | ||
} | ||
except Exception: | ||
return None | ||
|
||
@property | ||
def full_name(self): | ||
return self.first_name + " " + self.last_name | ||
|
This file contains 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.
I'll remove this before merging