1

In Google App Engine, how do I match strings that contain strings? My datastore contains 'tester' and if I pass in 'est' then tester should be returned.

Filter myFilter =  new FilterPredicate("name",FilterOperator.IN, "est");

But I receive this error: A collection of values is required

I do not think I am using the filter correctly.

dda
  • 6,030
  • 2
  • 25
  • 34
blue-sky
  • 51,962
  • 152
  • 427
  • 752
  • it seems cannot do a wildcard search on app engine : http://stackoverflow.com/questions/1402769/wildcard-search-on-appengine-in-python – blue-sky Dec 01 '12 at 22:27

3 Answers3

1

You can't use an IN filter the way you described. IN works if you give a list of strings, and want to match one of the strings in the given list.

The search API exists for what you're trying to do: https://developers.google.com/appengine/docs/python/search/overview

It's possible to find strings that start with a substring using a greater than/less than search, but you'll need to use the Search API if you want to find the substring anywhere in the string.

dragonx
  • 14,963
  • 27
  • 44
0

A possible solution to this, even though app engine does not support wildcards is to insert every possible sequential combination to the datastore.

So if wanted to do a wildcard search on 'design'

Add the following entries :

'd'
'de'
'des'
'desi'
'desig'
'design'
'e'
'es'
'esi'
'esig'
'esign'
's'
'si'
'sig'
'sign'
'i'
'ig'
'ign'
'g'
'gn'
'n'

These are all possible combinations for a wildcard search on 'design'. Although this is very wasteful of data storage memory.

blue-sky
  • 51,962
  • 152
  • 427
  • 752
0

Since strings can be compaired with >= and <= you could store the combinations:
design
esign
sign
ign
gn
n

To search for all names with 'sign' in them you would do a query for:

name >= 'sign' AND name <= 'sign\uffffd'

Practically you may get away with limiting the combination truncation to say 4 characters; few people are likely to need a full set of results for a search for all names with 'n' in.

andrew pate
  • 3,833
  • 36
  • 28