# 查找内容,默认一页十条
def search(q, from_, size=10):
return client.index(indexName).search(
q, opt_params={'limit': size,
'offset': from_,
}
)
# '当前页:' = str(from_// 10 + 1)
# 向索引添加或修改内容
def addIndex(index, json, key):
return client.index(index).add_documents_json(json, primary_key=key)
# 删除索引
def deleteIndex(index):
try:
client.delete_index(index)
except:
pass
# 添加或修改停用词库
def addStopWord():
print('添加或修改停用词')
wordList = [k.strip() for k in open('stop_words', encoding='utf-8').readlines() if k.strip() != '']
client.index(indexName).update_settings({
'stopWords': wordList,
})
print(client.index(indexName).get_settings())
注意:一定要添加存在的属性
print(client.index(indexName).update_ranking_rules([
"id:desc",
"sort",
"words",
"typo",
"proximity",
"attribute",
"exactness"
]))
print(client.index(indexName).search('key', {
# 'sort': ['id:desc']
}))
client.get_task(14483)