简体   繁体   中英

Objectify filtering substrings in Datastore

I need to create an advanced Query Filter that is capable to search letters inside a word.

For example, if I find the word gel for Angel it would be do a matched filter.

Filter propertyFilter =  new FilterPredicate("name", FilterOperator.EQUAL, name);

Query<User> result = ObjectifyService.ofy().load().type(User.class)
                    .filter(propertyFilter);

The Query works only if the word is equals to the match.

The datastore is a poor fit for this kind of thing. It is pretty straightforward to do prefix-matching or suffix-matching but arbitrary text in the middle of a string requires indexing each fragment that could match; eg Angel becomes [Angel, ngel, gel, el, l] . It is somewhat expensive to store all this data and it doesn't scale well to long strings.

GAE's Search API tends to be better for this kind of thing, and stores the index more efficiently.

BTW this is a hard problem for databases. RDBMSes turn LIKE '%gel%' into a table scan, which only works for small datasets. Fulltext search engines typically only search for words, not for interior substrings.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM