-->
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.  [ 6 posts ] 
Author Message
 Post subject: how to return none distinct entities in Hibernate Search?
PostPosted: Mon Mar 01, 2010 10:26 am 
Beginner
Beginner

Joined: Mon Oct 27, 2008 6:26 am
Posts: 36
Greeting , I need some help please.

In our application, we have Article and Author. An article might have a list of authors or have no author.

We are implementing a search function. In search result, article need to be displayed for multiple times with each of its authors if it has a list of authors. In addition, article without authors also need to be listed.

The result would like following:

Article1 [author1]
Article1 [author2]
Article2 [author1]
Article3
Article4 [author1]
......

I've tried all resultTransformer options but can not get the desired effect.

fullTextQuery.setResultTransformer(CriteriaSpecification.ROOT_ENTITY);
CriteriaSpecification.ROOT_ENTITY
CriteriaSpecification.DISTINCT_ROOT_ENTITY
CriteriaSpecification.PROJECTION
CriteriaSpecification.ROOT_ENTITY

Is it possible with hibernate search to do that?


Top
 Profile  
 
 Post subject: Re: how to return none distinct entities in Hibernate Search?
PostPosted: Mon Mar 01, 2010 1:23 pm 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
I am a little confused about your question. Are you actually using Hibernate Search or are you writing Hibernate Criteria queries?

In case you are using Hibernate Search it would be useful to see the annotated entities and your search query. Regarding your result, is it now just a display problem. If your article contains a collection of authors and your search results returns articles, can you not just iterate over the authors? Alternatively, you could look at the problem the other way around and index and search authors. Regarding articles without any authors - you probably have to use a custom bridge to index some sort of placeholder token for articles without no authors. Lucene per default ignores null values. There was a discussion about this just recently on this forum.

--Hardy


Top
 Profile  
 
 Post subject: Re: how to return none distinct entities in Hibernate Search?
PostPosted: Mon Mar 01, 2010 11:52 pm 
Beginner
Beginner

Joined: Mon Oct 27, 2008 6:26 am
Posts: 36
Hardy,

I am using hibernate search.

@Indexed
public class Article implements Cloneable, Serializable{
...
@DocumentId
private String id;
private String title;
@IndexedEmbedded
private Set<Author> authors;
...
}

Search query:
BooleanQuery query = new BooleanQuery();
keywordQuery.add(new TermQuery(new Term("title", keyword)), BooleanClause.Occur.SHOULD);
...
if(searchKeyword)query.add(keywordQuery, BooleanClause.Occur.MUST);
query.add(new TermQuery( new Term("authors.name",authorName)));

FullTextSession fullTextSession = Search.getFullTextSession( sessionFactory.getCurrentSession() );
FullTextQuery fullTextQuery = fullTextSession.createFullTextQuery( query );
fullTextQuery.setFirstResult( (pageNumber) * pageSize );
fullTextQuery.setMaxResults( pageSize );
PartialListHolder results = new PartialListHolder();
results.setSource( fullTextQuery.list());
results.setNrOfElements( fullTextQuery.getResultSize() );
results.setPageSize( pageSize );
results.setPage( pageNumber );

In old search function, we can get a list of matched articles by searching keyword or authorName. Our new requirement is to display same article multiple times with each of its authors if it has.

As you said, it is kind of display problem. But I can not simply iterate over the authors because of the paging issue. I still want to display fix number of articles in each page. But the setNrOfElements and page count are still generated by fullTextQuery.


Top
 Profile  
 
 Post subject: Re: how to return none distinct entities in Hibernate Search?
PostPosted: Tue Mar 02, 2010 8:28 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
You are not posting how Author is annotated, but if you also creating an author index I would recommend to search for authors instead of articles. This way you don't have to worry about the pagination and number of returned elements. It will just be right.
Have you tried this?


Top
 Profile  
 
 Post subject: Re: how to return none distinct entities in Hibernate Search?
PostPosted: Tue Mar 02, 2010 8:47 am 
Beginner
Beginner

Joined: Mon Oct 27, 2008 6:26 am
Posts: 36
Hardy,

yes, we are creating an author index as well. But the problem to search author index is, the search would not return articles which have no authors. right?

We are facing same issue to search course with schedule. A standard course would have a list of schedules. But some of course type do not have, such as elearning, self studied etc. If a user search java course, the search result need to be all matched courses, including courses which have no schedules, also course with mutiple schedules (course need to be displayed multiple times with each of its schedules).

Ian


Top
 Profile  
 
 Post subject: Re: how to return none distinct entities in Hibernate Search?
PostPosted: Tue Mar 02, 2010 9:01 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Right, here comes the dummy author into play I was mentioning. With Lucene you generally have the problem that null (empty) values are not indexed.
You could add a custom field bridge to the authors set which adds a static "unkown" author to the index in case the set is empty. In your query you just add the search criteria for this "unknown" author to your query.

--Hardy


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.