Answer the question
In order to leave comments, you need to log in
How to organize site search in Symfony?
Good afternoon everyone.
Actually the question is almost the whole above. Just started to deal with Symfony, and I would like to know if there is a "silver bullet" in terms of organizing search on the site?
Because The materials on the site are most often different entities in different tables, how can they be indexed in such a way that when adding a new entity, to reduce the refinement of the search to a minimum?
Answer the question
In order to leave comments, you need to log in
1) use one of the search engines (sphinx, ElasticSearch). There are ready-made bundles that help to use these engines in a symfony project.
2) either do a bunch of searches for the necessary entities yourself, you can make a UNION query:
SELECT id, title, 'article' as `type` FROM Article WHERE ...
UNION SELECT id, title, 'news' as `type` FROM News WHERE ...
UNION SELECT id, title, 'post' as `type` FROM Post WHERE ...
To organize a search within the application, according to the existing entities - this is not realistic, it seems to me. What fields to search? How to rank the results?
It is better to go the way of "crawlers" from search engines that crawl and collect content, bypassing the site like a search robot. All results can fit in 1 table of the form:
Symphony has a powerful commands tool with which you can create console applications.
I would go by writing a "crawler" that can be run by cron. The crawler will crawl your site and index the content. Symphony also has a DomCrawler component that makes it easy to select all links on a page, as well as collect text content. Text content can be placed in a special tag (for example) or just a class,
The algorithm is something like this:
1. parse "/"
2. save the content from the tag
3. save all new links (excluding external links and pdf, doc, etc) in a table.
4. parse the next record from our table.
Thus, we bypass the entire site by the crown.
PS
I would also look for ready-made bundles, for sure they are.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question