Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed fp.delete bug and added delete ability to api.py #30

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions API/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
'/query', 'query',
'/query?(.*)', 'query',
'/ingest', 'ingest',
'/delete', 'delete',
'/delete?(.*)', 'delete'
)


Expand Down Expand Up @@ -67,6 +69,21 @@ def GET(self):
return json.dumps({"ok":True, "query":stuff.fp_code, "message":response.message(), "match":response.match(), "score":response.score, \
"qtime":response.qtime, "track_id":response.TRID, "total_time":response.total_time})

class delete:
def POST(self):
return self.GET()

def GET(self):
params = web.input(track_ids=None)
if params.track_ids is None:
return web.webapi.BadRequest()
if params.track_ids == "*":
fp.erase_database(True)
else:
track_ids = params.track_ids.split(",")
fp.delete(track_ids);

return json.dumps({"ok":True, "track_ids":params.track_ids})

application = web.application(urls, globals())#.wsgifunc()

Expand Down
7 changes: 4 additions & 3 deletions API/fp.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,16 +449,17 @@ def delete(track_ids, do_commit=True, local=False):
return local_delete(track_ids)

with solr.pooled_connection(_fp_solr) as host:
for t in track_ids:
for t in track_ids:
host.delete_query("track_id:%s*" % t)

try:
try:
track_ids = [track_id.encode("utf8") for track_id in track_ids]
get_tyrant().multi_del(track_ids)
except KeyError:
pass

if do_commit:
commit()
commit()

def local_erase_database():
global _fake_solr
Expand Down