Example #1
0
 def test_get_prefix_matches(self):
     db.put(TestPerson(name='Bryan'))
     db.put(TestPerson(name='Bruce'))
     db.put(TestPerson(name='Benny'))
     db.put(TestPerson(name='Lenny'))
     test_query = TestPerson.all().order('name')
     # Test full string match
     test_criteria = {'name': 'bryan'}
     test_people = list(person.name for person in prefix.get_prefix_matches(
         test_query, 100, **test_criteria))
     assert test_people == ['Bryan']
     # Test 2-char prefix match
     test_criteria = {'name': 'br'}
     test_people = set(person.name for person in prefix.get_prefix_matches(
         test_query, 100, **test_criteria))
     assert test_people == set(['Bruce', 'Bryan'])
     # Test 1-char prefix match
     test_criteria = {'name': 'b'}
     test_people = set(person.name for person in prefix.get_prefix_matches(
         test_query, 100, **test_criteria))
     assert test_people == set(['Benny', 'Bruce', 'Bryan'])
     # Test limit
     test_criteria = {'name': 'b'}
     test_people = set(person.name for person in prefix.get_prefix_matches(
         test_query, 1, **test_criteria))
     assert test_people == set(['Benny'])
Example #2
0
 def test_get_prefix_matches(self):
     db.put(TestPerson(name='Bryan'))
     db.put(TestPerson(name='Bruce'))
     db.put(TestPerson(name='Benny'))
     db.put(TestPerson(name='Lenny'))
     test_query = TestPerson.all().order('name')
     # Test full string match
     test_criteria = {'name': 'bryan'}
     test_people = list(person.name for person in prefix.get_prefix_matches(
         test_query, 100, **test_criteria))
     assert test_people == ['Bryan']
     # Test 2-char prefix match
     test_criteria = {'name': 'br'}
     test_people = set(person.name for person in prefix.get_prefix_matches(
         test_query, 100, **test_criteria))
     assert test_people == set(['Bruce', 'Bryan'])
     # Test 1-char prefix match
     test_criteria = {'name': 'b'}
     test_people = set(person.name for person in prefix.get_prefix_matches(
         test_query, 100, **test_criteria))
     assert test_people == set(['Benny', 'Bruce', 'Bryan'])
     # Test limit
     test_criteria = {'name': 'b'}
     test_people = set(person.name for person in prefix.get_prefix_matches(
         test_query, 1, **test_criteria))
     assert test_people == set(['Benny'])
Example #3
0
 def search(self, criteria, new_search):
     if new_search:
         return indexing.search(Person, criteria, MAX_RESULTS)
     else:
         query = Person.all().order("entry_date")
         query = prefix.filter_prefix(query, **criteria)
         return list(prefix.get_prefix_matches(query, MAX_RESULTS, **criteria))