[Bahmni Lite]Search by identifier is taking to long to fetch results in lucene search

We have recently updated appointments module search in lite, to use lucene search following this card.

After modifying it we observed very high search time in appointments.

We are using a DB with almost 7000 patients. In this DB if we are searching with a filter that yields 300-400 results is taking 15-22secs.

We also compared the performance with normal search in Bahmni, here are the observations.

Module Number of charatcters Searched for Response records received Response time in seconds LITE Responce Time in seconds LEGACY Type of search in LITE Type of search in LEGACY
Registration 3 Patient ID(PT5) 400 17.33 4.05 Lucene Lucene
4 Patient ID(PT50) 102 2.05 1.14
3 Name(aff) 15 0.131 0.201
4 Name(affb) 3 0.119 0.116
OT scheduling Patient filter 3 Patient ID(PT5) 400 17.67 1.34 Lucene Normal
4 Patient ID(PT50) 102 1.93 1.31
3 Name(A19) 334 10.14 -
4 Name(A190) 22 0.274 -
3 Name(aff) 15 0.243 0.118
4 Name(affb) 3 0.138 0.115
OT scheduling - Search for patient in add surgery 3 Patient ID(PT5) 400 17.22 1.3 Lucene Normal
4 Patient ID(PT50) 102 2.16 1.3
3 Name(A19) 334 9.71 -
4 Name(A190) 22 0.358 -
3 Name(aff) 15 0.259 0.112
4 Name(affb) 3 0.169 0.097
Appointment list view 3 Patient ID(PT5) 400 18.31 1.32 Lucene Normal
4 Patient ID(PT50) 102 2 1.31
3 Name(A19) 334 9.8 -
4 Name(A190) 22 0.387 -
3 Name(aff) 15 0.257 0.106
4 Name(affb) 3 0.128 0.096

Here is the reference card we created in JIRA for this issue.