summaryrefslogtreecommitdiff
path: root/django/contrib/search/hype.py
blob: 3ec20a98c538348473a96d6428e3e386354512ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from base import Indexer
from query import ResultSet, Hit

import hype

# TODO: This is very incomplete.

class HypeIndexer(Indexer):
    def __init__(self, *args, **kwargs):
        super(Indexer, self).__init__(*args, **kwargs)
        self.db = hype.Database(self.path, hype.ESTDBWRITER | hype.ESTDBCREAT)

    def index(self, row):
        document = hype.Document()
        document['@pk'] = row._get_pk_val()
        document.add_text()

    def search(self, query_string, sortBy=None):
        searcher = self.db.search(query_string)
        return HypeResultSet(searcher)

    def close(self):
        self.db.close()


class HypeResultSet(ResultSet):
    def __len__(self):
        return len(self._hits)

    def __iter__(self):
        for hit in self._hits:
            yield HypeHit(hit, self._indexer)

class HypeHit(Hit):
    pass