mirror of
https://github.com/fxsjy/jieba.git
synced 2025-07-10 00:01:33 +08:00
update whoosh example
This commit is contained in:
parent
4b237f79fa
commit
ba5114dc95
@ -1,5 +1,5 @@
|
||||
# -*- coding: UTF-8 -*-
|
||||
import sys
|
||||
import sys,os
|
||||
sys.path.append("../")
|
||||
from whoosh.index import create_in,open_dir
|
||||
from whoosh.fields import *
|
||||
@ -10,6 +10,9 @@ 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 = create_in("tmp", schema) # for create new index
|
||||
#ix = open_dir("tmp") # for read only
|
||||
writer = ix.writer()
|
||||
|
@ -1,5 +1,6 @@
|
||||
# -*- coding: UTF-8 -*-
|
||||
import sys
|
||||
import os
|
||||
sys.path.append("../")
|
||||
from whoosh.index import create_in
|
||||
from whoosh.fields import *
|
||||
@ -10,6 +11,8 @@ 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 = create_in("tmp", schema)
|
||||
writer = ix.writer()
|
||||
|
||||
|
27
test/test_whoosh_flie_read.py
Normal file
27
test/test_whoosh_flie_read.py
Normal file
@ -0,0 +1,27 @@
|
||||
# -*- coding: UTF-8 -*-
|
||||
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)
|
||||
|
||||
for keyword in (u"水果小姐",u"你",u"first",u"中文",u"交换机",u"交换",u"少林",u"乔峰"):
|
||||
print "result of ",keyword
|
||||
q = parser.parse(keyword)
|
||||
results = searcher.search(q)
|
||||
for hit in results:
|
||||
print hit.highlights("content")
|
||||
print "="*10
|
Loading…
x
Reference in New Issue
Block a user