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();