Exemplo n.º 1
0
def test_search():
    client = Client(app_key, app_secret, base_url, lib=client_name)
    indexSearch = Search(client)
    indexSearch.addIndex(index_name)
    indexSearch.addSort('updated', const.SEARCH_SORT_DESC)
    indexSearch.fetch_fields = ['id', 'title', 'updated']
    indexSearch.query = "default:'opensearch'"
    agg_range = ['0~1439514378', '1439514378~1539514378']
    indexSearch.addAggregate('created',
                             'count()',
                             agg_sampler_threshold=10000,
                             agg_sampler_step=5,
                             agg_filter="created>1423456781",
                             max_group=100,
                             agg_range=agg_range)
    grade = [3.0, 5.0]
    indexSearch.addDistinct('owner_id', grade=grade)
    indexSearch.addFilter('owner_id>=1')
    indexSearch.addFilter('created>=1439514200')
    indexSearch.addSummary("text",
                           length=100,
                           element='em',
                           ellipsis='...',
                           snipped=1,
                           element_prefix='<em>',
                           element_postfix='</em>')
    indexSearch.qp = 'stop_word'
    indexSearch.disable = 'qp'
    indexSearch.start = 0
    indexSearch.hits = 50
    indexSearch.format = 'json'
    indexSearch.rerank_size = 200
    indexSearch.formula_name = 'default'
    indexSearch.first_formula_name = 'default'
    indexSearch.kvpairs = 'duniqfield:owner_id'
    ret = indexSearch.call()
    print('test_search', ret)
    assert ret['status'] == 'OK'
Exemplo n.º 2
0
def search(query_list,limit=5): # query_list 搜索词列表
    table_name = 'main' #默认配置
    index_name = build_index_name
    client = Client(app_key, app_secret, base_url, lib=client_name) #base_url = 'http://opensearch-cn-beijing.aliyuncs.com'# 我建立的openserch应用的 公网API域名 返回的是什么??
    indexSearch = Search(client)
    indexSearch.addIndex(build_index_name)
    #query_list = ["美女", "性感"]

    query_para_list = [] #检索字符串list
    for word in query_list:
        para = "default:'"+ word + "'"#转换格式  和阿里云的开放搜索页面的搜索测试相同的格式   default:'搜索'
        query_para_list.append(para)

    indexSearch.query = " OR ".join(query_para_list) #全or检索
    #print indexSearch.query
    indexSearch.addFilter("is_download=1")#过滤结果 要求 is_download字段必须设为1的才进行检索 数据库表 video_info

    indexSearch.start = 0 #start
    indexSearch.hits = limit #limit   hits
    indexSearch.format = 'json' #数据结果格式
    ret = indexSearch.call()
    #print json.dumps(ret)
    return ret["result"]["items"]
Exemplo n.º 3
0
def search(query_list, limit=50):
    table_name = 'main'  # 默认参数,不需要修改
    index_name = build_index_name
    client = Client(app_key, app_secret, base_url, lib=client_name)
    indexSearch = Search(client)
    indexSearch.addIndex("short_video")  # 搜索应用名称

    query_para_list = []  # 检索字符串list
    for word in query_list:
        para = "default:'" + word + "'"
        query_para_list.append(para)

    indexSearch.query = " OR ".join(query_para_list)  # 全or检索
    # print(indexSearch.query)
    # indexSearch.addFilter("is_download=1")

    indexSearch.start = 0  # start
    indexSearch.hits = limit  # limit
    indexSearch.format = 'json'  # 数据结果格式
    ret = indexSearch.call()
    print(ret)
    # print json.dumps(ret)
    return ret["result"]["items"]
Exemplo n.º 4
0
def test_errlog_raise2():
    with pytest.raises(const.ArgError):
        client = Client(app_key, app_secret, base_url, lib=client_name)
        errLog = ErrorLog(client, index_name)
        errLog.call(1, 50, sort_mode=const.LOG_SORT_ASC, method='PUT')
Exemplo n.º 5
0
def test_errlog():
    client = Client(app_key, app_secret, base_url, lib='httplib')
    errLog = ErrorLog(client, index_name)
    ret = errLog.call(1, 50, sort_mode=const.LOG_SORT_ASC)
    print(ret)
    assert ret['status'] == 'OK'
