舉例
def query(dirName, key,pageLen,pageNum):
ix = open_dir(dirName)
with ix.searcher() as searcher:
parser = QueryParser("title", ix.schema)
myquery = parser.parse(key)
print myquery
results = searcher.search_page(myquery, int(pageNum), pagelen=pageLen)
output = []
for item in results:
output.append(item.fields())
return {'pageTotal':results.pagecount,
'pageNum':results.pagenum,
'pageLen':results.pagelen,
'total': results.total,
'ids': output}
results = query(dirName="indexdir", key='document OR path:/c',pageLen=1,pageNum=2)
涉及到的高級用法
- 組合條件
- 分頁
- 排序