GitXplorerGitXplorer
s

WhooshAlchemy

public
32 stars
7 forks
5 issues

Commits

List of commits on branch master.
Unverified
dcac73912fc82de8b27b61e6d2b8dcd45272c624

Align release with latest tweaks.

ssfermigier committed 8 years ago
Unverified
d69c3b667e6fa73cae8c124765451911583d7792

Give the project some love.

ssfermigier committed 8 years ago
Unverified
be11650de1c30ac2eef63da003c3e1f924179c92

Put under Travis CI.

ssfermigier committed 13 years ago
Unverified
9ade9d2482ceef191a2a170ab8dd5a6684f6b0d1

Gitignore.

ssfermigier committed 13 years ago
Unverified
f6f3eba2d3b78f188614b4d5e8dae10da951cdb0

Another try.

ssfermigier committed 13 years ago
Unverified
679e71d51a13145bae68754f91bdc7e4f5cd8f5d

Another tweak to upload to PyPI.

ssfermigier committed 13 years ago

README

The README file for this repository.

WhooshAlchemy

Supports the easy text-indexing of SQLAlchemy model fields.

BSD license.

Written by Stefane Fermigier (http://www.fermigier.com/) based on Flask-WhooshAlchemy written by Karl Gyllstromk.

Quick-start example

Import this library:

from whooshalchemy import IndexService

Standard SQLAlchemy imports:

from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.schema import Column from sqlalchemy.types import Integer, Text, DateTime from sqlalchemy.engine import create_engine from sqlalchemy.orm.session import sessionmaker

Setup SQLAlchemy:

engine = create_engine('sqlite:///:memory:') Session = sessionmaker(bind=engine) session = Session() Base = declarative_base()

Our model:

class BlogPost(Base): ... tablename = 'blogpost' ... searchable = ['title', 'content'] # these fields will be indexed by whoosh ... ... id = Column(Integer, primary_key=True) ... title = Column(Text) ... content = Column(Text) ... ... def repr(self): ... return '{0}(title={1})'.format(self.class.name, self.title) ... Base.metadata.create_all(engine)

Create and init indexing service:

config = {"WHOOSH_BASE": "/tmp/whoosh"} index_service = IndexService(config=config, session=session) index_service.register_class(BlogPost) FileIndex(FileStorage('/tmp/whoosh/BlogPost'), 'MAIN')

Create a blog post:

m = BlogPost(title=u'My cool title', content=u'This is the first post.') session.add(m); session.commit()

Perform a few searches:

list(BlogPost.search_query(u'cool')) [BlogPost(title=My cool title)] list(BlogPost.search_query(u'first')) [BlogPost(title=My cool title)]

Note: the response is a BaseQuery object, so you can append other SQL operations:

list(BlogPost.search_query(u'first').filter(BlogPost.id >= 0)) [BlogPost(title=My cool title)]

Using with Flask

Setup you Flask app, create the db object (db = SQLAlchemy(app)), import your models.

Set WHOOSH_BASE to your Whoosh index directory in your Flask , then create the index service and register your models:

index_service = IndexService(config=app.config) index_service.register_class(MyFirstModel) index_service.register_class(MySecondModel)

Etc.

CHANGES

Version 0.3.0 (2017/01/09)


- Python 3 compatibility.
- Use pytest instead of nose for tests