How to remove all the duplicate results in Hibernate Search?
Asked Answered
P

1

6

I'm using Infinispan with 6.0.2 with Hibernate Search 4.4.0.

In the begining, after I execute a query like

CacheQuery cq = SearchManager.getQuery(query,Hibernate.class).projection("id");

I use the cq.list() to get "id".

But now the number of results reaches 300.000, because of the designing fo DB(cant change), the duplicate id is almost 29,000.

I wrote this to get "id":

for(int i=0;i<listObject.size();i++)
{
    Object[] rdf = (Object[])listObject.get(i);
    if(!result.contains((String) rdf[0])) 
       result.add((String) rdf[0]);
}

But even if I parallel this part, it also takes a long time.

Does there is a function to remove duplicate id for the query in Hibernate like the DISTINCT does in SQL?

Palfrey answered 12/6, 2014 at 7:50 Comment(2)
Is the question not really why you have so many duplicates, ot are you saying that is expected? Can you describe the full use case?Grammar
E.g the Hibernate provides me 300.000 results which my query hits, the value of each "id" is all correct. But the "id" is not unique, so there are 290.000 id is duplicate. I was wondering if there is a method like DISTINCT for SQL in Infinispan. I saw the Criteria in hibernate, but I didn't know how to use in Infinispan. @GrammarPalfrey
H
-1

setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY) use the distinct .

Herder answered 12/6, 2014 at 9:21 Comment(4)
I didn' find a method to set the resultTransformer in Infinispan. Can u give me a example?Palfrey
Criteria criteria2 = session.createCriteria(classname.class) .setProjection(Projections.distinct(Projections.property("id"))) .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY) .add(Restrictions.eq("clientName", userName)) .add(Restrictions.eq("id", id));Herder
In fact, I saw this in hibernate. But I'm using hibernate in Infinispan, there isn't even a class called Criteria...Palfrey
ResultTransformer is only available for normal Hibernate Criterias, not for Hibernate Search.Stopcock

© 2022 - 2024 — McMap. All rights reserved.