class FakeBoostedSearch(FakeSearch): boosters = [ search.GaussDecay('a_num_field', 10, 20, offset=5, decay=0.5), search.ExpDecay( 'another_field', 20, scale=30, offset=5, decay=0.5), search.LinearDecay('last_field', 30, 40, offset=5, decay=0.5), ]
class FakeBoostedSearch(FakeSearch): boosters = [ search.GaussDecay('a_num_field', get_10, get_20, offset=get_5, decay=get_dot5), search.ExpDecay('another_field', get_20, scale=get_30, offset=get_5, decay=get_dot5), search.LinearDecay('last_field', get_30, get_40, offset=get_5, decay=get_dot5), ]
class FakeBoostedSearch(FakeSearch): boosters = [ search.GaussDecay('a_num_field', 10), search.ExpDecay('another_field', 20), search.LinearDecay('last_field', 30), ]
class OrganizationSearch(search.ModelSearchAdapter): model = Organization fuzzy = True fields = ( 'name^6', 'acronym^6', 'description', ) sorts = { 'name': search.Sort('name.raw'), 'reuses': search.Sort('metrics.reuses'), 'datasets': search.Sort('metrics.datasets'), 'followers': search.Sort('metrics.followers'), 'views': search.Sort('metrics.views'), 'created': search.Sort('created'), } facets = { 'reuses': search.RangeFacet('metrics.reuses'), 'badge': search.TermFacet('badges', labelizer=organization_badge_labelizer), 'permitted_reuses': search.RangeFacet('metrics.permitted_reuses'), 'datasets': search.RangeFacet('metrics.datasets'), 'followers': search.RangeFacet('metrics.followers'), } mapping = { 'properties': { 'name': { 'type': 'string', 'analyzer': search.i18n_analyzer, 'fields': { 'raw': { 'type': 'string', 'index': 'not_analyzed' } } }, 'acronym': { 'type': 'string', 'index': 'not_analyzed', }, 'description': { 'type': 'string', 'analyzer': search.i18n_analyzer }, 'badges': { 'type': 'string', 'index_name': 'badges', 'index': 'not_analyzed' }, 'url': { 'type': 'string' }, 'created': { 'type': 'date', 'format': 'date_hour_minute_second' }, 'metrics': search.metrics_mapping(Organization), 'org_suggest': { 'type': 'completion', 'index_analyzer': 'simple', 'search_analyzer': 'simple', 'payloads': True, }, } } boosters = [ search.GaussDecay('metrics.followers', max_followers, decay=0.8), search.GaussDecay('metrics.reuses', max_reuses, decay=0.9), search.GaussDecay('metrics.datasets', max_datasets, decay=0.9), ] @classmethod def is_indexable(cls, org): return org.deleted is None @classmethod def serialize(cls, organization): completions = cls.completer_tokenize(organization.name) completions.append(organization.id) if organization.acronym: completions.append(organization.acronym) return { 'name': organization.name, 'acronym': organization.acronym, 'description': organization.description, 'url': organization.url, 'metrics': organization.metrics, 'badges': [badge.kind for badge in organization.badges], 'created': organization.created_at.strftime('%Y-%m-%dT%H:%M:%S'), 'org_suggest': { 'input': completions, 'output': str(organization.id), 'payload': { 'name': organization.name, 'acronym': organization.acronym, 'image_url': organization.logo(40), 'slug': organization.slug, }, } }
class OrganizationSearch(search.ModelSearchAdapter): model = Organization fuzzy = True class Meta: doc_type = 'Organization' name = String(analyzer=search.i18n_analyzer, fields={'raw': String(index='not_analyzed')}) acronym = String(index='not_analyzed') description = String(analyzer=search.i18n_analyzer) badges = String(index='not_analyzed') url = String(index='not_analyzed') created = Date(format='date_hour_minute_second') metrics = search.metrics_mapping_for(Organization) org_suggest = Completion(analyzer=simple, search_analyzer=simple, payloads=True) sorts = { 'name': 'name.raw', 'reuses': 'metrics.reuses', 'datasets': 'metrics.datasets', 'followers': 'metrics.followers', 'views': 'metrics.views', 'created': 'created', 'last_modified': 'last_modified', } facets = { 'reuses': RangeFacet(field='metrics.reuses', ranges=[('none', (None, 1)), ('few', (1, 5)), ('many', (5, None))], labels={ 'none': _('No reuses'), 'few': _('Few reuses'), 'many': _('Many reuses'), }), 'badge': TermsFacet(field='badges', labelizer=organization_badge_labelizer), 'datasets': RangeFacet(field='metrics.datasets', ranges=[('none', (None, 1)), ('few', (1, 5)), ('many', (5, None))], labels={ 'none': _('No datasets'), 'few': _('Few datasets'), 'many': _('Many datasets'), }), 'followers': RangeFacet(field='metrics.followers', ranges=[('none', (None, 1)), ('few', (1, 5)), ('many', (5, None))], labels={ 'none': _('No followers'), 'few': _('Few followers'), 'many': _('Many followers'), }), } boosters = [ search.GaussDecay('metrics.followers', max_followers, decay=lazy('followers_decay')), search.GaussDecay('metrics.reuses', max_reuses, decay=lazy('reuses_decay')), search.GaussDecay('metrics.datasets', max_datasets, decay=lazy('datasets_decay')), ] @classmethod def is_indexable(cls, org): return org.deleted is None @classmethod def serialize(cls, organization): completions = cls.completer_tokenize(organization.name) completions.append(organization.id) if organization.acronym: completions.append(organization.acronym) return { 'name': organization.name, 'acronym': organization.acronym, 'description': organization.description, 'url': organization.url, 'metrics': organization.metrics, 'badges': [badge.kind for badge in organization.badges], 'created': to_iso_datetime(organization.created_at), 'org_suggest': { 'input': completions, 'output': str(organization.id), 'payload': { 'name': organization.name, 'acronym': organization.acronym, 'image_url': organization.logo(40, external=True), 'slug': organization.slug, }, } }