-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathindex_small_example.py
38 lines (28 loc) · 1005 Bytes
/
index_small_example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
from __future__ import unicode_literals
import os
from whoosh import index
from whoosh.fields import Schema, ID, TEXT
# Ultra-simple example index.
schema = Schema(id=ID(unique=True), content=TEXT)
docs = [u"Ce matin j'ai bu un café.",
u"I've been emailing all day long.",
u"http://www.python.org/",
u"I love Python!",
u"I never want to send another email ever again.",
u"Email email email. Sooo many emails.",
]
INDEX_DIR = "ex_index"
if not os.path.exists(INDEX_DIR):
os.mkdir(INDEX_DIR)
# blindly overwrite any existing index to make sure the result has only the
# intended documents in it
ix = index.create_in(INDEX_DIR, schema)
print "creating index in '{}'".format(INDEX_DIR)
writer = ix.writer()
for i, d in enumerate(docs):
print "processing document {0}; document contents: {1}".format(i, d)
writer.update_document(id=unicode(i), content=d)
writer.commit()
print "done!"