I have the following annotated class that I am trying to sort the results from a lucene / hibernate search query. My query finally works fine for me, but it seems that when I implement the necessary annotations (seen on jobStatus) to sort this column, it makes it impossible to search for this column. I base this on the instructions I found here on Google . I'm having trouble calculating all this hibernate search and sort mode, now that I finally figured out how to sort and search all I need is to do them together.
@Entity @Table(name="jobReq") @Indexed public class JobReq { @Id @DocumentId @GeneratedValue(strategy=GenerationType.IDENTITY) private Integer id; @Field(index = Index.YES) @Column(name="jobId", nullable=false, unique=true) private String jobId; @Field(index = Index.YES) @Column(name="jobTitle", nullable=false) private String jobTitle; @Field(index = Index.YES) @Column(name="jobContract", nullable=false) private String contract; @Field(index = Index.YES) @Column(name="jobProject", nullable=true) private String project; @Field(index = Index.YES) @Column(name="jobLaborCategory", nullable=false) private String laborCategory; @Field(index = Index.YES) @Column(name="jobSummary", nullable=false) private String summary; @Field(index = Index.YES) @Column(name="jobDescription", nullable=false) private String jobDescription; @Fields({@Field, @Field(analyze = Analyze.NO, name = "jobStatus")}) @Column(name="jobStatus", nullable=false) private String status; @Field(index = Index.YES) @Column(name="TTONumber", nullable=false) private String TTONumber; @Field(index = Index.YES) @Column(name="jobPostedDate", nullable=false) @Type(type="date") private Date postedDate;
And a snippet from the search function
Field[] allFields = this.type.getDeclaredFields(); SortField field =new SortField(sortColumn, SortField.STRING, reverseSort); Sort sort = new Sort(field); hibQuery = fullTextSession.createFullTextQuery(bq, this.type).setSort(sort); results = hibQuery.list();
source share