2013-10-02 3 views
-2
import os, os.path 
from whoosh.index import create_in 
from whoosh.fields import * 
schema = Schema(title=TEXT(stored=True), path=ID(stored=True), content=TEXT) 

if not os.path.exists("indexdir"): 
    os.mkdir("indexdir") 


ix = create_in("indexdir", schema) 
writer = ix.writer() 
writer.add_document(title=u"First document", path=u"/a", 
       content=u"This is the first document we've added!") 
writer.add_document(title=u"Second document", path=u"/b", 
       content=u"The second one is even more interesting!") 
writer.commit() 
from whoosh.qparser import QueryParser 

with ix.searcher() as searcher: 
    query = QueryParser("content", ix.schema).parse("first") 
    results = searcher.search(query) 
    results[0] 

괜찮아 보이지만 결과가 표시되지 않습니다.프로그램이 출력을 표시하지 않습니다.

print results[0] 

참고 그러나 위의 코드는 파이썬 2.x 용입니다 :

+1

그럼 당신이 어떤 인쇄 문이 없습니다. 뭘 기대 했니? –

답변

0

파이썬은 명시 적으로 print를 사용하여 출력을 인쇄하도록 요구 파이썬 3.x의에서 printfunction로 변환되었다

print(results[0]) 
1

나는 당신이되고 당신에게 마지막 행을 원한다고 생각 :

print results[0]

관련 문제