There is a dictionary of translations of scientific terms. If you enter a query

LIKE% line% - will display:

approaching line online reservation line liner 

But the following order is needed:

 line approaching line online reservation liner 

Already wrote a sample of the database, but I do not know how to make a conclusion in the right order

 $Obj = RussianModel::where(function ($query) use ($search) { // ТОЧНОЕ СОВПАДЕНИЕ $query->where('translate', 'ILIKE', '' . $search . ''); // Точное совпадение $query->orWhere('translate', 'ILIKE', '' . $search . ' %'); // Слово в начале строки $query->orWhere('translate', 'ILIKE', '% ' . $search . ''); // Слово в конце строки $query->orWhere('translate', 'ILIKE', '% ' . $search . ' %'); // Слово в середине строки // ЧАСТИЧНОЕ СОВПАДЕНИЕ $query->orWhere('translate', 'ILIKE', '%' . $search . '%'); // Любое возможное совпадение })->get(); 

Already did 5 consecutive requests, combined the results. But this is not very good. Maybe there is another way to search?

  • What is interesting about the logic of the order that is needed? PgSQL has clear logic - alphabetically. To write operators you first need to logically describe the task. "Intellectual" does not mean at all "devoid of logic", do you agree? ;-) - Eugene Bartosh February
  • in that from the beginning an exact match is displayed for the query, and then various derivatives. If you make 5 requests, and then merge answers, then everything will turn out as it should. Just outputting by ID is not the right decision at all - PopcornPHP
  • then create a second field with regex to check for the occurrence of a whole word, sort by this field - postgresql.org/docs/9.5/static/functions-matching.html - Eugene Bartosh

0