예제 #1
0
def workx(s, t, k):
    l = []
    request_body = {
        "query": {
            "bool": {
                "should": [
                    {
                        "match": {
                            "content": s
                        }
                    }
                ]
            }
        }
    }
    if not (t is None):
        request_body["query"]["bool"]["must"] = [
            {
                "term": {
                    "type2": {
                        "value": t
                    }
                }
            }
        ]

    response = search("law", "data", request_body)
    for a in range(0, k):
        l.append(response["hits"]["hits"][a]["_source"]["content"])

    return l
예제 #2
0
def root():
    if "query" in request.args:
        data = search(
            "law", "data", {
                "query": {
                    "bool": {
                        "should": [{
                            "match": {
                                "content": request.args["query"]
                            }
                        }],
                    }
                }
            })["hits"]["hits"]
        problem = get(request.args["query"], problem_collection)
        kaodian = get(request.args["query"], kaodian_collection)
        return render_template("main.html",
                               text=json.dumps(data,
                                               indent=2,
                                               ensure_ascii=False,
                                               sort_keys=True),
                               problem=json.dumps(problem, ensure_ascii=False),
                               kaodian=json.dumps(kaodian, ensure_ascii=False),
                               query=str(request.args["query"])).replace(
                                   "\n", "<br>")
    else:
        return render_template("main.html").replace("\n", "<br>")
예제 #3
0
def worky(s, k):
    l = []
    request_body = {"query": {"bool": {"should": [{"match": {"content": s}}]}}}

    response = search("law_laws", "data", request_body)
    for a in range(0, k):
        l.append(response["hits"]["hits"][a]["_source"]["content"])

    return l
예제 #4
0
def work(filename):
    print(filename)
    data = []
    f = open(os.path.join(path, filename), "r")
    for line in f:
        d = json.loads(line)
        if doc_type_map_dic[d["subject"]] != -1:
            type2 = doc_type_map_dic[d["subject"]]

            d["reference"] = {}
            for option in d["option_list"]:
                s1 = d["analyse"]
                s2 = d["option_list"][option]
                request_body = {
                    "query": {
                        "bool": {
                            "should": [
                                {
                                    "match": {
                                        "content": s1
                                    }
                                },
                                {
                                    "match": {
                                        "content": s2
                                    }
                                }
                            ],
                            "must": [
                                {
                                    "term": {
                                        "type2": {
                                            "value": type2
                                        }
                                    }
                                }
                            ]
                        }
                    }
                }

                response = search("law", "data", request_body)
                d["reference"][option] = []
                for a in range(0, 10):
                    d["reference"][option].append(response["hits"]["hits"][a]["_source"]["content"])

        data.append(d)

    f.close()
    f = open(os.path.join(output_path, filename), "w")
    for d in data:
        print(json.dumps(d, sort_keys=True, ensure_ascii=False), file=f)
    f.close()
예제 #5
0
def worky(s, k):
    l = []
    request_body = {
        "query": {
            "bool": {
                "should": [
                    {
                        "match": {
                            "content": s
                        }
                    }
                ]
            }
        }
    }
    response = search("law_laws", "data", request_body)
    for a in range(0, min(k, len(response["hits"]["hits"]))):
        l.append(response["hits"]["hits"][a]["_source"]["content"])
    while len(l) < k:
        l.append("")
    # print(json.dumps(l, indent=2, ensure_ascii=False))

    return l