Skip to content

Instantly share code, notes, and snippets.

@robyoung
robyoung / gist:75728
Created March 8, 2009 11:01
create a solrpy connection
import solrpy
conn = solrpy.SolrConnection('http://search.example.com/solr')
@robyoung
robyoung / gist:75731
Created March 8, 2009 11:13
add a simple document with solrpy
conn.add(id=1, title="Lucene in Action", author=["Erik Hatcher", "Otis Gospodnetic"])
docs = []
docs.append({'id':1, 'title':"Lucene in Action", 'author':["Erik Hatcher", "Otis Gospodnetic"]})
docs.append({'id':2, 'title':"Programming Collective Intelligence", 'author':"Toby Segaran"})
conn.add(docs)
@robyoung
robyoung / gist:75733
Created March 8, 2009 11:28
solrpy quickstart
import solrpy
conn = solrpy.SolrConnection('http://search.example.com/solr')
conn.add(id=1, title="Lucene in Action", author=["Erik Hatcher", "Otis Gospodnetić"])
conn.commit()
response = conn.query("lucene")
for result in response.results:
print "%d - %s" % (result['id'], result['title'])
doc = solrpy.Document(1.6)
# like a dictionary
doc['id'] = 1
doc['title'] = solrpy.Field("Lucene in Action", boost=1.5)
doc['author'] = ["Erik Hatcher", solrpy.Field("Otis Gospodnetić", boost=1.1)]
# or with add()
doc.add(id=1, title=solrpy.Field("Lucene in Action", boost=1.5), author=["Erik Hatcher", solrpy.Field("Otis Gospodnetić", boost=1.1)])
@robyoung
robyoung / gist:75761
Created March 8, 2009 12:12
add with implicit commit
conn.add(True, id=1, title="Lucene in Action")
@robyoung
robyoung / gist:75782
Created March 8, 2009 13:04
delete by id
conn.delete(1)
conn.delete([2, 3])
conn.commit()
@robyoung
robyoung / gist:75786
Created March 8, 2009 13:09
solrpy delete by query
conn.delete_query('title:foo')
conn.delete_query(['title:foo', 'title:bar'])
conn.commit()
results = conn.query('foo:bar')
print "Your query executed in %s microseconds" % results.header['QTime']
for result in results.results:
print result['title']
import traceback
def app_view_processor(request):
"""Add the current application and view names to the context."""
params = {}
for item in reversed(traceback.extract_stack()):
if item[0].endswith("/views.py"):
params['CURRENT_APP'] = item[0].split("/")[-2]
params['CURRENT_VIEW'] = item[2]
return params
db.test.save({grouper:1, checker:false});
db.test.save({grouper:1, checker:false});
db.test.save({grouper:2, checker:false});
db.test.save({grouper:2, checker:false});
db.test.save({grouper:2, checker:false});
db.test.save({grouper:2, checker:false});
db.test.save({grouper:2, checker:false});
db.test.save({grouper:1, checker:false});
db.test.find({checker:false}).forEach(function(test) {
db.test.update({checker:test.checker}, {$set:{checker:true}}, false, true);