Ticket #2707: patch1.diff
File patch1.diff, 2.4 KB (added by , 18 years ago) |
---|
-
django/contrib/search/xapian.py
4 4 import xapwrap.document 5 5 from itertools import imap 6 6 7 from base import Indexer, ResultSet 7 from query import ResultSet, Hit 8 from base import Indexer 8 9 9 10 # TODO: This is incomplete. 10 11 … … 17 18 else: 18 19 update_queue = documents 19 20 20 for row in documents:21 for row in update_queue: 21 22 keys = [] 23 text_fields = [] 22 24 for name, field in self.attr_fields.iteritems(): 23 keys.append(xapwrap.document.SortKey(name, getattr(self.model, field.name))) 24 25 d = xapwrap.document.Document(textFields=fields, sortFields=keys, uid=row._get_pk_val()) 25 field_name = str(getattr(row, field.name)) 26 #keys.append(xapwrap.document.SortKey(name, field_name)) 27 text_fields.append(xapwrap.document.TextField(name,field_name)) 28 print keys 29 d = xapwrap.document.Document(textFields=text_fields,sortFields=keys, uid=row._get_pk_val()) 26 30 idx.index(d) 27 31 idx.close() 28 32 29 33 def search(self, query, order_by='RELEVANCE'): 30 idx = Index(self.path)34 idx = xapwrap.index.Index(self.path) 31 35 if order_by == 'RELEVANCE': 32 36 results = idx.search(query, sortByRelevence=True) 33 37 else: … … 37 41 while order_by[0] in '+-': 38 42 order_by = order_by[1:] 39 43 results = idx.search(query, order_by, sortAscending=ascending) 40 return XapianResultSet(results )44 return XapianResultSet(results,self) 41 45 42 46 43 47 class XapianResultSet(ResultSet): … … 49 53 return len(self._hits) 50 54 51 55 def __iter__(self): 52 for hit in self._hits): 53 yield XapianHit(hit, self._indexer) 56 for hit in self._hits: 57 print hit 58 yield XapianHit(hit,self._indexer) 54 59 55 60 56 class XapianHit( object):61 class XapianHit(Hit): 57 62 def get_pk(self): 58 return self.data['pk'] 63 # FIXME: Hardcoded 'pk' field. 64 return self.data.get('pk') 59 65 66 def __getitem__(self, item): 67 return self.data.__getitem__(item) 68 60 69 def get_score(self): 61 return self.data ['score']70 return self.data.getScore() 62 71 63 72 score = property(get_score) 64 73