-->
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.  [ 3 posts ] 
Author Message
 Post subject: Sort and Search on same field?
PostPosted: Mon Aug 12, 2013 10:11 am 
Newbie

Joined: Tue Aug 06, 2013 10:16 am
Posts: 4
I am trying to implement the .setSort() feature on my query. I read that you have to set the field to not be tokenized and that this was changed from Index.UN_TOKENIZED to analyze = Analyze.NO.


When I do this however it seems like my db loses it's indexing as search queries no longer return results, and not doing it doesn't sort the results. Am I going about this the right way?

Below is my annotated class (shown are only the fields that are indexed) and how I am sorting in my function.

Code:
@Entity
@Table(name="jobReq")
@Indexed
public class JobReq {
   
   @Id
   @DocumentId
   @GeneratedValue(strategy=GenerationType.IDENTITY)
   private Integer id;
   
   @Field(index = Index.YES, analyze = Analyze.NO)
   @Column(name="jobId", nullable=false, unique=true)
   private String jobId;
   
   @Field(index = Index.YES, analyze = Analyze.NO)
   @Column(name="jobTitle", nullable=false)
   private String jobTitle;
   
   @Field(index = Index.YES, analyze = Analyze.NO)
   @Column(name="jobContract", nullable=false)
   private String contract;
   
   @Field(index = Index.YES, analyze = Analyze.NO)
   @Column(name="jobProject", nullable=true)
   private String project;
   
   @Field(index = Index.YES, analyze = Analyze.NO)
   @Column(name="jobLaborCategory", nullable=false)
   private String laborCategory;
   
   @Field(index = Index.YES, analyze = Analyze.NO)
   @Column(name="jobSummary", nullable=false)
   private String summary;
   
   @Field(index = Index.YES, analyze = Analyze.NO)
   @Column(name="jobDescription", nullable=false)
   private String jobDescription;
   
   @Field(index=Index.YES, analyze = Analyze.NO)
   @Column(name="jobStatus", nullable=false)
   private String status;
   
   @Field(index = Index.YES, analyze = Analyze.NO)
   @Column(name="TTONumber", nullable=false)
   private String TTONumber;
   
   @Field(index = Index.YES, analyze = Analyze.NO)
   @Column(name="jobPostedDate", nullable=false)
   @Type(type="date")
   private Date postedDate;
   
   @Field(index = Index.YES, analyze = Analyze.NO)
   @Column(name="jobModifiedDate", nullable=false)
   @Type(type="date")
   private Date modifiedDate;
   



Code:
      Field[] allFields = this.type.getDeclaredFields();
      SortField field =new SortField("jobStatus", SortField.STRING);
      Sort sort = new Sort(field);
hibQuery = fullTextSession.createFullTextQuery(booleanQuery, this.type).setSort(new Sort(new SortField(allFields[6].getName(), SortField.SCORE)));
         results = hibQuery.list();


Last edited by HiberSearch on Tue Aug 13, 2013 2:59 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Searching and analyze.no?
PostPosted: Mon Aug 12, 2013 11:47 am 
Newbie

Joined: Tue Aug 06, 2013 10:16 am
Posts: 4
I managed to get the search to work with the help of a book on google, it was the only place I noticed the two fields thing
Code:
   @Fields({@Field, @Field(index=Index.YES, analyze = Analyze.NO, name = "jobStatus")})


But although the book makes it look like you can sort and search on the same field, it doesn't work. Link to the resource below:

http://books.google.com/books?id=qBLNYKx_tLEC&pg=PT118&lpg=PT118&dq=how+to+setsort+hibernate&source=bl&ots=pl9UI03chQ&sig=N2Pf9IqBQSi7k_xNeWpossMfav0&hl=en&sa=X&ei=UPIIUumuBIin2AXH44CoDQ&ved=0CEEQ6AEwBDgK#v=onepage&q=how%20to%20setsort%20hibernate&f=false


Top
 Profile  
 
 Post subject: Re: Sort and Search on same field?
PostPosted: Thu Sep 05, 2013 6:13 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
You're correct, you should use two different fields: one for sorting, one for querying.

_________________
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.  [ 3 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.