J
J
jle349252015-10-15 13:55:15
PHP
jle34925, 2015-10-15 13:55:15

How to make a relevant sorting for a query in an array?

There is a one-dimensional array with test sentences and there is a word. How to sort an array? In general, it’s like in Google, only everything is serious there, but I have an array.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Viverov, 2015-10-15
@Viverov

The simplest is boolean search
www.machinelearning.ru/wiki/images/d/d2/IR.pdf

A
Anton B, 2015-10-15
@bigton

Well, let's say if you need to sort by the number of occurrences of a word in each text.

$text_arr = []; // массив тестов
$word = 'слово'; // искомое слово

usort($text_arr, function ($a, $b) use ($word) {    
    return substr_count($a, $word) >= substr_count($b, $word) ? -1 : 1;
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question