Esempio n. 1
0
def _reindex(user):
    index = []
    for term in search.scrub(unicode(user)).split():
        for i in range(len(term) + 1):
            index.append(term[0:i])
    if user.dj_name is not None:
        for term in search.scrub(user.dj_name).split():
            for i in range(len(term) + 1):
                index.append(term[0:i])
    user.index = index
Esempio n. 2
0
def _reindex(user):
    index = []
    for term in search.scrub(unicode(user)).split():
        for i in range(len(term) + 1) :
            index.append(term[0:i])
    if user.dj_name is not None:
        for term in search.scrub(user.dj_name).split():
            for i in range(len(term) + 1):
                index.append(term[0:i])
    user.index = index
    def test_scrub(self):
        self.assertEqual(u"", search.scrub(u""))
        self.assertEqual(u"    ", search.scrub(u" \t\n\r"))

        self.assertEqual(u"foo", search.scrub(u"foo"))
        self.assertEqual(u"foo123", search.scrub(u"foo123"))

        self.assertEqual(u"foo ", search.scrub(u"Foo!"))
        self.assertEqual(u"oao", search.scrub(u"Øåø"))

        # Interior periods should be collapsed.
        self.assertEqual(u"la ", search.scrub(u"L.A."))
        self.assertEqual(u"gg  allen", search.scrub(u"G.G. Allen"))
Esempio n. 4
0
    def test_scrub(self):
        self.assertEqual(u"", search.scrub(u""))
        self.assertEqual(u"    ", search.scrub(u" \t\n\r"))

        self.assertEqual(u"foo", search.scrub(u"foo"))
        self.assertEqual(u"foo123", search.scrub(u"foo123"))

        self.assertEqual(u"foo ", search.scrub(u"Foo!"))
        self.assertEqual(u"oao", search.scrub(u"Øåø"))

        # Interior periods should be collapsed.
        self.assertEqual(u"la ", search.scrub(u"L.A."))
        self.assertEqual(u"gg  allen", search.scrub(u"G.G. Allen"))
Esempio n. 5
0
def user_search_for_autocomplete(request):
    match_users = []
    response = http.HttpResponse(mimetype="text/plain")
    terms = [term for term in search.scrub(request.GET.get('q', '')).split()]
    for term in terms:
        query = User.all()
        query.filter("is_active =", True).filter("index =", term)
        users = AutoRetry(query).fetch(999)
        if (len(users) > 0):
            for user in users:
                match_users.append(user)
            break
    for user in match_users:
        response.write("%s|%s\n" % (user, user.key()))
        if user.dj_name is not None:
            response.write("%s|%s\n" % (user.dj_name, user.key()))
    return response
Esempio n. 6
0
def user_search_for_autocomplete(request):
    match_users = []
    response = http.HttpResponse(mimetype="text/plain")
    terms = [term for term in search.scrub(request.GET.get('q', '')).split()]
    for term in terms:
        query = User.all()
        query.filter("is_active =", True).filter("index =", term)
        users = AutoRetry(query).fetch(999)
        if (len(users) > 0):
            for user in users:
                match_users.append(user)
            break
    for user in match_users :
        response.write("%s|%s\n" % (user, user.key()))
        if user.dj_name is not None:
            response.write("%s|%s\n" % (user.dj_name, user.key()))
    return response