mirror of https://github.com/fxsjy/jieba.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
826 B
Python
29 lines
826 B
Python
12 years ago
|
# -*- coding: UTF-8 -*-
|
||
10 years ago
|
from __future__ import unicode_literals
|
||
12 years ago
|
import sys
|
||
|
import os
|
||
|
sys.path.append("../")
|
||
|
from whoosh.index import create_in,open_dir
|
||
|
from whoosh.fields import *
|
||
|
from whoosh.qparser import QueryParser
|
||
|
|
||
|
from jieba.analyse import ChineseAnalyzer
|
||
|
|
||
|
analyzer = ChineseAnalyzer()
|
||
|
|
||
|
schema = Schema(title=TEXT(stored=True), path=ID(stored=True), content=TEXT(stored=True, analyzer=analyzer))
|
||
|
if not os.path.exists("tmp"):
|
||
|
os.mkdir("tmp")
|
||
|
ix = open_dir("tmp")
|
||
|
|
||
|
searcher = ix.searcher()
|
||
|
parser = QueryParser("content", schema=ix.schema)
|
||
|
|
||
11 years ago
|
for keyword in ("水果小姐","你","first","中文","交换机","交换","少林","乔峰"):
|
||
|
print("result of ",keyword)
|
||
12 years ago
|
q = parser.parse(keyword)
|
||
|
results = searcher.search(q)
|
||
|
for hit in results:
|
||
11 years ago
|
print(hit.highlights("content"))
|
||
|
print("="*10)
|