Beispiel #1
0
def _ownership_search(request):
    query = request.GET.get("q", "")

    fields_to_search = [
        "owner", "asset", "ownership_ground", "ownership_form", "share",
        "comment", "mortgage_charge", "mortgage_details",
        "mortgage_charge_subjects", "mortgage_holder", "mortgage_mortgagor",
        "mortgage_guarantor", "mortgage_other_persons"
    ]

    if query:
        ownerships = ElasticOwnership.search().query("multi_match",
                                                     query=query,
                                                     operator="and",
                                                     fields=fields_to_search)

        if ownerships.count() == 0:
            # PLAN B, PLAN B
            ownerships = ElasticOwnership.search().query(
                "multi_match",
                query=query,
                operator="or",
                minimum_should_match="2",
                fields=fields_to_search)
    else:
        ownerships = ElasticOwnership.search().query("match_all")

    return paginated_search(request, ownerships)
Beispiel #2
0
def _ownership_search(request):
    query = request.GET.get("q", "")

    fields_to_search = [
        "owner", "asset", "ownership_ground", "ownership_form", "share",
        "comment", "mortgage_charge", "mortgage_details",
        "mortgage_charge_subjects", "mortgage_holder", "mortgage_mortgagor",
        "mortgage_guarantor", "mortgage_other_persons"]

    if query:
        ownerships = ElasticOwnership.search().query(
            "multi_match", query=query, operator="and",
            fields=fields_to_search
        )

        if ownerships.count() == 0:
            # PLAN B, PLAN B
            ownerships = ElasticOwnership.search().query(
                "multi_match", query=query,
                operator="or",
                minimum_should_match="2",
                fields=fields_to_search
            )
    else:
        ownerships = ElasticOwnership.search().query("match_all")

    return paginated_search(request, ownerships)
Beispiel #3
0
def _ownership_search(request):
    query = request.GET.get("q", "")

    if query:
        return paginated_search(request, ElasticOwnership.search().query(
            "match", _all={"query": query, "minimum_should_match": "2"}
        ))

    return paginated_search(
        request, ElasticOwnership.search().query("match_all"))
Beispiel #4
0
    def assume(q, fuzziness):
        search = ElasticOwnership.search()\
            .source(['full_name_suggest', 'owner'])\
            .params(size=0)\
            .suggest(
                'name',
                q,
                completion={
                    'field': 'full_name_suggest',
                    'size': 10,
                    'fuzzy': {
                        'fuzziness': fuzziness,
                        'unicode_aware': True
                    }
                }
        )

        res = search.execute()

        if res.success():
            return list(
                set(val._source.owner
                    for val in res.suggest.name[0]['options']))
        else:
            return []
Beispiel #5
0
    def assume(q, fuzziness):
        search = ElasticOwnership.search()\
            .suggest(
                'name',
                q,
                completion={
                    'field': 'full_name_suggest',
                    'size': 10,
                    'fuzzy': {
                        'fuzziness': fuzziness,
                        'unicode_aware': 1
                    }
                }
        )

        res = search.execute()

        if res.success():
            return [val['text'] for val in res.suggest['name'][0]['options']]
        else:
            []
Beispiel #6
0
def suggest(request):
    search = ElasticOwnership.search()\
        .suggest(
            'name',
            request.GET.get('q', ''),
            completion={
                'field': 'full_name_suggest',
                'size': 10,
                'fuzzy': {
                    'fuzziness': 2,
                    'unicode_aware': 1
                }
            }
    )

    res = search.execute()

    if res.success():
        return JsonResponse(
            [val['text'] for val in res.suggest['name'][0]['options']],
            safe=False
        )
    else:
        return JsonResponse([], safe=False)