Here is the situation.
I have a Java jsf code using Lucene Index with Hibernate search. The search sort order is fine after the initial creation of the Lucene indexes. However, after editing an item from the result list, which results database changes, if perform another similar search again, the list is now in different sort order, which it is not expected. In order to see the correct order again, the Lucene indexes need to be reinitated.
Is this a Lucene index issue or Hibernate Search fails to update index with the database changes?
The user requirements are: - sort order by Status, and ID - all fields are searchable even the ID field. for example, if the search text is "1", the list will return records with 1 embedded in all fields.
The problem is: After editing an item from the result list, which results database changes, if perform another similar search again, the list is now in different sort order, which it is not expected.
Lucene indexing code snippet:
FullTextEntityManager manager = Search.getFullTextEntityManager(getEntityManager()); List<Site> sites = manager.createQuery( "select e from " + Site.class.getName() + " e") .getResultList(); for (Site s : sites) { s.getLocation(); s.getTitle(); s.getStatus(); manager.index(s); }
For search, Query Parser is used:
FullTextEntityManager manager = Search .getFullTextEntityManager(getEntityManager()); org.apache.lucene.queryParser.QueryParser parser = new QueryParser( Version.LUCENE_31, "title", new StandardAnalyzer(Version.LUCENE_31)); FullTextQuery searchLuceneQuery = manager.createFullTextQuery( wordParserQuery, Site.class); Sort sort = new Sort( new SortField("status",SortField.LONG.reverse));
The entity: @Id @DocumentId @Basic(optional = false) @Column(name = "ID") @SequenceGenerator(name="SITE_ID_SEQ",sequenceName="SITE_ID_SEQ") @GeneratedValue(generator="SITE_ID_SEQ") @Field(index=Index.TOKENIZED) private Long id;
@Field(index=Index.TOKENIZED) @Column(name = "LOCATION") private String location; @Field(index=Index.TOKENIZED) @Column(name = "STATUS") private String status;
@Field(index=Index.TOKENIZED) @Column(name = "TITLE") private String title;
Any help would be appreciated.
|