diff --git a/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/helper/plugin/PluginComparatorFactory.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/helper/plugin/PluginComparatorFactory.java index 808276fd3e228dd9da12e7ffc9a9e87a47440622..7e53021ebf677de23a8d0ad1d32b2cd75aaeceba 100644 --- a/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/helper/plugin/PluginComparatorFactory.java +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/helper/plugin/PluginComparatorFactory.java @@ -17,7 +17,10 @@ package ch.ethz.sis.openbis.generic.server.asapi.v3.helper.plugin; import java.util.Comparator; +import java.util.Map; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.common.fetchoptions.SortParameter; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.common.search.ISearchCriteria; import ch.ethz.sis.openbis.generic.asapi.v3.dto.plugin.Plugin; import ch.ethz.sis.openbis.generic.asapi.v3.dto.plugin.fetchoptions.PluginSortOptions; import ch.ethz.sis.openbis.generic.server.asapi.v3.helper.sort.AbstractStringComparator; @@ -44,7 +47,7 @@ public class PluginComparatorFactory extends ComparatorFactory } @Override - public Comparator<Plugin> getComparator(String field) + public Comparator<Plugin> getComparator(String field, Map<SortParameter, String> parameters, ISearchCriteria criteria) { if (PluginSortOptions.NAME.equals(field)) { diff --git a/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/helper/sort/FetchedFieldsScoreComparator.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/helper/sort/FetchedFieldsScoreComparator.java index 4104cd4bd585efca5afa35cdb984a4d563b55ba1..c02894de135373f3eb7d0ad30aab2b035979a69d 100644 --- a/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/helper/sort/FetchedFieldsScoreComparator.java +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/helper/sort/FetchedFieldsScoreComparator.java @@ -55,7 +55,14 @@ public class FetchedFieldsScoreComparator<OBJECT extends IEntityTypeHolder & IPr private List<Boost> boosts = new ArrayList<Boost>(); private Map<OBJECT, Integer> scoreCache = new HashMap<>(); - public FetchedFieldsScoreComparator(Map<SortParameter, String> parameters, ISearchCriteria criteria) { + private Integer fullCodeBoost = 0; + private Integer partialCodeBoost = 0; + private Integer fullPropertyBoost = 0; + private Integer fullTypeBoost = 0; + private Integer partialPropertyBoost = 0; + + public FetchedFieldsScoreComparator(Map<SortParameter, String> parameters, ISearchCriteria criteria) + { if (criteria == null || (criteria instanceof AbstractEntitySearchCriteria) == false) { throw new IllegalArgumentException("Missing criteria"); @@ -64,6 +71,28 @@ public class FetchedFieldsScoreComparator<OBJECT extends IEntityTypeHolder & IPr if (parameters == null) { throw new IllegalArgumentException("Missing score parameters"); + } else + { + if(parameters.containsKey(SortParameter.FULL_CODE_BOOST)) + { + fullCodeBoost = Integer.parseInt(parameters.get(SortParameter.FULL_CODE_BOOST)); + } + if(parameters.containsKey(SortParameter.PARTIAL_CODE_BOOST)) + { + partialCodeBoost = Integer.parseInt(parameters.get(SortParameter.PARTIAL_CODE_BOOST)); + } + if(parameters.containsKey(SortParameter.FULL_PROPERTY_BOOST)) + { + fullPropertyBoost = Integer.parseInt(parameters.get(SortParameter.FULL_PROPERTY_BOOST)); + } + if(parameters.containsKey(SortParameter.FULL_TYPE_BOOST)) + { + fullTypeBoost = Integer.parseInt(parameters.get(SortParameter.FULL_TYPE_BOOST)); + } + if(parameters.containsKey(SortParameter.PARTIAL_PROPERTY_BOOST)) + { + partialPropertyBoost = Integer.parseInt(parameters.get(SortParameter.PARTIAL_PROPERTY_BOOST)); + } } this.parameters = parameters; @@ -74,10 +103,12 @@ public class FetchedFieldsScoreComparator<OBJECT extends IEntityTypeHolder & IPr this.exactMatchTerms = new ArrayList<String>(); this.boosts = new ArrayList<Boost>(); - for(ISearchCriteria subCriteria:this.criteria.getCriteria()) { + for(ISearchCriteria subCriteria:this.criteria.getCriteria()) + { ISearchCriteriaParser<ISearchCriteria> parser = criteriaParsers.get(subCriteria.getClass()); - if(parser != null) { + if(parser != null) + { String value = parser.getValue(subCriteria); // Full Index @@ -226,10 +257,10 @@ public class FetchedFieldsScoreComparator<OBJECT extends IEntityTypeHolder & IPr if(code != null) { if (isPartialMatch(code, partialTerm)) { // If code matches partially - score += 100000 * boost.getCodeBoost(); + score += partialCodeBoost * boost.getCodeBoost(); if (isExactMatch(code, exactTerm)) { // If code matches exactly - score += 1000000 * boost.getCodeBoost(); + score += fullCodeBoost * boost.getCodeBoost(); } } } @@ -239,7 +270,7 @@ public class FetchedFieldsScoreComparator<OBJECT extends IEntityTypeHolder & IPr { if (isExactMatch(typeCode, exactTerm)) { // If type matches exactly - score += 1000 * boost.getTypeCodeBoost(); + score += fullTypeBoost * boost.getTypeCodeBoost(); } } @@ -253,10 +284,10 @@ public class FetchedFieldsScoreComparator<OBJECT extends IEntityTypeHolder & IPr String propertyValue = properties.get(propertykey); if (isPartialMatch(propertyValue, partialTerm)) { // If property matches partially - score += 100 * boost.getPropertyBoost(propertykey); + score += partialPropertyBoost * boost.getPropertyBoost(propertykey); if (isExactMatch(propertyValue, exactTerm)) { // If property matches exactly - score += 10000 * boost.getPropertyBoost(propertykey); + score += fullPropertyBoost * boost.getPropertyBoost(propertykey); } } } @@ -264,7 +295,6 @@ public class FetchedFieldsScoreComparator<OBJECT extends IEntityTypeHolder & IPr } } - System.out.println("CODE: "+ code + " SCORE: " + score); return score; }