Esempio n. 1
0
    def post(index_name, column_names):
        column_list = column_names.strip().split(",")
        request_body = get_request(request)
        if "query" in request_body and isinstance(request_body["query"], str):
            content, target, result = auto_complete(TDM, index_name,
                                                    column_list,
                                                    request_body["query"])
            if content is not None:
                if len(content) == 0:
                    resp = make_response('', RESPONSE_OK_WITH_NO_CONTENT)
                    resp.headers['Content-Length'] = 0

                    return resp
                else:
                    return content, RESPONSE_OK
            else:
                if target == Result.INDEX:
                    if result is True:
                        return INDEX_ALREADY_EXIST, RESPONSE_INTERNAL_ERROR
                    else:
                        return INDEX_NOT_EXIST, RESPONSE_INTERNAL_ERROR
                elif target == Result.COLUMN:
                    if result is True:
                        return COLUMN_ALREADY_EXIST, RESPONSE_INTERNAL_ERROR
                    else:
                        return COLUMN_NOT_EXIST, RESPONSE_INTERNAL_ERROR
                elif target == Result.DOCUMENT:
                    if result is True:
                        return DOCUMENT_ALREADY_EXIST, RESPONSE_INTERNAL_ERROR
                    else:
                        return DOCUMENT_NOT_EXIST, RESPONSE_INTERNAL_ERROR
                else:
                    return None, RESPONSE_INTERNAL_ERROR
        else:
            return AUTO_COMPLETE, RESPONSE_INVALID_INPUT
Esempio n. 2
0
 def put(index_name, document_id):
     request_body = get_request(request)
     if "id" in request_body and isinstance(request_body["id"], str):
         content, target, result = update_document(TDM, index_name,
                                                   document_id,
                                                   request_body)
         if content is not None:
             return content, RESPONSE_OK
         else:
             if target == Result.INDEX:
                 if result is True:
                     return INDEX_ALREADY_EXIST, RESPONSE_INTERNAL_ERROR
                 else:
                     return INDEX_NOT_EXIST, RESPONSE_INTERNAL_ERROR
             elif target == Result.COLUMN:
                 if result is True:
                     return COLUMN_ALREADY_EXIST, RESPONSE_INTERNAL_ERROR
                 else:
                     return COLUMN_NOT_EXIST, RESPONSE_INTERNAL_ERROR
             elif target == Result.DOCUMENT:
                 if result is True:
                     return DOCUMENT_ALREADY_EXIST, RESPONSE_INTERNAL_ERROR
                 else:
                     return DOCUMENT_NOT_EXIST, RESPONSE_INTERNAL_ERROR
             else:
                 return None, RESPONSE_INTERNAL_ERROR
     else:
         return PUT_CONTROL_DOCUMENT, RESPONSE_INVALID_INPUT
Esempio n. 3
0
    def delete(index_name):
        request_body = get_request(request)
        if "document_id" in request_body and isinstance(
                request_body["document_id"], str):
            content, target, result = delete_synonym(
                TDM, index_name, request_body["document_id"])

            if content is not None:
                if content:
                    return content, RESPONSE_OK
                else:
                    resp = make_response('', RESPONSE_OK_WITH_NO_CONTENT)
                    resp.headers['Content-Length'] = 0

                    return resp
            else:
                if target == Result.INDEX:
                    if result is True:
                        return INDEX_ALREADY_EXIST, RESPONSE_INTERNAL_ERROR
                    else:
                        return INDEX_NOT_EXIST, RESPONSE_INTERNAL_ERROR
                elif target == Result.COLUMN:
                    if result is True:
                        return COLUMN_ALREADY_EXIST, RESPONSE_INTERNAL_ERROR
                    else:
                        return COLUMN_NOT_EXIST, RESPONSE_INTERNAL_ERROR
                elif target == Result.DOCUMENT:
                    if result is True:
                        return DOCUMENT_ALREADY_EXIST, RESPONSE_INTERNAL_ERROR
                    else:
                        return DOCUMENT_NOT_EXIST, RESPONSE_INTERNAL_ERROR
                else:
                    return None, RESPONSE_INTERNAL_ERROR
        else:
            return DELETE_REBUILD_SYNONYM, RESPONSE_INVALID_INPUT
