Beispiel #1
0
 def test_docids(self):
     from hypatia._compat import u
     index = self._makeOne()
     index.index_doc(1, u('now is the time'))
     index.index_doc(2, u("l'ora \xe9 ora"))
     index.index_doc(3, u("you have nice hair."))
     self.assertEqual(set(index.docids()), set((1, 2, 3)))
Beispiel #2
0
 def test_docids(self):
     from hypatia._compat import u
     index = self._makeOne()
     index.index_doc(1, u('now is the time'))
     index.index_doc(2, u("l'ora \xe9 ora"))
     index.index_doc(3, u("you have nice hair."))
     self.assertEqual(set(index.docids()), set((1, 2, 3)))
Beispiel #3
0
 def test_applyNotContains(self):
     from hypatia._compat import u
     index = self._makeOne()
     index.index_doc(1, u('now is the time'))
     index.index_doc(2, u("l'ora \xe9 ora"))
     result = sorted(index.applyNotContains('time'))
     self.assertEqual(result, [2])
Beispiel #4
0
 def test_applyNotContains(self):
     from hypatia._compat import u
     index = self._makeOne()
     index.index_doc(1, u('now is the time'))
     index.index_doc(2, u("l'ora \xe9 ora"))
     result = sorted(index.applyNotContains('time'))
     self.assertEqual(result, [2])
Beispiel #5
0
 def test_applyNotContains_nothing_indexed(self):
     from hypatia._compat import u
     def discriminator(obj, default):
         return default
     index = self._makeOne(discriminator)
     index.index_doc(1, u('now is the time'))
     index.index_doc(2, u("l'ora \xe9 ora"))
     index.index_doc(3, 3)
     result = sorted(index.applyNotContains('time'))
     self.assertEqual(result, [1, 2, 3])
Beispiel #6
0
    def test_document_repr(self):
        index = self._makeOne()
        # Fake out _get_frequencies, which is supposed to be overridden.
        def _faux_get_frequencies(wids):
            return dict([(y, x) for x, y in enumerate(wids)]), 1
        index._get_frequencies = _faux_get_frequencies

        index.index_doc(1, u('one two \u00dcnic\u00f6de'))

        self.assertEqual(index.document_repr(1), u('one two \u00dcnic\u00f6de'))
        self.assertEqual(index.document_repr(50, True), True)
Beispiel #7
0
    def test_applyNotContains_nothing_indexed(self):
        from hypatia._compat import u

        def discriminator(obj, default):
            return default

        index = self._makeOne(discriminator)
        index.index_doc(1, u('now is the time'))
        index.index_doc(2, u("l'ora \xe9 ora"))
        index.index_doc(3, 3)
        result = sorted(index.applyNotContains('time'))
        self.assertEqual(result, [1, 2, 3])
Beispiel #8
0
 def test_applyNotContains_with_unindexed_doc(self):
     from hypatia._compat import u
     from hypatia._compat import string_types
     def discriminator(obj, default):
         if isinstance(obj, string_types):
             return obj
         return default
     index = self._makeOne(discriminator)
     index.index_doc(1, u('now is the time'))
     index.index_doc(2, u("l'ora \xe9 ora"))
     index.index_doc(3, 3)
     result = sorted(index.applyNotContains('time'))
     self.assertEqual(result, [2, 3])
Beispiel #9
0
    def test_document_repr(self):
        index = self._makeOne()

        # Fake out _get_frequencies, which is supposed to be overridden.
        def _faux_get_frequencies(wids):
            return dict([(y, x) for x, y in enumerate(wids)]), 1

        index._get_frequencies = _faux_get_frequencies

        index.index_doc(1, u('one two \u00dcnic\u00f6de'))

        self.assertEqual(index.document_repr(1),
                         u('one two \u00dcnic\u00f6de'))
        self.assertEqual(index.document_repr(50, True), True)
Beispiel #10
0
    def test_applyNotContains_with_unindexed_doc(self):
        from hypatia._compat import u
        from hypatia._compat import string_types

        def discriminator(obj, default):
            if isinstance(obj, string_types):
                return obj
            return default

        index = self._makeOne(discriminator)
        index.index_doc(1, u('now is the time'))
        index.index_doc(2, u("l'ora \xe9 ora"))
        index.index_doc(3, 3)
        result = sorted(index.applyNotContains('time'))
        self.assertEqual(result, [2, 3])
Beispiel #11
0
    def test_docids_with_indexed_and_not_indexed(self):
        from hypatia._compat import u

        index = self._makeOne()
        index.index_doc(1, u("Am I rich yet?"))
        index.index_doc(2, _marker)
        self.assertEqual(set([1, 2]), set(index.docids()))
Beispiel #12
0
 def test_index_doc_missing_value_then_with_value(self):
     from hypatia._compat import u
     index = self._makeOne()
     index.index_doc(20, _marker)
     self.assertEqual(set(), set(index.applyContains('rich')))
     self.assertTrue(20 in index.docids())
     index.index_doc(20, u('Am I rich yet?'))
     self.assertEqual(set([20]), set(index.applyContains('rich')))
     self.assertTrue(20 in index.docids())
Beispiel #13
0
 def document_repr(self, docid, default=None):
     try:
         words = []
         wids = self.get_words(docid)
         for wid in wids:
             words.append(self._lexicon.get_word(wid))
         return u(' ').join(words)
     except KeyError:
         return default
Beispiel #14
0
 def document_repr(self, docid, default=None):
     try:
         words = []
         wids = self.get_words(docid)
         for wid in wids:
             words.append(self._lexicon.get_word(wid))
         return u(' ').join(words)
     except KeyError:
         return default
Beispiel #15
0
 def test_index_doc_missing_value_then_with_value(self):
     from hypatia._compat import u
     index = self._makeOne()
     index.index_doc(20, _marker)
     self.assertEqual(set(), set(index.applyContains('rich')))
     self.assertTrue(20 in index.docids())
     index.index_doc(20, u('Am I rich yet?'))
     self.assertEqual(set([20]), set(index.applyContains('rich')))
     self.assertTrue(20 in index.docids())
Beispiel #16
0
    def test_index_doc_then_missing_value(self):
        from hypatia._compat import u

        index = self._makeOne()
        index.index_doc(3, u("Am I rich yet?"))
        self.assertEqual(set([3]), set(index.applyContains("rich")))
        self.assertTrue(3 in index.docids())
        index.index_doc(3, _marker)
        self.assertEqual(set(), set(index.applyEq("rich")))
        self.assertTrue(3 in index.docids())
Beispiel #17
0
    def test_unicode(self):
        from hypatia._compat import u

        self.assertEqual(self._call_fut('u"foo"'), u("foo"))
Beispiel #18
0
 def test_docids_with_indexed_and_not_indexed(self):
     from hypatia._compat import u
     index = self._makeOne()
     index.index_doc(1, u('Am I rich yet?'))
     index.index_doc(2, _marker)
     self.assertEqual(set([1, 2]), set(index.docids()))
Beispiel #19
0
 def test_unicode(self):
     from hypatia._compat import u
     self.assertEqual(self._call_fut('u"foo"'), u('foo'))