Exemple #1
0
    def test_integration():

        dirname = tempfile.mkdtemp()
        schema = Schema(title=TEXT(stored=True), path=ID(stored=True),
                        content=TEXT)

        ix = create_in(dirname, 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()

        # N.B., fields get sorted
        expect = ((u'path', u'title'),
                  (u'/a', u'first document'),
                  (u'/b', u'second document'))
        actual = etl.fromtextindex(dirname).convert('title', 'lower')
        ieq(expect, actual)
Exemple #2
0
schema = Schema(title=TEXT(stored=True), path=ID(stored=True), content=TEXT)
dirname = 'example.whoosh'
if not os.path.exists(dirname):
    os.mkdir(dirname)

index = create_in(dirname, schema)
writer = index.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()
# extract documents as a table
table = etl.fromtextindex(dirname)
table

# totextindex()
###############

import petl as etl
import datetime
import os
# here is the table we want to load into an index
table = (('f0', 'f1', 'f2', 'f3', 'f4'), ('AAA', 12, 4.3, True,
                                          datetime.datetime.now()),
         ('BBB', 6, 3.4, False, datetime.datetime(1900, 1, 31)),
         ('CCC', 42, 7.8, True, datetime.datetime(2100, 12, 25)))
# define a schema for the index
from whoosh.fields import *
Exemple #3
0
from whoosh.index import create_in
from whoosh.fields import *
schema = Schema(title=TEXT(stored=True), path=ID(stored=True), content=TEXT)
dirname = 'example.whoosh'
if not os.path.exists(dirname):
    os.mkdir(dirname)

index = create_in(dirname, schema)
writer = index.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()
# extract documents as a table
table = etl.fromtextindex(dirname)
table


# totextindex()
###############

import petl as etl
import datetime
import os
# here is the table we want to load into an index
table = (('f0', 'f1', 'f2', 'f3', 'f4'),
         ('AAA', 12, 4.3, True, datetime.datetime.now()),
         ('BBB', 6, 3.4, False, datetime.datetime(1900, 1, 31)),
         ('CCC', 42, 7.8, True, datetime.datetime(2100, 12, 25)))
# define a schema for the index