Autocomplete locking the database

2

I'm developing an application in PHP and Jquery with the framework Codeigniter 3. I'm using Postgre and I have a database with more than 1 million registered registrations.

I made an autocomplete that looks for the name of a product in the database, but as it searches in real time in the database, it starts to lock everything. I tested using a static array and it worked 100%.

Computationalally speaking as my database has many records, what would be the best way to do this?

PS: I'm using this jquery plugin ( link )

UPDATE

I'm using Full Text Search, but I have not created any indexes for it. I'll try to create it to see if it improves. Look at my code:

$query = $this->db->query("SELECT p.titulo AS value 
FROM sistema.produto p
WHERE to_tsvector(p.titulo) @@ to_tsquery(?)
ORDER BY p.id_categoria 
LIMIT 5", array($termo));
    
asked by anonymous 21.07.2017 / 06:44

1 answer

3

PostgreSql FullText Search

If you do not want to move significantly in the software or infrastructure, look at PostgreSql FullText Search .

This is a function / feature of PostgreSql to perform searches on some determiner fields.

ElasticSearch

If you can make more significant changes, I recommend using Elastic Search along with your Type Ahead - or < in> Auto Complete . This yes was all done for that purpose. With a separate search service, you can create all the searches you need, and take any load from your main database.

    
21.07.2017 / 11:21