Beispiel #1
0
def test_searchindex():

    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"Oranges", path=u"/a",
                        content=u"This is the first document we've added!")
    writer.add_document(title=u"Apples", path=u"/b",
                        content=u"The second document is even more "
                                u"interesting!")
    writer.commit()

    # N.B., fields get sorted
    expect = ((u'path', u'title'),
              (u'/a', u'Oranges'))
    # N.B., by default whoosh does not do stemming
    actual = searchindex(dirname, 'oranges')
    ieq(expect, actual)
    actual = searchindex(dirname, 'add*')
    ieq(expect, actual)

    expect = ((u'path', u'title'),
              (u'/a', u'Oranges'),
              (u'/b', u'Apples'))
    actual = searchindex(dirname, 'doc*')
    ieq(expect, actual)
Beispiel #2
0
def test_searchindex():

    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"Oranges",
                        path=u"/a",
                        content=u"This is the first document we've added!")
    writer.add_document(title=u"Apples",
                        path=u"/b",
                        content=u"The second document is even more "
                        u"interesting!")
    writer.commit()

    # N.B., fields get sorted
    expect = ((u'path', u'title'), (u'/a', u'Oranges'))
    # N.B., by default whoosh does not do stemming
    actual = searchindex(dirname, 'oranges')
    ieq(expect, actual)
    actual = searchindex(dirname, 'add*')
    ieq(expect, actual)

    expect = ((u'path', u'title'), (u'/a', u'Oranges'), (u'/b', u'Apples'))
    actual = searchindex(dirname, 'doc*')
    ieq(expect, actual)
Beispiel #3
0
                f2=NUMERIC(float, stored=True),
                f3=BOOLEAN(stored=True),
                f4=DATETIME(stored=True))
# load data
toindex(tbl, 'tmp/example', schema=schema)
# look what it did
look(fromindex('tmp/example'))

# searchindex
#############

# set up an index and load some documents via the Whoosh API
from whoosh.index import create_in
from whoosh.fields import *
schema = Schema(title=TEXT(stored=True), path=ID(stored=True), content=TEXT)
index = create_in('tmp/example', schema)
writer = index.writer()
writer.add_document(title=u"Oranges",
                    path=u"/a",
                    content=u"This is the first document we've added!")
writer.add_document(title=u"Apples",
                    path=u"/b",
                    content=u"The second document is even more "
                    u"interesting!")
writer.commit()
# demonstrate the use of searchindex()
from petl import look
from petlx.index import searchindex
look(searchindex('tmp/example', 'oranges'))
look(searchindex('tmp/example', 'doc*'))
Beispiel #4
0
                f3=BOOLEAN(stored=True),
                f4=DATETIME(stored=True))
# load data
toindex(tbl, 'tmp/example', schema=schema)
# look what it did
look(fromindex('tmp/example'))


# searchindex
#############


# set up an index and load some documents via the Whoosh API
from whoosh.index import create_in
from whoosh.fields import *
schema = Schema(title=TEXT(stored=True), path=ID(stored=True), content=TEXT)
index = create_in('tmp/example', schema)
writer = index.writer()
writer.add_document(title=u"Oranges", path=u"/a",
                    content=u"This is the first document we've added!")
writer.add_document(title=u"Apples", path=u"/b",
                    content=u"The second document is even more "
                            u"interesting!")
writer.commit()
# demonstrate the use of searchindex()
from petl import look
from petlx.index import searchindex
look(searchindex('tmp/example', 'oranges'))
look(searchindex('tmp/example', 'doc*'))