google app engine - GAE, how to search a text string in datastore? -


i have table following definition

entity(name = "historyvisitsdevicejpa") public class historyvisitsdevicejpa {          @id         @generatedvalue(strategy = generationtype.identity)         private long id;         private text pageaddress;         private long date;          @override         public boolean equals(object o) {             if (this == o) return true;             if (o == null || getclass() != o.getclass()) return false;              historyvisitsdevicejpa = (historyvisitsdevicejpa) o;              if (!pageaddress.equals(that.pageaddress)) return false;              return true;         }          @override         public int hashcode() {             return pageaddress.hashcode();         }      // other setter , getter methods     } 

i've stored url in pageaddress filed , it's time stamp in date field. want search in records based on pageaddress , pull list of matched objects.

my query this:

private static final string query_history_visits = "select m historyvisitsdevicejpa m m.pageaddress :keyword";  try {                 system.out.println("1");                 query q = em.createquery(query_history_visits).setparameter("keyword", urlparam);                  @suppresswarnings("unchecked")                 list<historyvisitsdevicejpa> dblist = (list<historyvisitsdevicejpa>) q.getresultlist();                 string jsonstring = printjson_historyvisitsdevicejpa(dblist);                 if(jsonstring != null) {                     printwriter out = response.getwriter();                     out.println(jsonstring);                 }             } {                 if (em != null)                     em.close();             } 

when run application, i'm getting following error:

problem query <select historyvisitsdevicejpa m m.pageaddress :keyword>: wildcard must appear @ end of expression string (only prefix matches supported) 

i tried add '%' @ end of string not successful. suggestion appreciated. thanks.

keep static final string query_history_visits shown , change

setparameter("keyword", urlparam); 

to

setparameter("keyword", urlparam+"%"); 

assuming consistent program logic.


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -