@@ -254,6 +254,10 @@ class CorpusConfiguration(models.Model):
254254 default = False ,
255255 help_text = 'whether this corpus has word models' ,
256256 )
257+ has_named_entities = models .BooleanField (
258+ default = False ,
259+ help_text = 'whether this corpus has named entity annotations' ,
260+ )
257261 default_sort = models .JSONField (
258262 blank = True ,
259263 validators = [validate_sort_configuration ],
@@ -298,34 +302,27 @@ def clean(self):
298302 ])
299303
300304 @property
301- def has_named_entities (self ):
302- from es .search import total_hits
305+ def visible_fields (self ) -> models .QuerySet ['Field' ]:
306+ fields = self .fields .all ()
307+
308+ if not self .has_named_entities :
309+ fields = fields .exclude (name__endswith = ':ner-kw' ).exclude (name__endswith = ':ner' )
310+
311+ return fields
312+
313+
314+ class FieldDisplayTypes (models .TextChoices ):
315+ TEXT_CONTENT = ('text_content' , 'text content' )
316+ TEXT = (MappingType .TEXT .value , 'text' )
317+ KEYWORD = (MappingType .KEYWORD .value , 'keyword' )
318+ DATE = (MappingType .DATE .value , 'date' )
319+ DATE_RANGE = (MappingType .DATE_RANGE .value , 'date_range' )
320+ INTEGER = (MappingType .INTEGER .value , 'integer' )
321+ FLOAT = (MappingType .FLOAT .value , 'float' )
322+ BOOLEAN = (MappingType .BOOLEAN .value , 'boolean' )
323+ GEO_POINT = (MappingType .GEO_POINT .value , 'geo_point' )
324+ URL = ('url' , 'url' )
303325
304- client = elasticsearch (self .corpus .name )
305- try :
306- # we check if any fields exist for filtering named entities
307- ner_exists = client .search (
308- index = self .es_index , query = {"exists" : {"field" : "*:ner-kw" }}, size = 0
309- )
310- if total_hits (ner_exists ):
311- return True
312- except :
313- return False
314- return False
315-
316-
317- FIELD_DISPLAY_TYPES = [
318- ('text_content' , 'text content' ),
319- (MappingType .TEXT .value , 'text' ),
320- (MappingType .KEYWORD .value , 'keyword' ),
321- (MappingType .DATE .value , 'date' ),
322- (MappingType .DATE_RANGE .value , 'date_range' ),
323- (MappingType .INTEGER .value , 'integer' ),
324- (MappingType .FLOAT .value , 'float' ),
325- (MappingType .BOOLEAN .value , 'boolean' ),
326- (MappingType .GEO_POINT .value , 'geo_point' ),
327- ('url' , 'url' ),
328- ]
329326
330327FIELD_VISUALIZATIONS = [
331328 (VisualizationType .RESULTS_COUNT .value , 'Number of results' ),
@@ -364,7 +361,7 @@ class Field(models.Model):
364361 )
365362 display_type = models .CharField (
366363 max_length = 16 ,
367- choices = FIELD_DISPLAY_TYPES ,
364+ choices = FieldDisplayTypes . choices ,
368365 help_text = 'as what type of data this field is rendered in the interface' ,
369366 )
370367 description = models .CharField (
0 commit comments