The database consists of 5 tables, the first three contain data of various kinds, as well as special tags by which they can be found.

Tables 1 - 3
_id | Name | ... | metka1 | metka2 | metka3

The fields metka1, metka2, metka3 are filled in as follows - the entered phrase of the user is divided into separate words and entered into the appropriate cell number (but not more than 3 words).

Table 4
_id | metka

All tags are entered in this table. Pre-check if there is an input label in the database, if not, add a new line.

Table 5
_id | ssilka_tabl | id_stroki | id_metki

The fifth table contains references to the data of the first three tables by index indices.

And now to perform the search.

I divide the query entered by the user into words in an array, for each word I find an index in table 4, and then by index I get an array of links to the first three tables. Looking through the array, I make a list of the received links, and depending on the number of tags matches, I set the weight, and then sort by weight.

Further application logic gets me into a dead end, tell me the possible options.

How to sort the results optimally in order to reveal the coincidence of the labels of one of the tables, and all three labels can coincide, and one or two, depending on weight, give preference to the highest value.

How to reveal that the data of two different tables coincided, and the tags in the user query string do not overlap each other. And as well as to do, if not all 3 tags coincided, but some of them.

    0