-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 
Author Message
 Post subject: @index on abstract class ?
PostPosted: Fri Nov 09, 2012 6:14 am 
Newbie

Joined: Tue Jul 19, 2011 2:16 pm
Posts: 19
Hello everyone,

I would like indexing all my entities and search results in all of them in one request.
To resolve that, I made all my entities ihnerited from an abstract class. But when I create my query, I have the error HSEARCH000109: [...].domain.AbstractDomainEntity is not an indexed type.

In my indexes directory I have the following folder : "lucene\indexes\[...].domain.AbstractDomainEntity"

Here is my abstract class :
Code:
@Indexed
@SuppressWarnings("serial")
@MappedSuperclass
public abstract class AbstractDomainEntity implements Serializable {

   @Id
   @GeneratedValue
   private Long id;

   //...
}


And here the way I create the query :
Code:
QueryBuilder queryBuilder = fullTextEntityManager.getSearchFactory()
          .buildQueryBuilder().forEntity( AbstractDomainEntity.class ).get();

org.apache.lucene.search.Query luceneQuery = queryBuilder
   .keyword()
   .fuzzy()
      .withThreshold(rechercheFuzzyThreshold)
      .withPrefixLength(rechercheFuzzyPrefixLength)
   .onField(rechercheChamp)
   .matching(critere)
   .createQuery();

// wrap Lucene query in a javax.persistence.Query
javax.persistence.Query persistenceQuery =
   fullTextEntityManager.createFullTextQuery(luceneQuery, AbstractDomainEntity.class);
      
// execute search
List<Object> result = persistenceQuery.getResultList();


What's wrong ??


Top
 Profile  
 
 Post subject: Re: @index on abstract class ?
PostPosted: Sat Nov 10, 2012 6:15 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hi Andilo,
your query is correct as you can search by all types specifying any superclass, but you could also target Object.class or just omit the parameter to target all indexed types.

The problem you're having is that the @Indexed annotation is not inherited, you have to specify it on each domain object. I think we need that to allow subclasses without indexing as you might not want to index all subtypes, but please share your thoughts about this: we can propose changes to the team.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: @index on abstract class ?
PostPosted: Tue Nov 13, 2012 4:18 am 
Newbie

Joined: Tue Jul 19, 2011 2:16 pm
Posts: 19
Hi sanne,

Thank you very much for your answer.

You said that my query is correct. But I think that my problem is about my queryBuilder :
Code:
QueryBuilder queryBuilder = fullTextEntityManager.getSearchFactory()
         .buildQueryBuilder().forEntity(AbstractDomainEntity.class).get();


I must set the class as parameter to the forEntity() method. Do you have another solution ?


Top
 Profile  
 
 Post subject: Re: @index on abstract class ?
PostPosted: Tue Nov 13, 2012 6:36 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Why is that a problem?
when using the QueryBuilder you need to target some entity.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: @index on abstract class ?
PostPosted: Tue Nov 13, 2012 7:01 am 
Newbie

Joined: Tue Jul 19, 2011 2:16 pm
Posts: 19
The problem is that I can't create a queryBuilder to request all indexed entities, or all indexed entities for a given abstract class.
I have the following hierarchie : http://www.gliffy.com/pubdoc/4069422/L.png

I would like requesting for both entities ConcreteSubClass1_1_1 and ConcreteSubClass1_1_2.
I try to create a queryBuilder for the AbstractDomainEntity because it's the root class, but I have an error "AbstractDomainEntity is not an indexed entity".
How could I do ?


Top
 Profile  
 
 Post subject: Re: @index on abstract class ?
PostPosted: Tue Nov 13, 2012 7:04 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Looks like you need https://hibernate.onjira.com/browse/HSEARCH-703. You could implement that?

An alternative is to work around it by not using the QueryBuilder to create Queries but construct Lucene queries directly.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: @index on abstract class ?
PostPosted: Wed Nov 14, 2012 4:08 am 
Newbie

Joined: Tue Jul 19, 2011 2:16 pm
Posts: 19
Hi sanne,

Thank you for your answer one more time.

The links describe my needs. It has been created one year ago :(

May be your solution is good. I'm going to search about creating a Lucene query. Do you have some links about it ?


Top
 Profile  
 
 Post subject: Re: @index on abstract class ?
PostPosted: Wed Nov 14, 2012 8:00 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Quote:
The links describe my needs. It has been created one year ago :(


It's an open source project: many people have ideas and we track them on JIRA, then anyone can implement them so that we get a mutual benefit from it. Usually if someone needs something badly he'll implement it, and we help with that and maintain it in future.
If it's still open after a year it is likely that this wasn't a very important issue.

Quote:
May be your solution is good. I'm going to search about creating a Lucene query. Do you have some links about it ?


checkout our tests, most use the standard Lucene Query API; you need to pick which kind of query you need, for example a single term query:
https://github.com/hibernate/hibernate-search/blob/master/hibernate-search-orm/src/test/java/org/hibernate/search/test/RamDirectoryTest.java#L60

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.