aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSix <unknown>2011-05-20 00:04:30 -0400
committerSix <unknown>2011-05-20 00:04:30 -0400
commit32870b39a5c0c905ae7ed03c901340fe8af01349 (patch)
tree08d6a1b52a915c2efc6db2f60573f5950780998e
parente3ad465ed22d4fb54c30bc6cfd6749ddb36231da (diff)
downloadd2-32870b39a5c0c905ae7ed03c901340fe8af01349.tar.bz2
d2-32870b39a5c0c905ae7ed03c901340fe8af01349.tar.xz
d2-32870b39a5c0c905ae7ed03c901340fe8af01349.zip
fixed initial search and added nicknames
-rw-r--r--lib/d2/app/adapters/search.py56
1 files changed, 40 insertions, 16 deletions
diff --git a/lib/d2/app/adapters/search.py b/lib/d2/app/adapters/search.py
index 034e2c9..0e1c38f 100644
--- a/lib/d2/app/adapters/search.py
+++ b/lib/d2/app/adapters/search.py
@@ -24,6 +24,16 @@ class SearchAdapter(BaseAdapter):
24 24
25 PERM_DIR = stat.S_IXUSR | stat.S_IRUSR | stat.S_IWUSR 25 PERM_DIR = stat.S_IXUSR | stat.S_IRUSR | stat.S_IWUSR
26 SEARCH_ARGS = ['label', 'description', 'plot_id', 'occupant_id'] 26 SEARCH_ARGS = ['label', 'description', 'plot_id', 'occupant_id']
27 NICKNAMES = {
28 u'Michael': [u'Mike'],
29 u'Mike': [u'Michael'],
30 u'James': [u'Jim', u'Jimmy'],
31 u'Jim': [u'James', u'Jimmy'],
32 u'Jimmy': [u'James', u'Jim'],
33 u'Leonard': [u'Len', u'Lenny'],
34 u'Matt Gibberman': [u'Snow Dog']
35 }
36
27 37
28 def __init__(self, db, log, index_directory, static, detail, detail_type, 38 def __init__(self, db, log, index_directory, static, detail, detail_type,
29 detail_adapter, forge_adapter): 39 detail_adapter, forge_adapter):
@@ -204,13 +214,21 @@ class SearchAdapter(BaseAdapter):
204 out = [] 214 out = []
205 data = data.split(u' ') 215 data = data.split(u' ')
206 for word in data: 216 for word in data:
207 out.append(word[0]) 217 word = word.strip().upper()
218 if word:
219 out.append(word[0])
220
208 if len(out) >= 2: 221 if len(out) >= 2:
209 break 222 break
210 if len(out) == 2: 223 if len(out) == 2:
211 out = u''.join(out) 224 out = u''.join(out)
212 return out.upper() 225 return out
213 226
227 def _label_to_nicknames(self, label):
228 for name, nicknames in self.NICKNAMES.items():
229 if label.lower().startswith(name.lower()):
230 return nicknames
231 return []
214 232
215 def _build_search_dictionaries(self, results): 233 def _build_search_dictionaries(self, results):
216 out = [] 234 out = []
@@ -229,13 +247,18 @@ class SearchAdapter(BaseAdapter):
229 if details[u'plot_id']: 247 if details[u'plot_id']:
230 if u'empty' in out['description'].lower(): 248 if u'empty' in out['description'].lower():
231 context.append(u'Empty') 249 context.append(u'Empty')
232 else: 250 if details[u'occupant_id']:
233 alt_label = self._split_label(out[u'label']) 251 alt_label = self._split_label(out[u'label'])
234 if alt_label != out[u'label']: 252 if alt_label != out[u'label']:
235 context.append(alt_label) 253 context.append(alt_label)
236 initials = self._label_to_initials(out[u'label']) 254 initials = self._label_to_initials(details[u'label'])
237 if initials: 255 if initials:
238 context.append(initials) 256 context.append(initials)
257 nicknames = self._label_to_nicknames(details[u'label'])
258 if nicknames:
259 for nickname in nicknames:
260 print nickname
261 context.append(nickname)
239 262
240 for key, detail in details.items(): 263 for key, detail in details.items():
241 if isinstance(detail, dict): 264 if isinstance(detail, dict):
@@ -288,16 +311,17 @@ class SearchAdapter(BaseAdapter):
288 311
289 def search(self, user_query_string): 312 def search(self, user_query_string):
290 out = [] 313 out = []
291 user_query_string = self._build_query(user_query_string) 314 if len(user_query_string.strip()) > 1:
292 with self.ix.searcher() as searcher: 315 user_query_string = self._build_query(user_query_string)
293 query = QueryParser("context", self.ix.schema) 316 with self.ix.searcher() as searcher:
294 myquery = query.parse(user_query_string) 317 query = QueryParser("context", self.ix.schema)
295 results = searcher.search(myquery) 318 myquery = query.parse(user_query_string)
296 for row in results[0:len(results)]: 319 results = searcher.search(myquery)
297 out.append(self._make_search_result( 320 for row in results[0:len(results)]:
298 row[u'label'], 321 out.append(self._make_search_result(
299 row[u'description'], 322 row[u'label'],
300 row.get(u'plot_id') or None, 323 row[u'description'],
301 row.get(u'occupant_id') or None 324 row.get(u'plot_id') or None,
302 )) 325 row.get(u'occupant_id') or None
326 ))
303 return out 327 return out