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'
def search():
    client = Client(app_key, app_secret, base_url, lib=client_name)
    indexSearch = Search(client)
    indexSearch.query = "default:'opensearch'"
    indexSearch.addIndex(index_name)
    indexSearch.addSort('updated', const.SEARCH_SORT_DESC)
    indexSearch.fetch_fields = ['id', 'title', 'updated']
    indexSearch.addAggregate('created', 'count()')
    indexSearch.addDistinct('owner_id')
    indexSearch.start = 0
    indexSearch.hits = 50
    ret = indexSearch.call()
    print('search result: ', ret)
def search():
    client = Client(app_key, app_secret, base_url, lib=client_name)
    indexSearch = Search(client)
    indexSearch.query = "default:'opensearch'"
    indexSearch.addIndex(index_name)
    indexSearch.addSort('updated', const.SEARCH_SORT_DESC)
    indexSearch.fetch_fields = ['id', 'title', 'updated']
    indexSearch.addAggregate('created', 'count()')
    indexSearch.addDistinct('owner_id')
    indexSearch.start = 0
    indexSearch.hits = 50
    ret = indexSearch.call()
    print('search result: ', ret)
Exemplo n.º 4
0
def test_search():
    client = Client(app_key, app_secret, base_url)
    indexSearch = Search(client)
    indexSearch.addIndex(index_name)
    indexSearch.addSort('updated', const.SEARCH_SORT_DESC)
    indexSearch.fetch_fields = ['id', 'title', 'updated']
    indexSearch.query = "default:'opensearch'"
    indexSearch.addAggregate('created', 'count()')
    # indexSearch.addDistinct('owner_id')
    indexSearch.start = 0
    indexSearch.hits = 50
    ret = yield from indexSearch.call()
    print(ret)
    client.session.close()
    assert ret['status'] == 'OK'
Exemplo n.º 5
0
def search(query_list, limit=5):
    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 json.dumps(ret)
    return ret["result"]["items"]
Exemplo n.º 6
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.º 7
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"]
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"