예제 #1
0
    def match_filter(self, uristr):
        uristrs = uri.expand(uristr)
        clauses = [{"match": {"uri": u}} for u in uristrs]

        if len(clauses) == 1:
            return {"query": clauses[0]}
        return {"query": {"bool": {"should": clauses}}}
예제 #2
0
    def __call__(self, params):
        uristr = params.pop('uri', None)
        if uristr is None:
            return None

        scopes = [uri.normalize(u) for u in uri.expand(uristr)]
        return {"terms": {"target.scope": scopes}}
예제 #3
0
파일: query.py 프로젝트: bitsoffreedom/h
    def __call__(self, params):
        uristr = params.pop('uri', None)
        if uristr is None:
            return None

        scopes = [uri.normalize(u) for u in uri.expand(uristr)]
        return {"terms": {"target.scope": scopes}}
예제 #4
0
파일: query.py 프로젝트: ningyifan/h
def _match_clause_for_uri(uristr):
    """Return an Elasticsearch match clause dict for the given URI."""
    uristrs = uri.expand(uristr)
    matchers = [{"match": {"uri": u}} for u in uristrs]

    if len(matchers) == 1:
        return matchers[0]
    return {"bool": {"minimum_should_match": 1, "should": matchers}}
예제 #5
0
파일: uri_test.py 프로젝트: chrber/h
def test_expand_document_uris(document_model):
    document_model.get_by_uri.return_value.uris.return_value = [
        "http://foo.com/",
        "http://bar.com/",
    ]
    assert uri.expand("http://example.com/") == [
        "http://foo.com/",
        "http://bar.com/",
    ]
예제 #6
0
def test_expand_document_uris(document_model):
    document_model.get_by_uri.return_value.uris.return_value = [
        "http://foo.com/",
        "http://bar.com/",
    ]
    assert uri.expand("http://example.com/") == [
        "http://foo.com/",
        "http://bar.com/",
    ]
예제 #7
0
파일: streamer.py 프로젝트: tilgovi/h
    def _expand_uris(self, clause):
        uris = clause['value']
        expanded = set()

        if not isinstance(uris, list):
            uris = [uris]

        for item in uris:
            expanded.update(uri.expand(item))

        clause['value'] = list(expanded)
예제 #8
0
    def _expand_uris(self, clause):
        uris = clause['value']
        expanded = set()

        if not isinstance(uris, list):
            uris = [uris]

        for item in uris:
            expanded.update(uri.expand(item))

        clause['value'] = list(expanded)
예제 #9
0
파일: query.py 프로젝트: plainspace/h
def _term_clause_for_uri(uristr):
    """Return an Elasticsearch term clause for the given URI."""
    uristrs = uri.expand(uristr)
    filters = [{"term": {"target.scope": uri.normalize(u)}}
               for u in uristrs]

    if len(filters) == 1:
        return filters[0]
    return {
        "or": filters
    }
예제 #10
0
파일: query.py 프로젝트: ningyifan/h
def _term_clause_for_uri(uristr):
    """Return an Elasticsearch term clause for the given URI."""
    uristrs = uri.expand(uristr)
    filters = [{
        "term": {
            "target.source_normalized": uri.normalize(u)
        }
    } for u in uristrs]

    if len(filters) == 1:
        return filters[0]
    return {"or": filters}
예제 #11
0
파일: uri_test.py 프로젝트: chrber/h
def test_expand_document_doesnt_expand_canonical_uris(document_model):
    document = document_model.get_by_uri.return_value
    document.get.return_value = [
        {"href": "http://foo.com/"},
        {"href": "http://bar.com/"},
        {"href": "http://example.com/", "rel": "canonical"},
    ]
    document.uris.return_value = [
        "http://foo.com/",
        "http://bar.com/",
        "http://example.com/",
    ]
    assert uri.expand("http://example.com/") == ["http://example.com/"]
예제 #12
0
파일: query.py 프로젝트: plainspace/h
def _match_clause_for_uri(uristr):
    """Return an Elasticsearch match clause dict for the given URI."""
    uristrs = uri.expand(uristr)
    matchers = [{"match": {"uri": u}} for u in uristrs]

    if len(matchers) == 1:
        return matchers[0]
    return {
        "bool": {
            "minimum_should_match": 1,
            "should": matchers
        }
    }
예제 #13
0
파일: uri_test.py 프로젝트: chrber/h
def test_expand_no_document(document_model):
    document_model.get_by_uri.return_value = None
    assert uri.expand("http://example.com/") == ["http://example.com/"]
예제 #14
0
def test_expand_no_document(document_model):
    document_model.get_by_uri.return_value = None
    assert uri.expand("http://example.com/") == ["http://example.com/"]
예제 #15
0
 def term_filter(self, uristr):
     scopes = [uri.normalize(u) for u in uri.expand(uristr)]
     return {"terms": {"target.scope": scopes}}