Skip to content
Snippets Groups Projects
Commit b930cf4c authored by ale's avatar ale
Browse files

catch and report SOLR errors

parent d9773ce0
Branches
No related tags found
No related merge requests found
......@@ -8,17 +8,25 @@ class Searcher(object):
self.solr = solr.Solr(solr_url, timeout=30)
def search(self, qstr, n=10, partial=False):
results = self.solr.select(q=qstr, sort='score desc',
fields='score,id', start=0, rows=n)
try:
results = self.solr.select(q=qstr, sort='score desc',
fields='score,id', start=0, rows=n)
except solr.SolrException, e:
log.error('SOLR exception (query="%s"): %s' % (
qstr, e))
for doc in results.results:
yield doc['score'], doc['id']
def more_like_these(self, hashes, n=5):
"""Return a set of hashes that are related to the ones provided."""
query_str = ' OR '.join('(id:%s)' % x for x in hashes)
results = self.solr.select(
q=query_str, fields='score,id', rows=n,
mlt='true', mlt_fl='text', mlt_mindf=1, mlt_mintf=1)
query_str = ' OR '.join('(id:%s)' % x for x in hashes if x)
try:
results = self.solr.select(
q=query_str, fields='score,id', rows=n,
mlt='true', mlt_fl='text', mlt_mindf=1, mlt_mintf=1)
except solr.SolrException, e:
log.error('SOLR exception (query="%s"): %s' % (
query_str, e))
# Parse and uniq-ify the results.
hashes_set = set(hashes)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment