Exemple #1
0
def sector_field():
    """Sector field."""
    ancestors = Object(properties={
        'id': Keyword(),
    }, )

    return Object(properties={
        'id': Keyword(),
        'name': NormalizedKeyword(),
        'ancestors': ancestors,
    }, )
Exemple #2
0
def _export_country_field():
    return Object(properties={
        'id':
        Keyword(index=False),
        'country':
        Object(properties={
            'id': Keyword(),
            'name': Text(index=False),
        }, ),
        'status':
        Text(index=False),
    }, )
Exemple #3
0
def interaction_field():
    """Interaction field with id, subject and date."""
    return Object(properties={
        'id': Keyword(),
        'subject': Text(index=False),
        'date': Date(),
    }, )
Exemple #4
0
def _related_investment_project_field():
    """Field for a related investment project."""
    return Object(
        properties={
            'id': Keyword(),
            'name': fields.NormalizedKeyword(),
            'project_code': fields.NormalizedKeyword(),
        })
Exemple #5
0
def _contact_field():
    return Object(properties={
        'id': Keyword(index=False),
        'first_name': Text(index=False),
        'last_name': Text(index=False),
        'name': Text(fields={
            'trigram': TrigramText(),
        }, ),
    }, )
Exemple #6
0
def _adviser_field_with_indexed_id():
    return Object(
        properties={
            'id': Keyword(),
            'first_name': Text(index=False),
            'last_name': Text(index=False),
            'name': Text(index=False),
        },
    )
Exemple #7
0
def id_name_partial_field():
    """Object field with id and name sub-fields, and with partial matching on name."""
    return Object(properties={
        'id':
        Keyword(),
        'name':
        Text(fields={
            'keyword': NormalizedKeyword(),
            'trigram': TrigramText(),
        }, ),
    }, )
Exemple #8
0
def address_field():
    """Address field as nested object."""
    return Object(properties={
        'line_1': TextWithTrigram(),
        'line_2': TextWithTrigram(),
        'town': TextWithTrigram(),
        'county': TextWithTrigram(),
        'area': area_field(),
        'postcode': TextWithTrigram(),
        'country': country_field(),
    }, )
Exemple #9
0
def company_field():
    """Company field with id, name, trading_names and trigrams."""
    return Object(properties={
        'id':
        Keyword(),
        'name':
        Text(fields={
            'trigram': TrigramText(),
            'keyword': NormalizedKeyword(),
        }, ),
        'trading_names':
        TextWithTrigram(),
    }, )
Exemple #10
0
def contact_or_adviser_field(include_dit_team=False):
    """Object field for advisers and contacts."""
    props = {
        'id':
        Keyword(),
        'first_name':
        NormalizedKeyword(),
        'last_name':
        NormalizedKeyword(),
        'name':
        Text(fields={
            'keyword': NormalizedKeyword(),
            'trigram': TrigramText(),
        }, ),
    }

    if include_dit_team:
        props['dit_team'] = id_name_field()

    return Object(properties=props)
Exemple #11
0
def id_unindexed_name_field():
    """Object field with id and unindexed name sub-fields."""
    return Object(properties={
        'id': Keyword(),
        'name': Keyword(index=False),
    }, )
Exemple #12
0
def id_name_field():
    """Object field with id and name sub-fields."""
    return Object(properties={
        'id': Keyword(),
        'name': NormalizedKeyword(),
    }, )
Exemple #13
0
def area_field():
    """Area field with id, name and trigram."""
    return Object(properties={
        'id': Keyword(),
        'name': TextWithTrigram(),
    }, )