Exemplo n.º 6
0
async def doc_delete():
    client = Client(app_key, app_secret, base_url)
    indexDoc = IndexDoc(client, index_name)
    ret = await indexDoc.delete(doc_id, table_name)
    client.session.close()
    print('delete doc status: ', ret['status'])
Exemplo n.º 7
0
async def doc_after_update_get():
    client = Client(app_key, app_secret, base_url)
    indexDoc = IndexDoc(client, index_name)
    ret = await indexDoc.get(doc_id, table_name)
    client.session.close()
    print("doc title: ", ret['result']['title'])
Exemplo n.º 8
0
def doc_get():
    client = Client(app_key, app_secret, base_url)
    indexDoc = IndexDoc(client, index_name)
    ret = yield from indexDoc.get(doc_id, table_name)
    client.session.close()
    print("doc title: ", ret['result']['title'])
def test_after_update_get():
    client = Client(app_key, app_secret, base_url, lib=client_name)
    indexDoc = IndexDoc(client, index_name)
    ret = indexDoc.get(doc_id, table_name)
    print(ret)
    assert ret['status'] == 'OK'
Exemplo n.º 10
0
def test_app_delete():
    client = Client(app_key, app_secret, base_url)
    indexApp = IndexApp(client)
    ret = yield from indexApp.delete(index_name)
    client.session.close()
    assert ret['status'] == 'OK'
Exemplo n.º 11
0
def test_rebuild():
    client = Client(app_key, app_secret, base_url, lib=client_name)
    indexApp = IndexApp(client)
    ret = indexApp.rebuild(index_name, 'createtask', table_name=table_name)
    print(ret)
    assert ret['status'] == 'OK'
Exemplo n.º 12
0
def test_errlog_post():
    client = Client(app_key, app_secret, base_url, lib=client_name, proxy=proxy)
    errLog = ErrorLog(client, index_name)
    ret = errLog.call(1, 50, sort_mode=const.LOG_SORT_ASC, method=const.HTTP_POST)
    print(ret)
    assert ret['status'] == 'OK'
Exemplo n.º 13
0
def test_delete():
    client = Client(app_key, app_secret, base_url, lib=client_name)
    indexDoc = IndexDoc(client, index_name)
    ret = indexDoc.delete(doc_id, table_name)
    assert ret['status'] == 'OK'
    time.sleep(5)
def doc_after_update_get():
    client = Client(app_key, app_secret, base_url, lib=client_name)
    indexDoc = IndexDoc(client, index_name)
    ret = indexDoc.get(doc_id, table_name)
    print("doc title: ", ret['result']['title'])
Exemplo n.º 15
0
def test_status():
    client = Client(app_key, app_secret, base_url, lib=client_name)
    indexApp = IndexApp(client)
    ret = indexApp.status(index_name)
    assert ret['status'] == 'OK'
    print(ret['result'])
def doc_delete():
    client = Client(app_key, app_secret, base_url, lib=client_name)
    indexDoc = IndexDoc(client, index_name)
    ret = indexDoc.delete(doc_id, table_name)
    print('delete doc status: ', ret['status'])
Exemplo n.º 17
0
def test_delete():
    client = Client(app_key, app_secret, base_url, lib=client_name)
    indexApp = IndexApp(client)
    ret = indexApp.delete(index_name)
    assert ret['status'] == 'OK'
Exemplo n.º 18
0
def test_deletes():
    client = Client(app_key, app_secret, base_url, lib=client_name)
    indexDoc = IndexDoc(client, index_name)
    ret = indexDoc.delete([100, 101, 102, 103, 200, 201, 202, 203], table_name)
    assert ret['status'] == 'OK'
    time.sleep(5)
Exemplo n.º 19
0
def test_app_create():
    client = Client(app_key, app_secret, base_url, lib=client_name)
    indexApp = IndexApp(client)
    ret = indexApp.create(index_name, 'tpl_test')
    assert ret['status'] == 'OK'
    time.sleep(5)