From 9b69ed408c64e9533b86d5482215682c85cf7aa3 Mon Sep 17 00:00:00 2001 From: Amir Kamran Date: Fri, 11 Nov 2016 18:50:53 +0100 Subject: [PATCH 1/2] updated query boosting --- .../dspace/discovery/SolrServiceTweaksPlugin.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/dspace-api/src/main/java/cz/cuni/mff/ufal/dspace/discovery/SolrServiceTweaksPlugin.java b/dspace-api/src/main/java/cz/cuni/mff/ufal/dspace/discovery/SolrServiceTweaksPlugin.java index 1d14f9334c47..868f83d73f14 100644 --- a/dspace-api/src/main/java/cz/cuni/mff/ufal/dspace/discovery/SolrServiceTweaksPlugin.java +++ b/dspace-api/src/main/java/cz/cuni/mff/ufal/dspace/discovery/SolrServiceTweaksPlugin.java @@ -45,14 +45,15 @@ public void additionalSearchParameters(Context context, { String query = discoveryQuery.getQuery(); // follows previous impl, but is it correct? - if (query == null) - { + if (query == null) { query = "*:*"; + } else { + query = "+(" + query + ")" + + " OR title:(" + query + ")^2" + + " OR dc.relation.replaces:[* TO *]^2" + + " OR (dc.relation.replaces:[* TO *] AND -dc.relation.isreplacedby:[* TO *])^2"; } - String q = solrQuery.getQuery() + " OR title:(" + query + ")^5"; - q = q + " OR ((" + q + ") AND -dc.relation.isreplacedby:*)^5 OR ((" + q + ") AND dc.relation.replaces:*)^15"; - solrQuery.setQuery(q); - + solrQuery.setQuery(query); } @Override From 3e0129b7d5ee81709b61bb7b65e35365ca9cfcd6 Mon Sep 17 00:00:00 2001 From: Amir Kamran Date: Mon, 20 Mar 2017 16:09:40 +0100 Subject: [PATCH 2/2] Update SolrServiceTweaksPlugin.java --- .../discovery/SolrServiceTweaksPlugin.java | 32 ++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/dspace-api/src/main/java/cz/cuni/mff/ufal/dspace/discovery/SolrServiceTweaksPlugin.java b/dspace-api/src/main/java/cz/cuni/mff/ufal/dspace/discovery/SolrServiceTweaksPlugin.java index 868f83d73f14..83fa404d9cc4 100644 --- a/dspace-api/src/main/java/cz/cuni/mff/ufal/dspace/discovery/SolrServiceTweaksPlugin.java +++ b/dspace-api/src/main/java/cz/cuni/mff/ufal/dspace/discovery/SolrServiceTweaksPlugin.java @@ -43,17 +43,27 @@ public class SolrServiceTweaksPlugin implements SolrServiceIndexPlugin, public void additionalSearchParameters(Context context, DiscoverQuery discoveryQuery, SolrQuery solrQuery) { - String query = discoveryQuery.getQuery(); - // follows previous impl, but is it correct? - if (query == null) { - query = "*:*"; - } else { - query = "+(" + query + ")" - + " OR title:(" + query + ")^2" - + " OR dc.relation.replaces:[* TO *]^2" - + " OR (dc.relation.replaces:[* TO *] AND -dc.relation.isreplacedby:[* TO *])^2"; - } - solrQuery.setQuery(query); + // This method is called from SolrServiceImpl.resolveToSolrQuery + // at this point the solrQuery object should already have the required query and parameters coming from discoveryQuery + + // get the current query + String query = solrQuery.getQuery(); + + // the query terms must occur in the search results + query = "+(" + query + ")"; + + // if the query terms are in the title increase the significance of search result + query += " OR title:(" + query + ")^2"; + + // if a new version of item available increase the significance of newer item (as the newer version should contain dc.relation.replaces) + query += " OR dc.relation.replaces:[* TO *]^2"; + + // if more than one version of the item is available increase the significance of the newest + // (should contain dc.relation.replaces but should not contain dc.relation.isreplacedby) + query += " OR (dc.relation.replaces:[* TO *] AND -dc.relation.isreplacedby:[* TO *])^2"; + + // set the updated query back to solrQuery + solrQuery.setQuery(query); } @Override