Exemple #14
0
class Interaction(BaseSearchModel):
    """OpenSearch representation of Interaction model."""

    id = Keyword()
    company = fields.company_field()
    companies = fields.company_field()
    company_sector = fields.sector_field()
    company_one_list_group_tier = fields.id_unindexed_name_field()
    communication_channel = fields.id_unindexed_name_field()
    contacts = _contact_field()
    created_on = Date()
    date = Date()
    dit_participants = Object(_DITParticipant)
    event = fields.id_name_partial_field()
    investment_project = fields.id_unindexed_name_field()
    investment_project_sector = fields.sector_field()
    is_event = Boolean(index=False)
    grant_amount_offered = Double(index=False)
    kind = Keyword()
    modified_on = Date()
    net_company_receipt = Double(index=False)
    notes = fields.Text(index=False)
    policy_areas = fields.id_unindexed_name_field()
    policy_issue_types = fields.id_unindexed_name_field()
    service = fields.id_name_partial_field()
    service_delivery_status = fields.id_unindexed_name_field()
    subject = fields.NormalizedKeyword(fields={
        'english': fields.EnglishText(),
    }, )
    was_policy_feedback_provided = Boolean()
    were_countries_discussed = Boolean()
    export_countries = _export_country_field()

    MAPPINGS = {
        'company': dict_utils.company_dict,
        'companies': _companies_list,
        'communication_channel': dict_utils.id_name_dict,
        'contacts': dict_utils.contact_or_adviser_list_of_dicts,
        'dit_participants': _dit_participant_list,
        'export_countries': _export_countries_list,
        'event': dict_utils.id_name_dict,
        'investment_project': dict_utils.id_name_dict,
        'policy_areas': dict_utils.id_name_list_of_dicts,
        'policy_issue_types': dict_utils.id_name_list_of_dicts,
        'service': dict_utils.id_name_dict,
        'service_delivery_status': dict_utils.id_name_dict,
    }

    COMPUTED_MAPPINGS = {
        'company_sector':
        dict_utils.computed_nested_sector_dict('company.sector'),
        'company_one_list_group_tier':
        lambda obj: dict_utils.id_name_dict(
            obj.company.get_one_list_group_tier() if obj.company else None, ),
        'investment_project_sector':
        dict_utils.computed_nested_sector_dict('investment_project.sector', ),
        'is_event':
        attrgetter('is_event'),
    }

    SEARCH_FIELDS = (
        'id',
        'company.name',
        'company.name.trigram',
        'companies.name',
        'companies.name.trigram',
        'contacts.name',  # to find 2-letter words
        'contacts.name.trigram',
        'event.name',
        'event.name.trigram',
        'service.name',
        'service.name.trigram',
        'subject.english',
        'dit_participants.adviser.name',
        'dit_participants.adviser.name.trigram',
        'dit_participants.team.name',
        'dit_participants.team.name.trigram',
    )
Exemple #15
0
class _DITParticipant(InnerDoc):
    adviser = Object(Person)
    team = Object(IDNameTrigram)
Exemple #16
0
def ch_company_field():
    """Object field with id and company_number sub-fields."""
    return Object(properties={
        'id': Keyword(),
        'company_number': NormalizedKeyword(),
    })
Exemple #17
0
def country_field():
    """Country field with id, name and trigram."""
    return Object(properties={
        'id': Keyword(),
        'name': TextWithTrigram(),
    }, )