Esempio n. 4
0
    def post(index_name):
        request_body = get_request(request)
        if isinstance(request_body, list):
            for doc in request_body:
                if "id" not in doc:
                    return POST_INDEX_CONTROL_AND_INSERT_DOCUMENT, RESPONSE_INVALID_INPUT

            content, target, result = insert_documents(TDM, index_name,
                                                       request_body)
            if target is None:
                return content, RESPONSE_OK
            else:
                if target == Result.INDEX:
                    if result is True:
                        return INDEX_ALREADY_EXIST, RESPONSE_INTERNAL_ERROR
                    else:
                        return INDEX_NOT_EXIST, RESPONSE_INTERNAL_ERROR
                elif target == Result.COLUMN:
                    if result is True:
                        return COLUMN_ALREADY_EXIST, RESPONSE_INTERNAL_ERROR
                    else:
                        return COLUMN_NOT_EXIST, RESPONSE_INTERNAL_ERROR
                elif target == Result.DOCUMENT:
                    if result is True:
                        if content:
                            return DOCUMENT_ALREADY_EXIST, RESPONSE_OK
                        else:
                            return DOCUMENT_ALREADY_EXIST, RESPONSE_ALREADY_EXIST
                    else:
                        return DOCUMENT_NOT_EXIST, RESPONSE_INTERNAL_ERROR
                else:
                    return None, RESPONSE_INTERNAL_ERROR
        else:
            content, target, result = create_index_and_insert_column(
                TDM, index_name)
            if content is not None:
                return content, RESPONSE_OK
            else:
                if target == Result.INDEX:
                    if result is True:
                        return INDEX_ALREADY_EXIST, RESPONSE_INTERNAL_ERROR
                    else:
                        return INDEX_NOT_EXIST, RESPONSE_INTERNAL_ERROR
                elif target == Result.COLUMN:
                    if result is True:
                        return COLUMN_ALREADY_EXIST, RESPONSE_INTERNAL_ERROR
                    else:
                        return COLUMN_NOT_EXIST, RESPONSE_INTERNAL_ERROR
                elif target == Result.DOCUMENT:
                    if result is True:
                        return DOCUMENT_ALREADY_EXIST, RESPONSE_INTERNAL_ERROR
                    else:
                        return DOCUMENT_NOT_EXIST, RESPONSE_INTERNAL_ERROR
                else:
                    return None, RESPONSE_INTERNAL_ERROR
Esempio n. 5
0
    def post(index_name):
        request_body = get_request(request)
        if isinstance(request_body, list):
            for doc in request_body:
                if not ("id" in doc and isinstance(doc["id"], str) and
                        "keyword" in doc and isinstance(doc["keyword"], str)
                        and "words" in doc and isinstance(doc["words"], list)):
                    return POST_REBUILD_SYNONYM, RESPONSE_INVALID_INPUT
                else:
                    for word in doc["words"]:
                        if not isinstance(word, str):
                            return POST_REBUILD_SYNONYM, RESPONSE_INVALID_INPUT

            content, target, result = insert_synonym(TDM, index_name,
                                                     request_body)

            if target is None:
                if content:
                    return content, RESPONSE_OK
                else:
                    resp = make_response('', RESPONSE_OK_WITH_NO_CONTENT)
                    resp.headers['Content-Length'] = 0

                    return resp
            else:
                if target == Result.INDEX:
                    if result is True:
                        return INDEX_ALREADY_EXIST, RESPONSE_INTERNAL_ERROR
                    else:
                        return INDEX_NOT_EXIST, RESPONSE_INTERNAL_ERROR
                elif target == Result.COLUMN:
                    if result is True:
                        return COLUMN_ALREADY_EXIST, RESPONSE_INTERNAL_ERROR
                    else:
                        return COLUMN_NOT_EXIST, RESPONSE_INTERNAL_ERROR
                elif target == Result.DOCUMENT:
                    if result is True:
                        if content:
                            return DOCUMENT_ALREADY_EXIST, RESPONSE_OK
                        else:
                            return DOCUMENT_ALREADY_EXIST, RESPONSE_ALREADY_EXIST
                    else:
                        return DOCUMENT_NOT_EXIST, RESPONSE_INTERNAL_ERROR
                else:
                    return None, RESPONSE_INTERNAL_ERROR
        else:
            return POST_REBUILD_SYNONYM, RESPONSE_INVALID_INPUT
Esempio n. 6
0
    def post(index_name, column_names):
        column_list = column_names.strip().split(",")
        request_body = get_request(request)
        if "query" in request_body and isinstance(
                request_body["query"],
                str) and "weight" in request_body and isinstance(
                    request_body["weight"], dict) and False not in [
                        isinstance(request_body["weight"][x], int)
                        or isinstance(request_body["weight"][x], float)
                        for x in request_body["weight"]
                    ]:
            content, target, result = search_with_word_count(
                TDM, index_name, column_list, request_body["query"],
                request_body["weight"])
            if content is not None:
                if len(content) == 0:
                    resp = make_response('', RESPONSE_OK_WITH_NO_CONTENT)
                    resp.headers['Content-Length'] = 0

                    return resp
                else:
                    return content, RESPONSE_OK
            else:
                if target == Result.INDEX:
                    if result is True:
                        return INDEX_ALREADY_EXIST, RESPONSE_INTERNAL_ERROR
                    else:
                        return INDEX_NOT_EXIST, RESPONSE_INTERNAL_ERROR
                elif target == Result.COLUMN:
                    if result is True:
                        return COLUMN_ALREADY_EXIST, RESPONSE_INTERNAL_ERROR
                    else:
                        return COLUMN_NOT_EXIST, RESPONSE_INTERNAL_ERROR
                elif target == Result.DOCUMENT:
                    if result is True:
                        return DOCUMENT_ALREADY_EXIST, RESPONSE_INTERNAL_ERROR
                    else:
                        return DOCUMENT_NOT_EXIST, RESPONSE_INTERNAL_ERROR
                else:
                    return None, RESPONSE_INTERNAL_ERROR
        else:
            return SEARCH_WORD_COUNT, RESPONSE_INVALID_INPUT