Documentation for stdnet 0.8.2. For development docs, go here.
Full text search in most key-value stores is not provided out of the box as it is in traditional relational databases. One may argue that no-sql databases don’t need to provide such feature since search engines such as Solr, ElasticSearch or Sphinx can be used to provide a full text search solution.
Stdnet provides the stdnet.odm.SearchEngine interface for implementing full text search of stdnet models. The interface can be customized with third party applications.
Stdnet provides a redis-based implementation for the stdnet.odm.SearchEngine so that you can have your models stored and indexed in redis and if you like in the same redis instance.
Installing the search engine is as easy as
Create a search engine and use the stdnet.odm.Router.set_search_engine() method to install it in the router. Here, we use the models router of our first tutorial:
from stdnet.apps.searchengine import SearchEngine
models.set_search_engine(SearchEngine(backend, ...))
where backend is either a instance of a stdnet.BackendDataServer or a valid connection string such as:
redis://127.0.0.1:6379?db=4
or None, to use the default stdnet.odm.Router.backend. This is the back-end server where the text indices WordItem are stored, and not the back-end server of your models to index. They can be the same. To use the same backend as the default backend of the router:
models.search_engine = SearchEngine(models.backend, ...)
Register models you want to index to the search engine signletone:
models.search_engine.register(Instrument)
Check the stdnet.odm.SearchEngine.register() documentation for more information.
Searching model instances for text can be achieved using the stdnet.odm.Query.search method:
models.instrument.search('bla foo...')
Like all stdnet.odm.Query methods, the search method can be chained in an efficient way:
models.instrument.filter(ccy='EUR').search('bla foo...')
A python implementation for the stdnet.odm.SearchEngine driver.
Parameters: |
|
---|
Implements stdnet.odm.SearchEngine.search_model(). It return a new stdnet.odm.QueryElem instance from the input Query and the text to search.
- class stdnet.apps.searchengine.WordItem(*args, **kwargs)¶
A model for associating a word with general stdnet.odm.StdModel instance.
- object(session)¶
Instance of model_type with id object_id.