Permalink
Browse files

Working search logic

  • Loading branch information...
1 parent e67cd84 commit 5a940c4f870a9ac2240ef9cd53bc5e28a9b9c5e9 @wejendorp wejendorp committed May 22, 2012
Showing with 13 additions and 10 deletions.
  1. +1 −1 Util.py
  2. +10 −7 controllers/searchController.py
  3. +2 −2 models/Application.py
View
@@ -38,7 +38,7 @@ def AddSNPDocument(snp):
fields=[
search.TextField(name='snpid', value=snp.snpid),
])
- search.Index(name=study._index).add(doc)
+ search.Index(name=snp._index).add(doc)
def AddGeneDocument(gene):
doc = search.Document(doc_id=gene.geneid,
@@ -9,13 +9,16 @@ def get(self, query):
""" Request via GET = single """
result = None
if query != "":
- result = self._model.search(query)
- self.response.out.write(result)
- #self.toJson(result)
-
- #def post(self, query):
- # """Request via POST = Batch"""
- # pass
+ result = self._model.search('"'+query+'"')
+ out = []
+ for scoreddocument in result:
+ d = {}
+ for f in scoreddocument.fields:
+ d[f.name] = f.value
+ out.append(d)
+ self.toJson(out)
+ else:
+ self.error(404)
class SNPSearch(SearchHandler):
@@ -10,9 +10,9 @@ def __dict__(self):
return dict([(p, unicode(getattr(self, p))) for p in self.properties()])
@classmethod
- def search(self,query):
+ def search(self, query):
"""Allow full-text search"""
if self._index:
- search.Index(name=self._index).search('"'+query+'"')
+ return search.Index(name=self._index).search(query)
else:
raise AttributeError('Index is not set for search on '+str(self))

0 comments on commit 5a940c4

Please sign in to comment.