Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6687759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:19:35+00:00 2026-05-26T05:19:35+00:00

I use jQuery UI autocomplete widget . Also I have GAE datastore: class Person(db.Model):

  • 0

I use jQuery UI autocomplete widget. Also I have GAE datastore:

class Person(db.Model):
    # key_name contains person id in format 'lastname-firstname-middlename-counter',
    # counter and leading dash are omitted, if counter=0
    first_name = db.StringProperty()
    last_name = db.StringProperty()
    middle_name = db.StringProperty()

How can I search the person in the autocomplete widget, when user can input there surname, first name and/or middle name?

So, I am getting user input string as self.request.get('term'). How should I search for the same in my datastore (since I need to look at each field and probably for combined value of 3 fields)? How to optimize such query?
I am also not clear what should be the reply format. jQuery doc says:

A data source can be:

an Array with local data
a String, specifying a URL
a Callback

The local data can be a simple Array of Strings, or it contains
Objects for each item in the array, with either a label or value
property or both.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T05:19:35+00:00Added an answer on May 26, 2026 at 5:19 am

    There are a few neat tricks here. Consider this augmented model:

    class Person(db.Model):
      first_name = db.StringProperty()
      last_name = db.StringProperty()
      middle_name = db.StringProperty()
      names_lower = db.StringListProperty()
    

    You’ll need to keep names_lower in sync with the real fields, e.g.:

    p.names_lower = [p.first_name.lower(), p.last_name.lower(),
                     p.middle_name.lower()]
    

    You can do this more elegantly with a DerivedProperty.

    And now, your query:

    term = self.request.get('term').lower()
    query = Person.all()
    query.filter('names_lower >=', term)
    query.filter('names_lower <=', unicode(term) + u"\ufffd")
    

    This gives you:

    • Matching on all 3 properties with one index
    • Case insensitive matches
    • Wildcard suffix matches

    So a query for “smi” will return any person with any name starting with “smi” in any case.

    Copying lower-cased names to a ListProperty enables case-insensitive matching, and allows us to search all 3 fields with one query. “\ufffd” is the highest possible unicode character, so it’s the upper limit for our substring match. If for some reason you want an exact match, filter for 'names_lower =', term instead.

    Edit:

    How should I search for the same in my datastore (since I need to look
    at each field and probably for combined value of 3 fields)? How to
    optimize such query?

    This is already accounted for in the original solution. By taking the 3 fields and copying them to a single ListProperty, we’re essentially creating a single index with multiple entries per person. If we have a person named Bob J Smith, he’ll have 3 hits in our index:

    • names_lower = bob
    • names_lower = j
    • names_lower = smith

    This eliminates the need to run distinct queries on each field.

    I am also not clear what should be the reply format.

    Read the docs carefully. Formatting output for jQuery should be pretty straightforward. Your data source will be a string specifying a URL, and you’ll want to format the response as JSON.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have use rails3-jquery-autocomplete plugin and I am just wondering how can I use
I'm using the jQuery UI Autocomplete widget. I need to use the selected text
I try to use jQUery-UI autocomplete plugin with a list of inputs that have
I'm trying to use the jQuery autocomplete plugin. I have an array of IDs
I use Jquery Autocomplete in my mvc3 application. I have a lot of textbox,
I use jquery.autocomplete , which uses a javascript regexp to highlight substrings in the
I am trying to use jquery autocomplete plugin, I want it to suggest ItemCodes
When I use JQuery's autocomplete and hardcode the array values in the page it
I'm trying to use JQuery's autocomplete plug-in but for some reasons Internet Explorer is
I'm struggling with the following problem. I use the jQuery autocomplete plugin to get

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.