質問

I need to be able to search for substrings in a text field, via a parameterised repository method, in neo4j 1.9.5

Ideally I want to be able to call

getInteractionsByTermAndDateRange(String term,
        long startMillis, long endMillis

and get back every WRInteraction where the 'content' field contains 'term', with the pubMillis value within the specified range( 'content' is specified as a FULLTEXT index in the WRInteraction object declaration)

First attempt:

@Query("START  n=node:WRInteraction('content:*{0}*') " + " WHERE "
        + "    n.pubMillis >= {1} AND n.pubMillis <= {2}" + " RETURN "
        + "     n")
Iterable<WRInteraction> getInteractionsByTermAndDateRange(String term,
        long startMillis, long endMillis);

This throws

Caused by: org.apache.lucene.queryParser.ParseException: Cannot parse 'content:*{0}*': 
Encountered " "}" "} "" at line 1, column 11.
Was expecting one of:
"TO" ...
<RANGEEX_QUOTED> ...
<RANGEEX_GOOP> ...

at org.apache.lucene.queryParser.QueryParser.parse(QueryParser.java:211) ~[lucene-core-3.6.2.jar:3.6.2 1423725 - rmuir - 2012-12-18 19:45:40]
at org.neo4j.index.impl.lucene.IndexType.query(IndexType.java:300) ~[neo4j-lucene-index-1.9.5.jar:1.9.5]

Second try -- pass the whole lucene query via the parameter:

@Query("START  n=node:WRInteraction('content:{0}') " + " WHERE "
        + "    n.pubMillis >= {1} AND n.pubMillis <= {2}" + " RETURN "
        + "     n")

doesn't fare any better... what's the pattern I should be using here? The key requirement is to be able to pass a substring to a repository method as a parameter, and return any WRInteractions where that substring is present int he 'content' field. Should be easy, right?

Thanks

役に立ちましたか?

解決

You need to specify the lucene query as a whole.

@Query("START n=node:WRInteraction({0}) WHERE n.pubMillis >= {1} AND n.pubMillis <= {2} RETURN n")
Iterable<WRInteraction> getInteractionsByTermAndDateRange(String query,
        long startMillis, long endMillis);

Call this method like:

repository.getInteractionsByTermAndDateRange("content:*" + term + "*", 0, 0);
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top