fix: add pinyin

This commit is contained in:
Tim
2025-09-28 14:28:45 +08:00
parent 23cc2d1606
commit 8869121bcb
2 changed files with 105 additions and 19 deletions

View File

@@ -197,7 +197,7 @@ public class SearchService {
s.multiMatch(mm ->
mm
.query(qRaw)
.fields("title^3", "content^2")
.fields("title^3", "title.py^3", "content^2", "content.py^2")
.type(TextQueryType.BestFields)
.fuzziness("AUTO")
.minimumShouldMatch("70%")
@@ -210,7 +210,17 @@ public class SearchService {
bool.should(s ->
s.queryString(qs ->
qs
.query("(title:" + qsEscaped + "* OR content:" + qsEscaped + "*)")
.query(
"(title:" +
qsEscaped +
"* OR title.py:" +
qsEscaped +
"* OR content:" +
qsEscaped +
"* OR content.py:" +
qsEscaped +
"*)"
)
.analyzeWildcard(true)
)
);
@@ -226,6 +236,30 @@ public class SearchService {
.boost(2.0f)
)
);
bool.should(s ->
s.match(m ->
m
.field("author.py")
.query(v -> v.stringValue(qRaw))
.boost(2.0f)
)
);
bool.should(s ->
s.match(m ->
m
.field("category.py")
.query(v -> v.stringValue(qRaw))
.boost(1.2f)
)
);
bool.should(s ->
s.match(m ->
m
.field("tags.py")
.query(v -> v.stringValue(qRaw))
.boost(1.2f)
)
);
if (enableWildcard) {
// prefix/wildcard 这里的 value 是 String直接传即可