# solrpy /

Filename Size Date modified Message
docs
solr
tests
68 B
494 B
412 B
50 B
1.8 KB
9.5 KB
558 B

# Solr API for Python

solrpy is a Python client for Solr, an enterprise search server built on top of Lucene. solrpy allows you to add documents to a Solr instance, and then to perform queries and gather search results from Solr using Python.

## Overview

Here's the basic gist:

import solr

# create a connection to a solr server
s = solr.Solr('http://example.org:8083/solr')

# add a document to the index
doc = dict(
id=1,
title='Lucene in Action',
author=['Erik Hatcher', 'Otis Gospodnetić'],
)

# do a search
response = s.query('title:lucene')
for hit in response.results:
print hit['title']


## More powerful queries

Optional parameters for query, faceting, highlighting and more like this can be passed in as Python parameters to the query method. You just need to convert the dot notation (e.g. facet.field) to underscore notation (e.g. facet_field) so that they can be used as parameter names.

For example, let's say you wanted to get faceting information in your search result:

response = s.query(
'title:lucene', facet='true', facet_field='subject')


and if the parameter takes multiple values you just pass them in as a list:

response = s.query(
'title:lucene', facet='true',
facet_field=['subject', 'publisher'])


## Community

Feel free to join our discussion list if you have ideas or suggestions. Also, please add examples to the wiki if you have the time and interest.

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.