Esempio n. 1
0
def wordPartsGenerator(word):
    return q.let(
        {
            "indexes":
            q.map_(
                # Reduce this array if you want less ngrams per word.
                # Setting it to [ 0 ] would only create the word itself, Setting it to [0, 1] would result in the word itself
                # and all ngrams that are one character shorter, etc..
                lambda index: q.subtract(q.length(word), index),
                maxNgrams),
            "indexesFiltered":
            q.filter_(
                # left min parts length 3
                lambda l: q.gte(l, 3),
                q.var('indexes')),
            "ngramsArray":
            q.distinct(
                q.union(
                    q.map_(lambda l: q.ngram(q.lowercase(word), l, l),
                           q.var('indexesFiltered'))))
        },
        q.var('ngramsArray'))
 def test_length(self):
     self.assertJson(query.length('hello'), '{"length":"hello"}')
Esempio n. 3
0
 def test_length(self):
     self.assertEqual(self._q(query.length("")), 0)
     self.assertEqual(self._q(query.length("A")), 1)
     self.assertEqual(self._q(query.length("ApPle")), 5)
     self.assertEqual(self._q(query.length("two words")), 9)