From 11a5f10c77714b7a4c99902336dac9fe694b9f6e Mon Sep 17 00:00:00 2001 From: Michael Peter Christen Date: Wed, 25 Mar 2026 00:13:17 +0100 Subject: modified ranking and query parser to allow more matches and better ranking --- source/net/yacy/search/query/QueryGoal.java | 13 +++++++------ source/net/yacy/search/query/QueryParams.java | 27 +++++++++++++++------------ 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/source/net/yacy/search/query/QueryGoal.java b/source/net/yacy/search/query/QueryGoal.java index 9a35ae9cc..e621df3c5 100644 --- a/source/net/yacy/search/query/QueryGoal.java +++ b/source/net/yacy/search/query/QueryGoal.java @@ -392,7 +392,7 @@ public class QueryGoal { if (isCatchall()) return new StringBuilder(AbstractSolrConnector.CATCHALL_QUERY); // add goal query - return getGoalQuery(); + return getGoalQuery(false); } /** @@ -496,7 +496,7 @@ public class QueryGoal { if (isCatchall()) return new StringBuilder(AbstractSolrConnector.CATCHALL_QUERY); // add goal query - StringBuilder w = getGoalQuery(); + StringBuilder w = getGoalQuery(true); q.append(w); // combine these queries for all relevant fields @@ -513,21 +513,22 @@ public class QueryGoal { return q; } - private StringBuilder getGoalQuery() { + private StringBuilder getGoalQuery(final boolean strictAllTerms) { int wc = 0; StringBuilder w = new StringBuilder(80); for (String s: include_strings) { if (Segment.catchallString.equals(s)) continue; - if (wc > 0) w.append(" AND "); + if (wc > 0) w.append(strictAllTerms ? " AND " : " "); if (s.indexOf('~') >= 0 || s.indexOf('*') >= 0 || s.indexOf('?') >= 0) w.append(s); else w.append(dq).append(s).append(dq); wc++; } for (String s: exclude_strings){ - if (wc > 0) w.append(" AND -"); + if (wc > 0) w.append(strictAllTerms ? " AND -" : " -"); + else w.append('-'); if (s.indexOf('~') >= 0 || s.indexOf('*') >= 0 || s.indexOf('?') >= 0) w.append(s); else w.append(dq).append(s).append(dq); wc++; } - if (wc > 1) {w.insert(0, '('); w.append(')');} + if (strictAllTerms && wc > 1) {w.insert(0, '('); w.append(')');} return w; } diff --git a/source/net/yacy/search/query/QueryParams.java b/source/net/yacy/search/query/QueryParams.java index ae4f392ce..f0e079fca 100644 --- a/source/net/yacy/search/query/QueryParams.java +++ b/source/net/yacy/search/query/QueryParams.java @@ -621,20 +621,23 @@ public final class QueryParams { * @param filterQueries a mutable list of filter queries, initialized with filters related to content domain. Must not be null. * @return a Solr query instance ready to use */ - private SolrQuery solrQuery(final boolean getFacets, final List filterQueries) { - if (this.cachedQuery != null) { - this.cachedQuery.setStart(this.offset); - if (!getFacets) this.cachedQuery.setFacet(false); - return this.cachedQuery; + private SolrQuery solrQuery(final boolean getFacets, final List filterQueries) { + if (this.cachedQuery != null) { + this.cachedQuery.setStart(this.offset); + if (!getFacets) this.cachedQuery.setFacet(false); + return this.cachedQuery; } - // construct query - final SolrQuery params = getBasicParams(getFacets, filterQueries); - int rankingProfile = this.ranking.coeff_date == RankingProfile.COEFF_MAX ? 1 : (this.modifier.sitehash != null || this.modifier.sitehost != null) ? 2 : 0; - params.setQuery(this.queryGoal.collectionTextQuery().toString()); - Ranking actRanking = indexSegment.fulltext().getDefaultConfiguration().getRanking(rankingProfile); // for a by-date ranking select different ranking profile - - String fq = actRanking.getFilterQuery(); + // construct query + final SolrQuery params = getBasicParams(getFacets, filterQueries); + int rankingProfile = this.ranking.coeff_date == RankingProfile.COEFF_MAX ? 1 : (this.modifier.sitehash != null || this.modifier.sitehost != null) ? 2 : 0; + params.setQuery(this.queryGoal.collectionTextQuery().toString()); + if (this.queryGoal.getIncludeSize() > 1) { + params.setParam(DisMaxParams.MM, "1"); + } + Ranking actRanking = indexSegment.fulltext().getDefaultConfiguration().getRanking(rankingProfile); // for a by-date ranking select different ranking profile + + String fq = actRanking.getFilterQuery(); String bq = actRanking.getBoostQuery(); String bf = actRanking.getBoostFunction(); final String qf = actRanking.getQueryFields(); -- cgit v1.2.3