Browse files

This version of echoprint uses solr for storage. If you want a ton of…

… data, use your own keystore.
  • Loading branch information...
1 parent 5661c8a commit 87159965f1324f12f61f61b5c056089d9e67ebb1 Brian Whitman committed Apr 3, 2011
Showing with 7 additions and 67 deletions.
  1. +7 −3 API/fp.py
  2. +0 −64 API/store.py
View
10 API/fp.py
@@ -8,7 +8,6 @@
"""
from __future__ import with_statement
import logging
-import store
import solr
import threadrun
from collections import defaultdict
@@ -321,15 +320,20 @@ def query_fp(code_string, rows=15, local=False):
try:
# query the fp flat
- resp = _fp_solr.query(code_string, qt="/hashq", rows=rows)
+ resp = _fp_solr.query(code_string, qt="/hashq", rows=rows, fl="track_id")
return resp
except SolrException:
return None
def fp_code_for_track_id(track_id, local=False):
if local:
return local_fp_code_for_track_id(track_id)
- return store.retrieve(track_id, "fp_codes")
+ # Get it from solr
+ resp = _fp_solr.query("track_id:"+track_id, rows=1, fl="fp")
+ if len(resp.results):
+ return resp.results[0]["fp"]
+ else:
+ return None
def new_track_id():
rand5 = ''.join(random.choice(string.letters) for x in xrange(5)).upper()
View
64 API/store.py
@@ -1,64 +0,0 @@
-from __future__ import with_statement
-import time
-from pytyrant import PyTyrant, TyrantError
-from operator import add
-from pool import ConnectionPool, pooled_connection
-
-
-# If running locally just have this be localhost.
-# If not change at will
-node = '127.0.0.1'
-_nodes = [node+":7705"]
-
-# Holds or persisted connections (until close() is called)
-_tt = {}
-
-def close():
- '''Closes all the open Tokyo Tyrant socket connections.'''
- for nodekey in _tt.keys():
- _tt[nodekey].get().close()
- del _tt[nodekey]
-
-def _conn():
- '''Retrieves or opens correctly hashed connection pool for your key.'''
- nodekey = _nodes[0]
- if _tt.has_key(nodekey):
- return _tt[nodekey]
- else:
- host, port = nodekey.split(':')
- _tt[nodekey] = ConnectionPool(PyTyrant.open, host, int(port))
- return _tt[nodekey]
-
-def delete(key):
- '''Deletes k/v pair based on key.'''
- with pooled_connection(_conn()) as conn:
- del conn[key]
-
-def get(key):
- '''Returns k/v pair based on key.'''
-
- with pooled_connection(_conn()) as conn:
- try:
- value = conn[key]
- except KeyError:
- value = None
-
- if value is not None:
- return value
- else:
- return None
-
-def getmany_serially(keys):
- return [get(key) for key in keys]
-
-def append(key, value):
- with pooled_connection(_conn()) as conn:
- conn.concat(key, value)
-
-def set(key, value):
- with pooled_connection(_conn()) as conn:
- conn[key] = value
-
-def count():
- with pooled_connection(_conn()) as conn:
- return len(conn)

0 comments on commit 8715996

Please sign in to comment.