From 1a9d7f94098e2bc2f682edac453adbfafe0fc54a Mon Sep 17 00:00:00 2001 From: Erwan Rouchet <rouchet@teklia.com> Date: Mon, 2 Jul 2018 13:00:56 +0000 Subject: [PATCH] Frontend fixes --- arkindex/documents/api.py | 6 ++++-- arkindex/documents/serializers.py | 6 ++++++ arkindex/templates/elastic/search_acts.json | 7 +++++++ arkindex/templates/elastic/search_transcriptions.json | 7 +++++++ 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/arkindex/documents/api.py b/arkindex/documents/api.py index e8413386dc..116b1b8263 100644 --- a/arkindex/documents/api.py +++ b/arkindex/documents/api.py @@ -251,10 +251,11 @@ class TranscriptionSearch(ListAPIView): def get_queryset(self): query = self.request.query_params.get('q') corpus = self.request.query_params.get('corpus') + type = self.request.query_params.get('type') return ESQuerySet( query=ESQuerySet.make_query( 'elastic/search_transcriptions.json', - ctx={'query': query, 'corpus': corpus}, + ctx={'query': query, 'corpus': corpus, 'type': type}, ), sort={"score": {"order": "desc", "mode": "max"}}, es_index=settings.ES_INDEX_TRANSCRIPTIONS, @@ -272,11 +273,12 @@ class ActSearch(ListAPIView): def get_queryset(self): query = self.request.query_params.get('q') corpus = self.request.query_params.get('corpus') + type = self.request.query_params.get('type') return ESQuerySet( _source=False, query=ESQuerySet.make_query( 'elastic/search_acts.json', - ctx={'query': query, 'corpus': corpus}, + ctx={'query': query, 'corpus': corpus, 'type': type}, ), es_index=settings.ES_INDEX_ACTS, es_type=Act.INDEX_TYPE, diff --git a/arkindex/documents/serializers.py b/arkindex/documents/serializers.py index 14b4e22b17..8542f78eaf 100644 --- a/arkindex/documents/serializers.py +++ b/arkindex/documents/serializers.py @@ -15,10 +15,14 @@ class TranscriptionSerializer(serializers.ModelSerializer): Serialises a Transcription issued from a search """ + + type = EnumField(ElementType) + class Meta: model = Transcription fields = ( 'id', + 'type', 'text', 'line', 'score', @@ -200,6 +204,7 @@ class TranscriptionSearchResultSerializer(serializers.ModelSerializer): """ Link between objects & their search indexation """ + type = EnumField(ElementType) zone = ZoneSerializer() parents = serializers.ListField( child=serializers.ListField( @@ -212,6 +217,7 @@ class TranscriptionSearchResultSerializer(serializers.ModelSerializer): model = Transcription fields = ( 'id', + 'type', 'text', 'line', 'score', diff --git a/arkindex/templates/elastic/search_acts.json b/arkindex/templates/elastic/search_acts.json index 9073b5ba2c..48af56721b 100644 --- a/arkindex/templates/elastic/search_acts.json +++ b/arkindex/templates/elastic/search_acts.json @@ -22,6 +22,13 @@ } }, {% endif %} + {% if type %} + { + "match": { + "transcriptions.type": "{{ type }}" + } + }, + {% endif %} { "match": { "transcriptions.text": "{{ query }}" diff --git a/arkindex/templates/elastic/search_transcriptions.json b/arkindex/templates/elastic/search_transcriptions.json index 8ce0d2476c..6be0cea4ff 100644 --- a/arkindex/templates/elastic/search_transcriptions.json +++ b/arkindex/templates/elastic/search_transcriptions.json @@ -13,6 +13,13 @@ } }, {% endif %} + {% if type %} + { + "match": { + "type": "{{ type }}" + } + }, + {% endif %} { "range": { "score": { -- GitLab