Ticket #2707: patch1.diff

File patch1.diff, 2.4 KB (added by sdm@…, 18 years ago)

Patch for Xapian

  • django/contrib/search/xapian.py

     
    44import xapwrap.document
    55from itertools import imap
    66
    7 from base import Indexer, ResultSet
     7from query import ResultSet, Hit
     8from base import Indexer
    89
    910# TODO: This is incomplete.
    1011
     
    1718        else:
    1819            update_queue = documents
    1920
    20         for row in documents:
     21        for row in update_queue:
    2122            keys = []
     23            text_fields = []
    2224            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())
    2630            idx.index(d)
    2731        idx.close()
    2832
    2933    def search(self, query, order_by='RELEVANCE'):
    30         idx = Index(self.path)
     34        idx = xapwrap.index.Index(self.path)
    3135        if order_by == 'RELEVANCE':
    3236            results = idx.search(query, sortByRelevence=True)
    3337        else:
     
    3741            while order_by[0] in '+-':
    3842                order_by = order_by[1:]
    3943            results = idx.search(query, order_by, sortAscending=ascending)
    40         return XapianResultSet(results)
     44        return XapianResultSet(results,self)
    4145
    4246
    4347class XapianResultSet(ResultSet):
     
    4953        return len(self._hits)
    5054
    5155    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)
    5459
    5560
    56 class XapianHit(object):
     61class XapianHit(Hit):
    5762    def get_pk(self):
    58         return self.data['pk']
     63        # FIXME: Hardcoded 'pk' field.
     64        return self.data.get('pk')
    5965
     66    def __getitem__(self, item):
     67        return self.data.__getitem__(item)
     68
    6069    def get_score(self):
    61         return self.data['score']
     70        return self.data.getScore()
    6271
    6372    score = property(get_score)
    6473
Back to Top