# Enable/Disable Soundex when search for patients

**URL:** <https://talk.openmrs.org/t/enable-disable-soundex-when-search-for-patients/16194>\
**Category:** Development\
**Tags:** patient-search, core\
**Created:** [February 19, 2018, 1:03pm UTC](https://talk.openmrs.org/t/enable-disable-soundex-when-search-for-patients/16194 "2018-02-19T13:03:47Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![owais.hussain](https://talk.openmrs.org/user_avatar/talk.openmrs.org/owais.hussain/32/530_2.png) [@owais.hussain](https://talk.openmrs.org/u/owais.hussain)\
**Post date:** [February 19, 2018, 1:03pm UTC](https://talk.openmrs.org/t/enable-disable-soundex-when-search-for-patients/16194/1 "2018-02-19T13:03:47Z")

</div>

Hi,

We’ve been struggling in one of our implementations (v1.11.x) with patient search, which takes over 30 seconds now to search for a patient with the number of records reaching 350k. Searching for a way to optimize this time (note that Lucene queries aren’t being used for patient search for versions 1.x), I was exploring possibilities to disable using Soundex function. I couldn’t find any. If that indeed is the case, I think it would be good to add a variable in advanced settings to switch using Soundex on and off.

Thoughts?

---

<div class="post-metadata">

**Author:** ![darius](https://talk.openmrs.org/user_avatar/talk.openmrs.org/darius/32/8082_2.png) [@darius](https://talk.openmrs.org/u/darius)\
**Post date:** [February 20, 2018, 11:39pm UTC](https://talk.openmrs.org/t/enable-disable-soundex-when-search-for-patients/16194/2 "2018-02-20T23:39:01Z")

</div>

AFAIK the only place that soundex (or similar) is done (pre-Lucene) is in the namephonetics module, which is optional.

---

<div class="post-metadata">

**Author:** ![mogoodrich](https://talk.openmrs.org/user_avatar/talk.openmrs.org/mogoodrich/32/3324_2.png) [@mogoodrich](https://talk.openmrs.org/u/mogoodrich)\
**Post date:** [February 21, 2018, 1:14am UTC](https://talk.openmrs.org/t/enable-disable-soundex-when-search-for-patients/16194/3 "2018-02-21T01:14:15Z")

</div>

That’s what I thought as well… I think if you don’t have Name Phonetics running, then there is no soundex.

---

<div class="post-metadata">

**Author:** ![owais.hussain](https://talk.openmrs.org/user_avatar/talk.openmrs.org/owais.hussain/32/530_2.png) [@owais.hussain](https://talk.openmrs.org/u/owais.hussain)\
**Post date:** [February 21, 2018, 7:45am UTC](https://talk.openmrs.org/t/enable-disable-soundex-when-search-for-patients/16194/4 "2018-02-21T07:45:58Z")

</div>

Yes, Lucene queries were introduced for patient search later. Also, I benchmarked the query with and without Soundex, and Soundex found out to be a few ms faster regardless of data growth. Here are my findings:

| | With Soundex | | Without Soundex | |
| --- | --- | --- | --- | --- |
| **Records** | **Matches** | **Time(ms)** | **Matches** | **Time(ms)** |
| 100000 | 832 | 267 | 1171 | 280 |
| 200000 | 1032 | 161 | 1691 | 184 |
| 300000 | 1232 | 243 | 2211 | 263 |
| 400000 | 1432 | 315 | 2731 | 359 |
| 500000 | 1632 | 908 | 3251 | 990 |

The above results are from my laptop - (Core i7, 7500U, Windows 10-64 bit, MySQL v5.6)

---

<div class="post-metadata">

**Author:** ![tansentim](https://talk.openmrs.org/letter_avatar/tansentim/32/6_449c533f586939b6e5f246632a46421f.png) [@tansentim](https://talk.openmrs.org/u/tansentim)\
**Post date:** [February 21, 2018, 9:49am UTC](https://talk.openmrs.org/t/enable-disable-soundex-when-search-for-patients/16194/5 "2018-02-21T09:49:40Z")

</div>

Which did you run first? If you run two similar queries in most database engines, the second one is nearly always quicker, because of disk/table caching.

Also the time per match is much less in the ‘Without Soundex’ table.

---

<div class="post-metadata">

**Author:** ![owais.hussain](https://talk.openmrs.org/user_avatar/talk.openmrs.org/owais.hussain/32/530_2.png) [@owais.hussain](https://talk.openmrs.org/u/owais.hussain)\
**Post date:** [February 21, 2018, 11:42am UTC](https://talk.openmrs.org/t/enable-disable-soundex-when-search-for-patients/16194/6 "2018-02-21T11:42:16Z")

</div>

Yes, time per match has reduced, but from end-user perspective, it has actually increased. But I get your point, I guess I should repeat the experiment with query caching disabled.

---

<div class="post-metadata">

**Author:** ![owais.hussain](https://talk.openmrs.org/user_avatar/talk.openmrs.org/owais.hussain/32/530_2.png) [@owais.hussain](https://talk.openmrs.org/u/owais.hussain)\
**Post date:** [March 2, 2018, 5:45am UTC](https://talk.openmrs.org/t/enable-disable-soundex-when-search-for-patients/16194/7 "2018-03-02T05:45:45Z")

</div>

@tansentim here are the results with query caching disabled

| | With Soundex | | | Without Soundex | | |
| --- | --- | --- | --- | --- | --- | --- |
| Records | Matches | Time(ms) | Match/ms | Matches | Time(ms) | Match/ms |
| 100000 | 298 | 100 | 2.98 | 635 | 122 | 5.20 |
| 150000 | 398 | 116 | 3.43 | 895 | 132 | 6.78 |
| 200000 | 498 | 163 | 3.06 | 1155 | 185 | 6.24 |
| 250000 | 598 | 179 | 3.34 | 1415 | 217 | 6.52 |
| 300000 | 698 | 232 | 3.01 | 1675 | 270 | 6.20 |
| 350000 | 778 | 870 | 0.89 | 1883 | 902 | 2.09 |

![image](https://talk.openmrs.org/uploads/default/original/2X/6/6b9df92d1319be6a0865c4157b8b0b3ee067e4ea.png)

![image](https://talk.openmrs.org/uploads/default/original/2X/3/3ae533326c17537c5115a32453a3bfe848133a2a.png)

![image](https://talk.openmrs.org/uploads/default/original/2X/0/0035ab4c98cf181027c31c0b1ab8ae34ea2e88d6.png)

Looking at the last graph, the records retrieved per milliseconds is definitely higher without Soundex.
