Commits

Anonymous committed 7b0990c

columns.py: PostingColumnReader shouldn't have been translating the bytes in sort_key() method.
Made TranslatingColumn wrapper optional in SegmentReader.column_reader(), changed sorting code to not use it.

Comments (0)

Files changed (4)

src/whoosh/columns.py

             for docid in postings.all_ids():
                 values[docid] = btext
 
-    def sort_key(self, docnum, reverse=False):
-        return self._frombytes(self._values.get(docnum, emptybytes))
-
     def __len__(self):
         return self._length
 

src/whoosh/reading.py

         coltype = self.schema[fieldname].column_type
         return coltype and self._perdoc.has_column(fieldname)
 
-    def column_reader(self, fieldname, column=None):
+    def column_reader(self, fieldname, column=None, translate=True):
         fieldobj = self.schema[fieldname]
         if self.has_column(fieldname):
             ctype = column or fieldobj.column_type
             creader = self._perdoc.column_reader(fieldname, ctype)
-
-            # Wrap the column in a translator to present nice values to the
-            # caller instead of sortable column values
-            translate = fieldobj.from_column_value
-            creader = columns.TranslatingColumnReader(creader, translate)
+            if translate:
+                # Wrap the column in a Translator to give the caller
+                # nice values instead of sortable representations
+                fcv = fieldobj.from_column_value
+                creader = columns.TranslatingColumnReader(creader, fcv)
         else:
             # If the field wasn't indexed with a column, create one from
             # postings and cache it

src/whoosh/sorting.py

 
     def set_searcher(self, segment_searcher, docoffset):
         r = segment_searcher.reader()
-        self._creader = r.column_reader(self._fieldname)
+        self._creader = r.column_reader(self._fieldname, translate=False)
 
     def key_for(self, matcher, segment_docnum):
         return self._creader.sort_key(segment_docnum, self._reverse)
         reader = global_searcher.reader()
         self._doccount = reader.doc_count_all()
 
-        global_creader = reader.column_reader(fieldname)
+        global_creader = reader.column_reader(fieldname, translate=False)
         self._values = sorted(set(global_creader))
 
     def key_for(self, matcher, segment_docnum):
         if self._use_vectors:
             pass
         elif self._use_column:
-            self._creader = reader.column_reader(fieldname)
+            self._creader = reader.column_reader(fieldname, translate=False)
         else:
             # Otherwise, cache the values in each document in a huge list
             # of lists

tests/test_results.py

         r = s.search(query.Term("text", "alfa"))
         assert len(r) == 1
         hit = r[0]
-        assert hit["text"] == "alfa bravo charlie"
+        assert hit["text"] == u("alfa bravo charlie")