コード例 #1
0
ファイル: artsearch.py プロジェクト: gsf/trwbl
def create_index():
    index = Index(fields=(
        Field('title', weight=0.8),
        Field('date', index=False),
        Field('keyword', weight=0.7, copy_to='keyword_s'),
        Field('keyword_s', weight=0, tokenizer=None),
        Field('description', weight=0.6),
        Field('content', store=False),
    ))
    for article in glob('../art/*'):
        print "Adding %s ..." % article,
        file_handle = open(article)
        data = file_handle.read()
        file_handle.close()
        fields = artsy.get_file_dict(data)
        doc = Document(
            title=fields['title'],
            date=fields['date'],
            keyword=[x.strip() for x in fields['keywords'].split(',')],
            description=fields['description'],
            content=fields['contents'],
        )
        index.add(doc)
        print "done."
    print len(index.documents)
    index.save('index')
コード例 #2
0
ファイル: artsearch.py プロジェクト: gsf/trwbl
def search_index(query):
    index = Index('index')
    results = index.search(query)
    for document in results.documents:
        print "%02d %s %s" % (document.id, document.score, document['title'])