Hello. My task is to categorize keywords when downloading. For example, there is a list:
ΠΊΠ°ΡΡΠΈΠ½ΠΊΠΈ ΠΊΠΎΡΠΈΠΊΠΎΠ² ΠΊΠ°ΡΡΠΈΠ½ΠΊΠΈ ΠΊΠΎΡΡΡΡ ΠΊΠΎΡΠΈΠΊΠΈ ΠΊΠΎΡΠΈΠΊΠΈ Π²ΠΏΠ΅ΡΠ΅Π΄ ΠΊΠΎΡΠΈΠΊΠΈ ΠΊΠ°ΡΡΠΈΠ½ΠΊΠΈ ΠΊΠΎΡΠΈΠΊΠΎΠ² ΠΊΠΎΡΠΈΠΊΠΎΠ² Π²ΠΏΠ΅ΡΠ΅Π΄ ΠΊΠΎΡΡΡΡ ΠΊΡΠΏΠΈΡΡ ΡΠΎΠ±Π°ΠΊΡ ΠΊΡΠΏΠΈΡΡ ΡΠ΅Π½ΠΊΠ° ΠΏΠΎΡΠΎΠ΄Ρ ΡΠΎΠ±Π°ΠΊ ΡΠΎΠ±Π°ΠΊΠ° ΡΠΎΠ±Π°ΠΊΠΈ ΡΠΎΡΠΎ ΡΠ΅Π½ΠΊΠΈ ΡΠ΅Π½ΠΊΠΈ ΠΌΠ΅ΡΡΡ ΡΠ΅Π½ΠΊΠΈ Π½Π΅ΠΌΠ΅ΡΠΊΠΎΠΉ ΡΠ΅Π½ΠΊΠΈ ΠΎΠ²ΡΠ°ΡΠΊΠΈ There are categories "cats" and "dogs". Each category corresponds to a part of the words that can define a category. For example, for "Kitties": cat, cats, kittens, for "Dogs": dogs, puppies. In fact, there are much more categories and parts of keywords for selection. Yes, and load lists of several hundred thousand lines. Now the distribution is as follows:
$all_keys = explode("\r\n", $_POST['all_keys']);//ΡΠ°Π·Π±ΠΈΠ²Π°Π΅ΠΌ ΠΏΠΎΡΡΡΠΎΡΠ½ΠΎ foreach($all_keys as $str_keys) { $name_category = 'unsort';//ΠΊΠ°ΡΠ΅Π³ΠΎΡΠΈΡ ΠΏΠΎ ΡΠΌΠΎΠ»ΡΠ°Π½ΠΈΡ, ΠΊΠ°ΠΊ Π½Π΅ΡΠΎΡΡΠΈΡΠΎΠ²Π°Π½Π½ΡΠ΅ $cats_key = array ("ΠΊΠΎΡ", "ΠΊΠΎΡΠΊ", "ΠΊΠΎΡΡ");//ΡΠΏΠΈΡΠΎΠΊ ΡΠ°ΡΡΠ΅ΠΉ ΠΊΠ»ΡΡΠ΅ΠΉ Π΄Π»Ρ ΠΎΠΏΡΠ΅Π΄Π΅Π»Π΅Π½ΠΈΡ ΠΊΠ°ΡΠ΅Π³ΠΎΡΠΈΠΈ foreach ($cats_key as $cats) { $poisk = stripos ($str_keys, $cats); //ΠΏΡΠΎΠ²Π΅ΡΡΠ΅ΠΌ Π½Π΅ΠΆΠ΅Π»Π°ΡΠ΅Π»ΡΠ½ΡΠ΅ ΡΠ»ΠΎΠ²Π° if ($poisk !== false) { $name_category = 'cats'; goto endsort;//Π΅ΡΠ»ΠΈ ΠΊΠ°ΡΠ΅Π³ΠΎΡΠΈΡ ΠΏΡΠΈΡΠ²ΠΎΠ΅Π½Π°, ΡΠΎ ΡΡΠ°Π·Ρ Π·Π°ΠΏΠΈΡΡΠ²Π°Π΅ΠΌ ΡΠ»ΠΎΠ²ΠΎ Π² Π±Π°Π·Ρ } } $dogs_key = array ("ΡΠΎΠ±Π°ΠΊ", "ΡΠ΅Π½ΠΊ"); foreach ($dogs_key as $dogs) { $poisk1 = stripos ($str_keys, $dogs); if ($poisk1 !== false) { $name_category = 'dogs'; goto endsort; } } endsort: mysqli_query ($db, "INSERT INTO keywords (keyword, theme_key) VALUES ('$str_keys', '$name_category')"); unset ($name_category); } I am sure that there is a more intelligible decision. If the categories will increase, the number of parts of the words, too, then the download will be very heavy with such a search of each word. Advise how you can simplify the process of parsing the line. Parts of keys can be stored in code, in a text document, in the database. Thank you in advance. I will add the purpose of all this: Statistics are taken from the statistics in a solid list. The system prepares pages for dogs and cats separately. So, so that the operator for the dogs in the form got the keys only for dogs and the distribution occurs
likeselect the appropriate ones. In general, you can do this in one request. Although something tells me that you need to dig in the direction of full-text search, taking into account word forms, etc. and this is some kind ofsphinx... - Mikeinsert into keywords(keyword, key) select '$str_keys', category from key_categories K where '$str_keys' like concat('%', K.key, '%')only possible to add some group by having having to select each category 1 time in case of coincidence of several roots and it is possible to filter it additionally - Mike