Hi team,
The below code :
queryString = "piccadilly*";
Query queryToExecute = new StandardQueryParser().parse(queryString,
"stationNameIndex");
LuceneQuery<Long, Station> luceneQuery =
luceneService
.createLuceneQueryFactory()
.setLimit(100)
.create(
"stationNameIndex",
"stations-region",
index -> {
return new BooleanQuery.Builder()
.add(queryToExecute, BooleanClause.Occur.MUST)
.build();
});
Collection<Station> stations = luceneQuery.findValues();
*throws the below error : *
Error while querying => {}
org.apache.geode.SerializationException: failed serializing object
at
org.apache.geode.internal.cache.tier.sockets.Message.serializeAndAddPart(Message.java:408)
at
org.apache.geode.internal.cache.tier.sockets.Message.addObjPart(Message.java:350)
at
org.apache.geode.internal.cache.tier.sockets.Message.addObjPart(Message.java:329)
at
org.apache.geode.cache.client.internal.ExecuteRegionFunctionSingleHopOp$ExecuteRegionFunctionSingleHopOpImpl.<init>(ExecuteRegionFunctionSingleHopOp.java:180)
at
org.apache.geode.cache.client.internal.ServerRegionProxy.lambda$executeFunction$1(ServerRegionProxy.java:699)
at
org.apache.geode.cache.client.internal.ExecuteRegionFunctionSingleHopOp.constructAndGetExecuteFunctionTasks(ExecuteRegionFunctionSingleHopOp.java:131)
at
org.apache.geode.cache.client.internal.ExecuteRegionFunctionSingleHopOp.execute(ExecuteRegionFunctionSingleHopOp.java:84)
at
org.apache.geode.cache.client.internal.ServerRegionProxy.executeFunction(ServerRegionProxy.java:701)
at
org.apache.geode.internal.cache.execute.ServerRegionFunctionExecutor.executeOnServer(ServerRegionFunctionExecutor.java:200)
at
org.apache.geode.internal.cache.execute.ServerRegionFunctionExecutor.executeFunction(ServerRegionFunctionExecutor.java:154)
at
org.apache.geode.internal.cache.execute.ServerRegionFunctionExecutor.execute(ServerRegionFunctionExecutor.java:379)
at
org.apache.geode.cache.lucene.internal.LuceneQueryImpl.findTopEntries(LuceneQueryImpl.java:121)
at
org.apache.geode.cache.lucene.internal.LuceneQueryImpl.findPages(LuceneQueryImpl.java:99)
at
org.apache.geode.cache.lucene.internal.LuceneQueryImpl.findResults(LuceneQueryImpl.java:85)
at
org.apache.geode.cache.lucene.internal.LuceneQueryImpl.findValues(LuceneQueryImpl.java:78)
whereas
LuceneQuery<Long, Station> luceneQuery =
luceneService
.createLuceneQueryFactory()
.setLimit(100)
.create(
"stationNameIndex",
"stations-region",
queryString,
"stationName"
});
works perfectly & Station implements org.apache.geode.DataSerializable.
What am I missing?.
Please help.
Regards,
Aj
On Tue, Jan 28, 2020 at 11:31 PM Xiaojian Zhou <[email protected]> wrote:
> Maybe you should change one or both of the "MUST" to "SHOULD". And it's
> better to switch the order of the 2 subqueries.
>
>
> On Tue, Jan 28, 2020 at 2:23 PM vas aj <[email protected]> wrote:
>
>> Thanks Dan for the quick help.
>> However the query failed.
>>
>> Working on the same.
>>
>> On Tue, 28 Jan 2020, 19:55 Dan Smith, <[email protected]> wrote:
>>
>>> I think you could probably use a BooleanQuery to do this. Something like
>>> this, although I haven't tested it. Your LuceneQuery1 just results in a
>>> call to StandardQueryParser.parse, so you can combine that with your
>>> spatial query:
>>>
>>> LuceneQuery<Long, Station> luceneQuery2 =
>>> luceneService
>>> .createLuceneQueryFactory()
>>> .create("stationNameIndex", "stations-region", index -> {
>>> BooleanQuery query = new BooleanQuery();
>>> query.add(new StandardQueryParser().parse(queryString,
>>> name), BooleanQuery.Occur.MUST);
>>> query.add(SpatialHelper.findWithin(-122.8515139, 45.5099231,
>>> 0.5), , BooleanQuery.Occur.MUST);
>>> return query;
>>> }
>>>
>>> On Tue, Jan 28, 2020 at 11:36 AM vas aj <[email protected]>
>>> wrote:
>>>
>>>> Hi team,
>>>>
>>>> I want to execute a *LuceneQuery* that searches both a
>>>> queryString(E.g. "station:Piccadilly*") as well as nearest station within
>>>> .5 miles.(E.g. SpatialHelper.findWithin(lat, long, 0.5))
>>>>
>>>> In other words, is there any means of combining *luceneQuery1* &
>>>> *luceneQuery2* and executing them as
>>>> Collection<Station> nearestStations = *luceneQuery*.findValues();
>>>>
>>>> where luceneQuery = luceneQuery1 + luceneQuery2
>>>>
>>>> *LuceneQuery1*
>>>> LuceneQuery<Long, Station> luceneQuery1 =
>>>> luceneService
>>>> .createLuceneQueryFactory()
>>>> .setLimit(100)
>>>> .create("stationNameIndex", "stations-region", queryString,
>>>> "name");
>>>>
>>>> *LuceneQuery2*
>>>> LuceneQuery<Long, Station> luceneQuery2 =
>>>> luceneService
>>>> .createLuceneQueryFactory()
>>>> .create("stationNameIndex", "stations-region", index ->
>>>> SpatialHelper.findWithin(-122.8515139, 45.5099231, 0.5);
>>>>
>>>> Regards
>>>> Aj
>>>>
>>>