Hi ,
My Entity :
public class Search{
@Fields({
@Field(name="fName"),
@Field(name="fName_phonetic", analyzer=@Analyzer(definition="phonetic"))
})
protected String fName;
@Fields({
@Field(name="lName"),
@Field(name="lName_phonetic", analyzer=@Analyzer(definition="phonetic"))
})
protected String lName;
@DocumentId
@Field
@Analyzer(impl = WhitespaceAnalyzer.class)
protected String primKey;
//setter & getter for each . I use XML based configuration . So rest annotations are there.
}
My Indexing code :
// getting the session,analyzer etc
session = sessionFactory.openSession();
FullTextSession fullTextSession = Search.getFullTextSession(session);
SearchFactory searchFactory = fullTextSession.getSearchFactory();
Analyzer phoneticAnalyzer = searchFactory.getAnalyzer(SearchData.class);
org.apache.lucene.queryParser.QueryParser parser =
new QueryParser("primKey",phoneticAnalyzer);
searchQuery = "primKey:" + dataDO.getPrimKey();
org.apache.lucene.search.Query luceneQuery = parser.parse(searchQuery);
org.hibernate.Query fullTextQuery = fullTextSession.createFullTextQuery( luceneQuery );
// search result list will have only one object , becasue unique primary key
List query = fullTextQuery.list();
if(query !=null){
// Updating the data object retrieved from Lucene index with the latest DO
Search searchResultDO = (Search)query.get(0);
searchResultDO.setLName(dataDO.getLName());
searchResultDO.setFName(dataDO.getFName());
session.setFlushMode(FlushMode.MANUAL);
session.setCacheMode(CacheMode.IGNORE);
org.hibernate.Transaction tx = session.beginTransaction();
// saving the changes in lucene index
Search.getFullTextSession(session).index( searchResultDO );
tx.commit();
}
Dues to my usecase & business logic the Search DO is mapped to a VIEW . And dataDO is mapped to another TABLE.
hardy.ferentschik wrote:
Hi,
Manual indexing does not insert any new records in the database. You have to seperate the database from the Lucene index. In your description I get the feeling you are mixing two concepts up a little.
--Hardy
I didnt mean that a new row is to be added to database. I meant adding new row to lucene index only. So in case of automatic indexing, Hibernate Search is also deleting & then adding a new row in index file. I can aslo follow the same in my application by doing a purge before executing my index statement.
I am just afraid about the performace of this, once we have bulk of users together working out.