Hi,
Could you please let me know some ways to improve the search performance. With my current implementation, the search takes around a min to bring back around 800 records. I want to know if something is wrong in my implementation or that I am missing something that it would take so long.
I am having around 93000 records so for a simple search which brings 800 records it takes 1 min, I suspect with few thousand records it might take a long time. I want to improve the performance, considering the fact that in real world my search could bring in 10000 records as well sometime.
I would appreciate if you could provide any suggestions on improving the search time.
Quote:
Configuration file :
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:@url:1531:schema</property>
<property name="hibernate.connection.username">username</property>
<property name="hibernate.connection.password">pwd</property>
<property name="hibernate.connection.pool_size">10</property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.Oracle9Dialect</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<!-- Hibernate search configuration -->
<property name="hibernate.search.default.directory_provider">org.hibernate.search.store.FSDirectoryProvider</property>
<property name="hibernate.search.default.indexName">cp_employees</property>
<property name="hibernate.search.default.indexBase">\indexes</property>
<property name="hibernate.search.default.batch.merge_factor">10</property>
<property name="hibernate.search.default.batch.max_buffered_docs">10</property>
<!-- Mapping files -->
<mapping resource="employees.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Quote:
Indexing the document
public void indexRecord(){
FullTextSession ftSession = SessionUtil.getFullTextSessionInstance();
ftSession.getTransaction().begin();
try {
long startTime = Calendar.getInstance().getTimeInMillis();
ftSession.createIndexer(CP_Employees.class).batchSizeToLoadObjects(100)
.cacheMode(CacheMode.IGNORE).threadsToLoadObjects(10).threadsForSubsequentFetching(25).startAndWait();
long endTime = Calendar.getInstance().getTimeInMillis();
long batchTime = endTime - startTime;
System.out.println(batchTime );
} catch (InterruptedException e) {
e.printStackTrace();
}
ftSession.getTransaction().commit(); //index are written at commit time
}
Quote:
Generic Search
@SuppressWarnings({ "deprecation"})
public List<?> genericCPEmployeesSearch(String searchQuery){
String[] searchFields = getSearchFields();
FullTextSession ftSession = SessionUtil.getFullTextSessionInstance();
MultiFieldQueryParser multiQueryParser = new MultiFieldQueryParser(
searchFields, ftSession.getSearchFactory().getAnalyzer(CP_Employees.class));
try {
org.apache.lucene.search.Query luceneQuery = multiQueryParser.parse(makeGenericQueryString(searchQuery));
long startTime = Calendar.getInstance().getTimeInMillis();
@SuppressWarnings("unchecked")
List<CP_Employees> results = ftSession.createFullTextQuery(luceneQuery, CP_Employees.class).list();
long endTime = Calendar.getInstance().getTimeInMillis();
long timeDiff = endTime - startTime;
System.out.println("results.size() " + results.size());
System.out.println("timeDiff " + timeDiff/(60*1000));
return results;
} catch (ParseException e) {
e.printStackTrace();
}
return null;
}
The getSearchField() method returns the list of all fields in the CP_Employees entity object.
Quote:
ENTITY Definition used for search
public class CP_Employees {
@Id
@GeneratedValue
@DocumentId
private long emplid;
@Field (index=Index.TOKENIZED, store=Store.NO)
private String emplClass;
@Field (index=Index.TOKENIZED, store=Store.NO)
private String status;
@Field (index=Index.TOKENIZED, store=Store.YES)
private String title;
@Field (index=Index.TOKENIZED, store=Store.YES)
private String firstName;
@Field (index=Index.TOKENIZED, store=Store.YES)
private String lastName;
@Field (index=Index.UN_TOKENIZED, store=Store.NO)
private String busName;
@Field (index=Index.UN_TOKENIZED, store=Store.NO)
private String name;
@Field (index=Index.TOKENIZED, store=Store.NO)
private Date birthDate;
@Field (index=Index.TOKENIZED, store=Store.NO)
private Date hireDate;
@Field (index=Index.TOKENIZED, store=Store.YES)
private long hrStatus;
@Field (index=Index.UN_TOKENIZED, store=Store.NO)
private String jobTitle;
@Field (index=Index.TOKENIZED, store=Store.NO)
private String location;
@Field (index=Index.TOKENIZED, store=Store.YES)
private String localDesc;
@Field (index=Index.TOKENIZED, store=Store.YES)
private String physicalCity;
@Field (index=Index.TOKENIZED, store=Store.YES)
private String physicalCountry;
@Field (index=Index.TOKENIZED, store=Store.YES)
private String physicalRegion;
@Field (index=Index.UN_TOKENIZED, store=Store.NO)
private String rankDesc;
@Field (index=Index.UN_TOKENIZED, store=Store.NO)
private String sex;
@Field (index=Index.UN_TOKENIZED, store=Store.NO)
private String payrollCompany;
Thanks in advance.
Cheers,
Manoj