Skip to content
Fetching contributors…
Cannot retrieve contributors at this time
102 lines (67 sloc) 3.17 KB


Library to use Solr with python.


  1. Searching:

    searcher = SolrSearcher() # you can't do real requests to Solr, use next: SolrSearcher('http://localhost:8180/db')
    q ='test', category=1).ps(5).qf('name^5 description').bf('linear(rank,100,0)')
  2. Filtering:

    q = q.filter(status=0).filter(category__in=[1, 2, 3]).exclude(rank__lte=5)
    q = q.exclude(rank=None)
  3. Grouping:

    q ='director', limit=5)
  4. Facets:

    q = q.facet('status').facet(['category', 'type'], params={'category': {'mincount': 5}})
    qf = q.get_query_filter()
    qf.add_ordering([(u'by rank', '-rank'), (u'by date', '-date_created')])
    # now you can filter your search query by get parameters
    # supports Django's QueryDict, webob's MultiDict or python dict
    q = qf.apply(q, {'status': [0,1], 'type': 3, 'type__gte': 5, 'sort': '-rank'})

There are facet.field and facet.query support. Also automatically adds tag for every fq and excludes corresponding fq's from facets. See

  1. Mapping

Mapping docs and facets on any objects you want and then you can access it via .instance attribute:

class MovieSearcher(SolrSearcher):
    model = Movie

    # example of non-standart mapping
    class KeywordFacet(Facet):
        field = 'keywords'
        model = Keyword
        session = session

        def get_id(self, id):
            return id

        def get_instances(self, ids):
            return dict([(, obj) for obj in session.query(self.model).filter(])

    def get_instances(self, ids):
        return dict([(, obj) for obj in session.query(self.model).filter(])

q ='monty python').facet('keywords')
for doc in q:

for fv in q.results.get_facet('keywords'):
    print, fv.count
  1. Multiple Solr's

Reading from and writing to multiple Solr instances. For reading choses Solr instance randomly. Writes into every Solr instance. You should syncronize reading Solr's with writing instances manually (use rsync or something else).

  1. Lazy evaluate

Only iterating, count and access to .results attribute make http requests to Solr.


  • Dynamic fields support (need mapping for facets)
  • Groups refactoring
  • Lazy results and facets
  • and facet.range support
  • Django support
  • Documentation
  • Unit tests
Jump to Line
Something went wrong with that request. Please try again.