Question

How do I perform a full text search of Google AppEngine Datastore with JPA and LIKE? I tried the following but it gave an error.

Error

Caused by: com.google.appengine.datanucleus.query.DatastoreQuery$UnsupportedDatastoreFeatureException: Problem with query <SELECT s FROM Study s WHERE description like :desc>: Wildcard must appear at the end of the expression string (only prefix matches are supported)

Code

    TypedQuery<Study> tq = emf.createQuery(query, Study.class);
    if (hasKeywords) tq.setParameter("desc", "%" + keywords + "%");

I tried removing the first %, and it worked. That's not very useful however. The description field is a string, not a blob.

Version

appengine-api-1.0-sdk-1.8.6.jar

Was it helpful?

Solution

This is a known limitation. What you want to do instead is use their Search APIs for doing a full text search.

You can write a entity modification listener that updates the search index every time the entity is modified. This listener can then queue a job (via task queues) that will update the search index.

Now in the screen where you are displaying the search box, you can use the Search APIs to fetch the result.

....

Or, the alternative is to live with a prefix only search query.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top