diff --git a/arkindex/documents/api.py b/arkindex/documents/api.py index e8413386dc67b463e31a96dc64904a86c7c1f0f1..116b1b826324d48e8c26b8afb13cac88cf65aad3 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 14b4e22b173d32beeaf784a2079fc29fc7a6c168..8542f78eafca2b5b6768712ffa559cfb7d6878ab 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 9073b5ba2c0761c630b2974778c5f6b0957d196f..48af56721b499540bc965f9cb081141e76409e32 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 8ce0d2476cde78f2d40d375def58d191c132ea6a..6be0cea4ffa42ed1dbb3cc28beb6ee3b38b431db 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": {