3

I have a website made in Laravel 5.2, and I need to implement a search box, I know what it basically the process involves (make petition to controller, find and then answer with json, etc).

So, before do that I really need to know some tips, what are best practices to achieve this in the best way as possible. Briefly, I have a database table with a lot of posts(really a lot, lets say 500k registers), every post have some properties: name, description, poster, punctuation. I know there's no a exactly answer to this question, but I only want to know what should I take in count before do that, how can I improve the search and how to make it using the best practices.

  • 1.- Do you think that I need to create a separate table with only the names and id of the post? this table is only for the search.
  • 2.- To make the search faster, should I put the name column as an index in the database? or sort by date?
  • 3.-How can I improve the speed of the search? maybe use some puntuation?(something based in how many times that post was the one searched by the user), it's a good idea?

  • 4.- I'm thinking that maybe I only have to find by the name of the post because the quantity of items in the DB. Am I right?

  • 5.- Also, which algorithms can I use to treat with some situations where the user wrote with a typo? I need to interpret what they tried to said and show them the related post.

  • 6.- Which tools or extensions related do you recomend me?

Finally, thank you very much!

1

2 Answers 2

4

Yes, check out Laravel Scout with Algolia; but you'd need to update to Laravel 5.3 or 5.4. Once you set up Scout/Algolia (should be fast) you'd still need to do an AJAX call to the API but if done right it should be quite fast.

https://laravel.com/docs/5.4/scout

Sign up to request clarification or add additional context in comments.

Comments

3

The best solution is don't use database as a search engine.

Using a search engine like Elasticsearch make your search faster and smarter then using pure database search.

If you application is really lage as you said, worth it.

With it you can implement advanced searching, using many analyzers available like nGram, where you can search for redn and get results for Sredny M Casanova eg. or find even when user wrote a typo.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.