Exemple #18
0
class InvestmentProject(BaseSearchModel):
    """OpenSearch representation of InvestmentProject."""

    id = Keyword()
    actual_land_date = Date()
    actual_uk_regions = fields.id_name_field()
    address_1 = Text()
    address_2 = Text()
    address_town = fields.NormalizedKeyword()
    address_postcode = Text()
    approved_commitment_to_invest = Boolean()
    approved_fdi = Boolean()
    approved_good_value = Boolean()
    approved_high_value = Boolean()
    approved_landed = Boolean()
    approved_non_fdi = Boolean()
    allow_blank_estimated_land_date = Boolean(index=False)
    allow_blank_possible_uk_regions = Boolean(index=False)
    anonymous_description = fields.EnglishText()
    archived = Boolean()
    archived_by = fields.contact_or_adviser_field()
    archived_on = Date()
    archived_reason = Text()
    associated_non_fdi_r_and_d_project = _related_investment_project_field()
    average_salary = fields.id_name_field()
    business_activities = fields.id_name_field()
    client_cannot_provide_foreign_investment = Boolean()
    client_cannot_provide_total_investment = Boolean()
    client_contacts = fields.contact_or_adviser_field()
    client_relationship_manager = fields.contact_or_adviser_field(
        include_dit_team=True)
    client_requirements = Text(index=False)
    comments = fields.EnglishText()
    country_investment_originates_from = fields.id_name_field()
    country_lost_to = Object(properties={
        'id': Keyword(index=False),
        'name': Text(index=False),
    }, )
    created_on = Date()
    created_by = fields.contact_or_adviser_field(include_dit_team=True)
    date_abandoned = Date()
    date_lost = Date()
    delivery_partners = fields.id_name_field()
    description = fields.EnglishText()
    estimated_land_date = Date()
    export_revenue = Boolean()
    fdi_type = fields.id_name_field()
    fdi_value = fields.id_name_field()
    foreign_equity_investment = Double()
    government_assistance = Boolean()
    incomplete_fields = Text()
    intermediate_company = fields.id_name_field()
    investor_company = fields.id_name_partial_field()
    investor_company_country = fields.id_name_field()
    investment_type = fields.id_name_field()
    investor_type = fields.id_name_field()
    level_of_involvement = fields.id_name_field()
    likelihood_to_land = fields.id_name_field()
    project_assurance_adviser = fields.contact_or_adviser_field(
        include_dit_team=True)
    project_manager = fields.contact_or_adviser_field(include_dit_team=True)
    name = Text(fields={
        'keyword': fields.NormalizedKeyword(),
        'trigram': fields.TrigramText(),
    }, )
    new_tech_to_uk = Boolean()
    non_fdi_r_and_d_budget = Boolean()
    number_new_jobs = Integer()
    number_safeguarded_jobs = Long()
    modified_on = Date()
    project_arrived_in_triage_on = Date()
    project_code = fields.NormalizedKeyword(fields={
        'trigram': fields.TrigramText(),
    }, )
    proposal_deadline = Date()
    other_business_activity = Text(index=False)
    quotable_as_public_case_study = Boolean()
    r_and_d_budget = Boolean()
    reason_abandoned = Text(index=False)
    reason_delayed = Text(index=False)
    reason_lost = Text(index=False)
    referral_source_activity = fields.id_name_field()
    referral_source_activity_event = fields.NormalizedKeyword()
    referral_source_activity_marketing = fields.id_name_field()
    referral_source_activity_website = fields.id_name_field()
    referral_source_adviser = Object(properties={
        'id': Keyword(index=False),
        'first_name': Text(index=False),
        'last_name': Text(index=False),
        'name': Text(index=False),
    }, )
    sector = fields.sector_field()
    site_decided = Boolean()
    some_new_jobs = Boolean()
    specific_programme = fields.id_name_field()
    stage = fields.id_name_field()
    status = fields.NormalizedKeyword()
    team_members = fields.contact_or_adviser_field(include_dit_team=True)
    total_investment = Double()
    uk_company = fields.id_name_partial_field()
    uk_company_decided = Boolean()
    uk_region_locations = fields.id_name_field()
    will_new_jobs_last_two_years = Boolean()
    level_of_involvement_simplified = Keyword()
    latest_interaction = fields.interaction_field()

    gross_value_added = Double()

    MAPPINGS = {
        'actual_uk_regions':
        lambda col: [dict_utils.id_name_dict(c) for c in col.all()],
        'archived_by':
        dict_utils.contact_or_adviser_dict,
        'associated_non_fdi_r_and_d_project':
        dict_utils.investment_project_dict,
        'average_salary':
        dict_utils.id_name_dict,
        'business_activities':
        lambda col: [dict_utils.id_name_dict(c) for c in col.all()],
        'client_contacts':
        lambda col: [dict_utils.contact_or_adviser_dict(c) for c in col.all()],
        'client_relationship_manager':
        dict_utils.adviser_dict_with_team,
        'country_lost_to':
        dict_utils.id_name_dict,
        'country_investment_originates_from':
        dict_utils.id_name_dict,
        'created_by':
        dict_utils.adviser_dict_with_team,
        'delivery_partners':
        lambda col: [dict_utils.id_name_dict(c) for c in col.all()],
        'fdi_type':
        dict_utils.id_name_dict,
        'fdi_value':
        dict_utils.id_name_dict,
        'intermediate_company':
        dict_utils.id_name_dict,
        'investment_type':
        dict_utils.id_name_dict,
        'investor_company':
        dict_utils.id_name_dict,
        'investor_company_country':
        dict_utils.id_name_dict,
        'investor_type':
        dict_utils.id_name_dict,
        'latest_interaction':
        dict_utils.interaction_dict,
        'level_of_involvement':
        dict_utils.id_name_dict,
        'likelihood_to_land':
        dict_utils.id_name_dict,
        'project_assurance_adviser':
        dict_utils.adviser_dict_with_team,
        'project_code':
        str,
        'project_manager':
        dict_utils.adviser_dict_with_team,
        'referral_source_activity':
        dict_utils.id_name_dict,
        'referral_source_activity_marketing':
        dict_utils.id_name_dict,
        'referral_source_activity_website':
        dict_utils.id_name_dict,
        'referral_source_adviser':
        dict_utils.contact_or_adviser_dict,
        'sector':
        dict_utils.sector_dict,
        'specific_programme':
        dict_utils.id_name_dict,
        'stage':
        dict_utils.id_name_dict,
        'team_members':
        lambda col: [
            dict_utils.contact_or_adviser_dict(c.adviser,
                                               include_dit_team=True)
            for c in col.all()
        ],
        'uk_company':
        dict_utils.id_name_dict,
        'uk_region_locations':
        lambda col: [dict_utils.id_name_dict(c) for c in col.all()],
    }

    SEARCH_FIELDS = (
        'id',
        'name',
        'name.trigram',
        'uk_company.name',
        'uk_company.name.trigram',
        'investor_company.name',
        'investor_company.name.trigram',
        'project_code',
        'sector.name',
    )