예제 #1
0
def test_pickle_idlist():
    schema = fields.Schema(
        pk=fields.ID(stored=True, unique=True),
        text=fields.TEXT(),
        tags=fields.IDLIST(stored=True),
    )
    with TempIndex(schema) as ix:
        assert ix
예제 #2
0
파일: enron.py 프로젝트: ws-os/oh-mainline
 def whoosh_schema(self):
     ana = analysis.StemmingAnalyzer(maxsize=40, cachesize=None)
     storebody = self.options.storebody
     schema = fields.Schema(body=fields.TEXT(analyzer=ana, stored=storebody),
                            filepos=fields.STORED,
                            date=fields.ID(stored=True),
                            frm=fields.ID(stored=True),
                            to=fields.IDLIST(stored=True),
                            subject=fields.TEXT(stored=True),
                            cc=fields.IDLIST,
                            bcc=fields.IDLIST)
     return schema
예제 #3
0
def test_idlist():
    schema = fields.Schema(paths=fields.IDLIST(stored=True))
    ix = RamStorage().create_index(schema)

    with ix.writer() as w:
        w.add_document(paths=u('here there everywhere'))
        w.add_document(paths=u('here'))
        w.add_document(paths=u('there'))

    with ix.searcher() as s:
        qp = qparser.QueryParser('paths', schema)
        q = qp.parse(u('here'))

        r = s.search(q)
        assert sorted(hit['paths']
                      for hit in r) == ['here', 'here there everywhere']
예제 #4
0
class JSON(fields.TEXT):
    def to_bytes(self, value: dict) -> bytes:
        return super(JSON, self).to_bytes(json.dumps(value))

    def from_bytes(self, bs: bytes) -> dict:
        return json.loads(super(JSON, self).from_bytes(bs))

    def index(self, value: dict, **kwargs) -> Iterable:
        yield (self.to_bytes(value), 1, 1.0, emptybytes)
        return


SCHEMA = fields.Schema(title=fields.TEXT(stored=True),
                       path=fields.ID(stored=True),
                       parents=fields.IDLIST(stored=True),
                       content=fields.TEXT(stored=True))

STATIC_SCHEMA = fields.Schema(path=fields.ID(stored=True))


class PageDoesNotExist(Exception):
    """A requested :class:`Page` does not exist."""


class SchemaDoesNotExist(Exception):
    """A requested :class:`Schema` does not exist."""


def create_index() -> index.Index:
    """Initialize the index."""