kundera icon indicating copy to clipboard operation
kundera copied to clipboard

Kundera doesn't escape ids before sending them to lucene

Open rsshilli opened this issue 13 years ago • 5 comments

I'm doing the following with Lucene indexing turned on:

                List<Contact> contacts = entityManager.createQuery("select c from Contact c where c.linkedInId = :id", Contact.class)
                        .setParameter("id", person.getId())
                        .getResultList();

getting the following exception:

com.impetus.kundera.KunderaException: com.impetus.kundera.index.LuceneIndexingException: org.apache.lucene.queryParser.ParseException: Cannot parse '+entity.class:com.onlyinsight.peoplelinker.shared.contact.contact AND +Contact.linkedInId:-h_eWbaB98': Encountered " "-" "- "" at line 1, column 90.
Was expecting one of:
    "(" ...
    "*" ...
    <QUOTED> ...
    <TERM> ...
    <PREFIXTERM> ...
    <WILDTERM> ...
    "[" ...
    "{" ...
    <NUMBER> ...

        at com.impetus.kundera.persistence.EntityManagerImpl.persist(EntityManagerImpl.java:174)
        at com.onlyinsight.peoplelinker.server.oAuth.OAuthServlet.doGet(OAuthServlet.java:130)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
        at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
        at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:390)
        at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
        at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
        at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
        at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:440)
        at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:230)
        at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)
        at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
        at org.mortbay.jetty.Server.handle(Server.java:326)
        at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
        at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:926)
        at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:549)
        at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
        at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
        at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:410)
        at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
Caused by: com.impetus.kundera.index.LuceneIndexingException: org.apache.lucene.queryParser.ParseException: Cannot parse '+entity.class:com.onlyinsight.peoplelinker.shared.contact.contact AND +Contact.linkedInId:-h_eWbaB98': Encountered " "-" "- "" at line 1, column 90.
Was expecting one of:
    "(" ...
    "*" ...
    <QUOTED> ...
    <TERM> ...
    <PREFIXTERM> ...
    <WILDTERM> ...
    "[" ...
    "{" ...
    <NUMBER> ...

        at com.impetus.kundera.index.LuceneIndexer.unindex(LuceneIndexer.java:275)
        at com.impetus.kundera.index.IndexManager.update(IndexManager.java:119)
        at com.impetus.kundera.client.ClientBase.indexNode(ClientBase.java:195)
        at com.impetus.client.cassandra.pelops.PelopsClient.indexNode(PelopsClient.java:557)
        at com.impetus.kundera.client.ClientBase.persist(ClientBase.java:87)
        at com.impetus.kundera.lifecycle.states.ManagedState.handleFlush(ManagedState.java:182)
        at com.impetus.kundera.graph.Node.flush(Node.java:525)
        at com.impetus.kundera.persistence.PersistenceDelegator.flush(PersistenceDelegator.java:452)
        at com.impetus.kundera.persistence.PersistenceDelegator.persist(PersistenceDelegator.java:181)
        at com.impetus.kundera.persistence.EntityManagerImpl.persist(EntityManagerImpl.java:168)
        ... 20 more

I even tried using the Lucene Query Parser escaping, but that doesn't seem to help.

                List<Contact> contacts = entityManager.createQuery("select c from Contact c where c.linkedInId = :id", Contact.class)
                        .setParameter("id", QueryParser.escape(person.getId()))
                        .getResultList();

Same exception.

Also - I wanted you to know how much I'm enjoying Kundera. As a hibernate junkie, after struggling with Hector for a while, I finally gave up and started using Kundera a few days ago. Much better! Thank you creating this.

rsshilli avatar May 03 '13 21:05 rsshilli

Also, is there a way to tell Kundera to "not use Lucene for this query/column"? That would be a super useful feature. It's awesome when you need it but I'd rather use just straight Cassandra when I'm just searching for an exact match on a primary key, etc.

rsshilli avatar May 03 '13 21:05 rsshilli

If you don't specify "index.home.dir", it will automatically use Cassandra's secondary indexes.

Have a look at: https://github.com/impetus-opensource/Kundera/blob/trunk/kundera-cassandra/src/test/java/com/impetus/client/crud/PersonCassandraTest.java

for running without Lucene.

To run with Lucene, please have a look at:

https://github.com/impetus-opensource/Kundera/blob/trunk/kundera-cassandra/src/test/java/com/impetus/client/crud/PersonCassandraLuceneTest.java

Hope it helps!

-Vivek

mevivs avatar May 04 '13 04:05 mevivs

Coming back to original error, can you share given below details:

  1. Version of Lucene
  2. persistence.xml and code snippet to replicate this issue.

-Vivek

mevivs avatar May 04 '13 04:05 mevivs

Please provide more details on this issue.

-Vivek

Hi, This is what I have tried with latest version ie kundera-2.7 and working fine.

With single quotes:

        List<PersonLucene> allPersons = em.createQuery("select p from PersonLucene p where p.personName = 'vivek'",
                PersonLucene.class).getResultList();

        Assert.assertNotNull(allPersons);
        Assert.assertEquals(3, allPersons.size());

        allPersons = em.createQuery("select p from PersonLucene p where p.personId = :id", PersonLucene.class)
                .setParameter("id", "'1'").getResultList();

        Assert.assertNotNull(allPersons);
        Assert.assertEquals(1, allPersons.size());

With lucene keyword (+ and &):

        allPersons = em.createQuery("select p from PersonLucene p where p.personId = :id", PersonLucene.class)
                .setParameter("id", QueryParser.escape("+1")).getResultList();

        Assert.assertNotNull(allPersons);
        Assert.assertEquals(1, allPersons.size());

        allPersons = em.createQuery("select p from PersonLucene p where p.personId = :id", PersonLucene.class)
                .setParameter("id", QueryParser.escape("&1")).getResultList();

Please give a try with 2.7 and let me know if we have anything to discuss.

Thanks Kuldeep

kkmishra avatar Sep 11 '13 09:09 kkmishra