Skip to content
This repository has been archived by the owner on May 27, 2020. It is now read-only.

Cassandara lucene index support for Spring Data cassandra? #138

Closed
Prasanthmv opened this issue May 24, 2016 · 3 comments
Closed

Cassandara lucene index support for Spring Data cassandra? #138

Prasanthmv opened this issue May 24, 2016 · 3 comments

Comments

@Prasanthmv
Copy link

Hi,

I am using spring data cassandra . I would like to use cassandra lucene index for quering the data . But while using thse queries getting following error
Exception in thread "main" com.datastax.driver.core.exceptions.SyntaxError: line 1:98 missing EOF at '12341' (... associations WHERE lucene = '{query : {type : "match",field : "physicianid",value :'[12341]'}...) at com.datastax.driver.core.exceptions.SyntaxError.copy(SyntaxError.java:35) at com.datastax.driver.core.DefaultResultSetFuture.extractCauseFromExecutionException(DefaultResultSetFuture.java:269) at com.datastax.driver.core.DefaultResultSetFuture.getUninterruptibly(DefaultResultSetFuture.java:183) at com.datastax.driver.core.AbstractSession.execute(AbstractSession.java:52) at org.springframework.cassandra.core.CqlTemplate$12.doInSession(CqlTemplate.java:503) at org.springframework.cassandra.core.CqlTemplate$12.doInSession(CqlTemplate.java:494) at org.springframework.cassandra.core.CqlTemplate.doExecute(CqlTemplate.java:471) at org.springframework.cassandra.core.CqlTemplate.doExecute(CqlTemplate.java:494) at org.springframework.cassandra.core.CqlTemplate.doExecute(CqlTemplate.java:483)

My query method is given below
@Query("SELECT * FROM associations WHERE lucene = '{query : {type : \"match\",field : \"physicianid\",value :?0}}'") List<Associations> findByPhysicianId(String physicianid);

Is there any way to escape the value ? Please help

@ealonsodb
Copy link
Contributor

ealonsodb commented May 24, 2016

Hi @Prasanthmv:

Can you tell us which type is 'physicianid'?

I think that you want to build this query:

SELECT * FROM associations WHERE lucene = '{query : {type : "match",field : "physicianid",value :"12341"}}' 

but you are getting from springdata:

SELECT * FROM associations WHERE lucene = '{query : {type : "match",field : "physicianid",value :'12341'}}' 

because springdata traits physicalid as a casssandra string and encloses between '.

Then, the cassandra driver is lokkiing at the query as:

SELECT * FROM associations WHERE lucene = '{query : {type : "match",field : "physicianid",value :' 

and trying to find the end character ';' after this fails.

You need to avoid springdata to format "physicianid" String.

As a workaround you can try with:

@Query("SELECT * FROM associations WHERE lucene = '{query : {type : \"match\",field : \"physicianid\",value :\"?0\"}}'") List<Associations> findByPhysicianId(Integer physicianid);

Or change the 'physicianid' type to a cassandra number(int, bigint...)

Cheers

@Prasanthmv
Copy link
Author

Prasanthmv commented May 24, 2016

Hi,
The type of physicianid i have given is text in Cassandra .

@adelapena
Copy link
Contributor

Hi,

You can also try with this, using the query builder:

import static com.stratio.cassandra.lucene.builder.Builder.*;

...

@Query("SELECT * FROM associations WHERE lucene = ?") 
List<Associations> findByPhysicianId(String json);

List<Associations> findByPhysicianId(Integer physicianid) {
   String json = search().query(match("physicianid", physicianid)).build();
   return findByPhysicianId(json);
}

By the way, are you sure you want to do this search using a relevance query? Maybe a filter is enough:

SELECT * FROM associations WHERE lucene = '{filter : {type : "match",field : "physicianid",value :"12341"}}'

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants