JPA LIKE with % support
I'm trying to do the following:
query = em.createQuery("SELECT l from Location l WHERE l.nameLowerCase LIKE :nameParam ORDER BY l.nameLowerCase ASC"); query.setParameter("nameParam", nameprefix+"%");
I've therefore turned on Lucene, since I believe that with Cassandra at any rate, this will be the only way to do this.
I get an error:
...om.impetus.kundera.index.LuceneIndexer: Searching index with query[+Location.nameLowerCase:back creek, nsw, australia%* AND +entity.class:co.twickets.core.location], start:-1, count:10
I think that there are two things wrong with the generated query:
- The entire text string should be enclosed in quotes.
- The % is being left in the query string, JPQL looks to me to copy standard sql in this behaviour.
Hi, Did you turn lucene on, while persisting data for Location entity?
-Vivek
Yes, I added the Lucene index file location into persistence.xml, stopped the system, truncated all my column families, restarted and reloaded my data. It appears to be generating the index fine - the problem I think is with the generated query which doesn't seem to be valid.
Actually reading the Lucene docs more, wildcard queries and phrases aren't supported in the standard query language.
Hummm...
Yes. Like clause should work without "%" as well. "%" is not supported yet. Also As of now support limits to very basic, We have a plan to create complete translation platform to support like "BooleanTerm" and other Term queries etc provided by Lucene.
Reason is with Lucene, performance is really not that good and also it is not scalable, so we suggest to stick with Cassandra secondary indexing.
-Vivek
I'd really prefer not to use Lucene, I agree with you comments, however as far as I can see Cassandra doesn't support this through secondary indexes either (although I'm new to cassandra, so could well be wrong here, I'm sure you can set me straight).
I'm actually translating an app from Google App Engine's data store, and have some range queries to look up data objects such as (very basic version):
select x from Thing where name LIKE 'prefix%';
In GAE you do the following:
select x from Thing where name >= 'prefix' and name < 'prefix'+'\uffff' order by name;
However tried this in cassandra and it doesn't work - it seems that you need at least one equals clause when you use an index, which is why I tried switching on the lucene index.
I'll try and understand the equals restriction more to see if I can work out another way.
Thanks!
- Daniel
I hope you must have tried,
select x from Thing where name LIKE 'prefix'(without '%').
Here is one alternative provided by Kundera , which is using "inverted index".
Here is the link : https://github.com/impetus-opensource/Kundera/wiki/Cassandra-Specific-Features
-Vivek
Additionally you can also think about "cross data store" persistence, which means any such support, which is not available with Cassandra, You can migrate those to RDBMS, and still can use Kundera to fetch all such associations.
It is totally a design decision.
Thanks, Vivek
The first suggestion - I assume you are talking about that in the context of lucene, not sure how well it would match what I'm trying to do - I need startsWith() semantics.
Second point Thanks - I saw that but forgot to go back to it, I will review and try that.
Third point (RDBMS) - sure, there's always that option, not sure I want to do that as it increases complexity.
By the way do you want me to close the other issues or do you leave them open up until next release?
Ok. I think issue#91 need work for different key_validation_class. If other issues are fine with you, please go ahead to close them.
-Vivek
From: dstrawson [email protected] To: Vivek Mishra [email protected] Sent: Monday, July 30, 2012 9:59 PM Subject: Re: [Kundera] JPA LIKE with % support (#93)
The first suggestion - I assume you are talking about that in the context of lucene, not sure how well it would match what I'm trying to do - I need startsWith() semantics.
Second point Thanks - I saw that but forgot to go back to it, I will review and try that.
Third point (RDBMS) - sure, there's always that option, not sure I want to do that as it increases complexity.
By the way do you want me to close the other issues or do you leave them open up until next release?
Reply to this email directly or view it on GitHub: https://github.com/impetus-opensource/Kundera/issues/93#issuecomment-7373465