Improve Facebook lead comment keyword matching
This commit is contained in:
@@ -29,13 +29,37 @@ public class FacebookLeadCollectorService {
|
||||
private static final DateTimeFormatter FACEBOOK_TIMESTAMP_FORMAT =
|
||||
DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssZ");
|
||||
|
||||
private static final List<String> KEYWORDS = List.of(
|
||||
normalizeForSearch("хочу купить"),
|
||||
normalizeForSearch("напишите в лс"),
|
||||
normalizeForSearch("напишете в лс"),
|
||||
normalizeForSearch("цена"),
|
||||
normalizeForSearch("как заказать"),
|
||||
normalizeForSearch("сколько стоит")
|
||||
private static final List<String> HOT_LEAD_KEYWORDS = List.of(
|
||||
normalizeForSearch("адрес"),
|
||||
normalizeForSearch("филиал"),
|
||||
normalizeForSearch("где вы"),
|
||||
normalizeForSearch("где находит"),
|
||||
normalizeForSearch("как доехать"),
|
||||
normalizeForSearch("график"),
|
||||
normalizeForSearch("режим"),
|
||||
normalizeForSearch("со скольки"),
|
||||
normalizeForSearch("до скольки"),
|
||||
normalizeForSearch("работает"),
|
||||
normalizeForSearch("открыты"),
|
||||
normalizeForSearch("доставк"),
|
||||
normalizeForSearch("заказ"),
|
||||
normalizeForSearch("меню"),
|
||||
normalizeForSearch("привез"),
|
||||
normalizeForSearch("оформить"),
|
||||
normalizeForSearch("яндекс"),
|
||||
normalizeForSearch("wolt"),
|
||||
normalizeForSearch("glovo"),
|
||||
normalizeForSearch("цен"),
|
||||
normalizeForSearch("стоит"),
|
||||
normalizeForSearch("прайс"),
|
||||
normalizeForSearch("каспи"),
|
||||
normalizeForSearch("qr"),
|
||||
normalizeForSearch("red"),
|
||||
normalizeForSearch("лс"),
|
||||
normalizeForSearch("директ"),
|
||||
normalizeForSearch("личк"),
|
||||
normalizeForSearch("номер"),
|
||||
normalizeForSearch("телефон")
|
||||
);
|
||||
|
||||
private final FacebookLeadProperties properties;
|
||||
@@ -191,11 +215,12 @@ public class FacebookLeadCollectorService {
|
||||
continue;
|
||||
}
|
||||
|
||||
String matchedKeyword = findMatchedKeyword(message);
|
||||
if (matchedKeyword == null) {
|
||||
if (!containsHotLeadKeyword(message)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String matchedKeyword = findMatchedKeyword(message);
|
||||
|
||||
log.info("Hot Facebook comment detected. commentId={}, author={}, matchedKeyword='{}', message='{}'",
|
||||
externalCommentId, authorName, matchedKeyword, shorten(message));
|
||||
|
||||
@@ -224,9 +249,13 @@ public class FacebookLeadCollectorService {
|
||||
return savedCount;
|
||||
}
|
||||
|
||||
private String findMatchedKeyword(String message) {
|
||||
static boolean containsHotLeadKeyword(String message) {
|
||||
return findMatchedKeyword(message) != null;
|
||||
}
|
||||
|
||||
private static String findMatchedKeyword(String message) {
|
||||
String normalizedMessage = normalizeForSearch(message);
|
||||
return KEYWORDS.stream()
|
||||
return HOT_LEAD_KEYWORDS.stream()
|
||||
.filter(normalizedMessage::contains)
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
|
||||
@@ -13,6 +13,7 @@ import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
@@ -260,4 +261,13 @@ class FacebookLeadCollectorServiceTest {
|
||||
assertEquals("ежик напишете в лс", normalized);
|
||||
assertTrue(normalized.contains("напишете в лс"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void containsHotLeadKeywordShouldMatchExpandedKeywordRootsIgnoringCase() {
|
||||
assertTrue(FacebookLeadCollectorService.containsHotLeadKeyword("Подскажите, где находиться ваш филиал?"));
|
||||
assertTrue(FacebookLeadCollectorService.containsHotLeadKeyword("Есть ли ДОСТАВКА через Wolt?"));
|
||||
assertTrue(FacebookLeadCollectorService.containsHotLeadKeyword("Можно оплатить по Каспи QR или Red?"));
|
||||
assertTrue(FacebookLeadCollectorService.containsHotLeadKeyword("Напишите в личку номер телефона"));
|
||||
assertFalse(FacebookLeadCollectorService.containsHotLeadKeyword("Спасибо за красивый пост"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user