我有以下带注释的类,我试图对来自 lucene/hibernate 搜索查询的结果进行排序。我终于让查询正常工作,但似乎当我实现必要的注释(在 jobStatus 上看到)来对该列进行排序时,就不可能再搜索该列。我的依据是我在 google 上找到的说明。我一直在解决整个休眠搜索和排序问题,现在我终于弄清楚了如何排序和搜索,我所需要的就是能够一起完成它们。
@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;
以及来自搜索功能的片段
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();