Skip to content
Snippets Groups Projects
Commit cbf55cfc authored by juanf's avatar juanf
Browse files

SP-935 / BIS-517 : ELN UI - Copy YeastLab iPad Search for ELN service

SVN: 30006
parent 71ef8b3f
No related branches found
No related tags found
No related merge requests found
...@@ -44,45 +44,26 @@ public class SearchResultSorterByScore implements ISearchResultSorter ...@@ -44,45 +44,26 @@ public class SearchResultSorterByScore implements ISearchResultSorter
return; return;
} }
// 1. Get terms to use as input for the main algorithm // 1. Get terms and boosts to use as input for the main algorithm
List<Pattern> partialMatchTerms = new ArrayList<Pattern>(); List<Pattern> partialMatchTerms = new ArrayList<Pattern>();
List<String> exactMatchTerms = new ArrayList<String>(); List<String> exactMatchTerms = new ArrayList<String>();
List<Boost> boosts = new ArrayList<Boost>(); List<Boost> boosts = new ArrayList<Boost>();
for (DetailedSearchCriterion criterion : criteria.getCriteria()) for (DetailedSearchCriterion criterion : criteria.getCriteria())
{ {
// Full Index
partialMatchTerms.add(getPartialMatchTerm(criterion.getValue())); partialMatchTerms.add(getPartialMatchTerm(criterion.getValue()));
exactMatchTerms.add(getExactMatchTerm(criterion.getValue())); exactMatchTerms.add(getExactMatchTerm(criterion.getValue()));
boosts.add(getBoostForCriterion(criterion, 10));
// Split Index
String[] splitIndexes = criterion.getValue().replace("*", " ").replace("?", " ").replaceAll("\\s+", " ").trim().split(" ");
switch (criterion.getField().getKind()) for (String splitIndex : splitIndexes)
{ {
case ANY_FIELD: partialMatchTerms.add(getPartialMatchTerm(splitIndex));
boosts.add(new Boost(1, 1, 1, 1, null)); exactMatchTerms.add(getExactMatchTerm(splitIndex));
break; boosts.add(getBoostForCriterion(criterion, 1));
case ANY_PROPERTY:
boosts.add(new Boost(0, 0, 1, 1, null));
break;
case PROPERTY:
boosts.add(new Boost(0, 0, 0, 1, criterion.getField().getPropertyCode()));
break;
case ATTRIBUTE:
if (criterion.getField().getAttributeCode().equalsIgnoreCase("code"))
{
boosts.add(new Boost(1, 0, 0, 0, null)); // Attribute code
} else if ( // TODO FIX hard coded types, will be clever to not naming the same thing differently internally to avoid this.
criterion.getField().getAttributeCode().equalsIgnoreCase("sample_type")
|| criterion.getField().getAttributeCode().equalsIgnoreCase("data_set_type")
|| criterion.getField().getAttributeCode().equalsIgnoreCase("material_type")
|| criterion.getField().getAttributeCode().equalsIgnoreCase("experiment_type"))
{
boosts.add(new Boost(0, 1, 0, 0, null)); // Attribute type code
} else
{
boosts.add(new Boost(1, 1, 1, 1, null)); // Other attributes not supported, default to general case
}
break;
case REGISTRATOR:
boosts.add(new Boost(1, 1, 1, 1, null)); // Registrator not supported, default to general case
break;
} }
} }
...@@ -113,6 +94,8 @@ public class SearchResultSorterByScore implements ISearchResultSorter ...@@ -113,6 +94,8 @@ public class SearchResultSorterByScore implements ISearchResultSorter
} }
} }
}); });
System.out.println(entitiesToSort);
} }
private int getScore(IEntitySearchResult entity, List<Pattern> partialMatchTerms, List<String> exactMatchTerms, List<Boost> boosts) private int getScore(IEntitySearchResult entity, List<Pattern> partialMatchTerms, List<String> exactMatchTerms, List<Boost> boosts)
...@@ -157,7 +140,7 @@ public class SearchResultSorterByScore implements ISearchResultSorter ...@@ -157,7 +140,7 @@ public class SearchResultSorterByScore implements ISearchResultSorter
} }
} }
} }
// For development System.out.println(entity.getCode() + " " + score); System.out.println(entity.getCode() + " " + score);
return score; return score;
} }
...@@ -209,6 +192,38 @@ public class SearchResultSorterByScore implements ISearchResultSorter ...@@ -209,6 +192,38 @@ public class SearchResultSorterByScore implements ISearchResultSorter
} }
public Boost getBoostForCriterion(DetailedSearchCriterion criterion, int boost)
{
switch (criterion.getField().getKind())
{
case ANY_FIELD:
return new Boost(boost, boost, boost, boost, null); // Default case
case ANY_PROPERTY:
return new Boost(0, 0, boost, boost, null);
case PROPERTY:
return new Boost(0, 0, 0, boost, criterion.getField().getPropertyCode());
case ATTRIBUTE:
if (criterion.getField().getAttributeCode().equalsIgnoreCase("code"))
{
return new Boost(boost, 0, 0, 0, null); // Attribute code
} else if ( // TODO FIX hard coded types, will be clever to not naming the same thing differently internally to avoid this.
criterion.getField().getAttributeCode().equalsIgnoreCase("sample_type")
|| criterion.getField().getAttributeCode().equalsIgnoreCase("data_set_type")
|| criterion.getField().getAttributeCode().equalsIgnoreCase("material_type")
|| criterion.getField().getAttributeCode().equalsIgnoreCase("experiment_type"))
{
return new Boost(0, boost, 0, 0, null); // Attribute type code
} else
{
return new Boost(boost, boost, boost, boost, null); // Other attributes not supported, default to general case
}
case REGISTRATOR:
return new Boost(boost, boost, boost, boost, null); // Registrator not supported, default to general case
default:
return new Boost(boost, boost, boost, boost, null); // Default to general case
}
}
public Pattern getPartialMatchTerm(String term) public Pattern getPartialMatchTerm(String term)
{ {
return Pattern.compile(("*" + term + "*").replace("*", ".*").replace("?", ".?"), Pattern.CASE_INSENSITIVE); return Pattern.compile(("*" + term + "*").replace("*", ".*").replace("?", ".?"), Pattern.CASE_INSENSITIVE);
......
...@@ -130,6 +130,23 @@ public class SearchResultSorterByScoreTest extends AssertJUnit ...@@ -130,6 +130,23 @@ public class SearchResultSorterByScoreTest extends AssertJUnit
assertEntities(entities, "CODE_4", "CODE_1", "CODE_2", "CODE_3"); assertEntities(entities, "CODE_4", "CODE_1", "CODE_2", "CODE_3");
} }
@Test
public void testCriteriaPropForPropertiesWithSpaces()
{
// Entities Setup
List<EntitySearchResult> entities = new ArrayList<EntitySearchResult>();
entities.add(createEntity("CODE_2", "TYPE_2", "ABC"));
entities.add(createEntity("CODE_1", "TYPE_1", "ABC "));
entities.add(createEntity("CODE_3", "TYPE_3", "ABC", "DEF"));
entities.add(createEntity("CODE_4", "TYPE_4", "ABC \tDEF"));
// Test hit only properties, partial and exact
sort(entities, getPropertyFieldCriterion("PROP_1", "ABC \tDEF"));
// Verify results
assertEntities(entities, "CODE_4", "CODE_2", "CODE_3", "CODE_1");
}
@Test @Test
public void testCriteriaAnyPropForProperties() public void testCriteriaAnyPropForProperties()
{ {
...@@ -147,6 +164,23 @@ public class SearchResultSorterByScoreTest extends AssertJUnit ...@@ -147,6 +164,23 @@ public class SearchResultSorterByScoreTest extends AssertJUnit
assertEntities(entities, "CODE_1", "CODE_4", "CODE_3", "CODE_2"); assertEntities(entities, "CODE_1", "CODE_4", "CODE_3", "CODE_2");
} }
@Test
public void testCriteriaAnyPropForPropertiesWithSpaces()
{
// Entities Setup
List<EntitySearchResult> entities = new ArrayList<EntitySearchResult>();
entities.add(createEntity("CODE_2", "TYPE_2", "ABC"));
entities.add(createEntity("CODE_1", "TYPE_1", "ABC "));
entities.add(createEntity("CODE_3", "TYPE_3", "ABC", "DEF"));
entities.add(createEntity("CODE_4", "TYPE_4", "ABC \tDEF"));
// Test hit only properties, partial and exact
sort(entities, getAnyPropertyFieldCriterion("ABC \tDEF"));
// Verify results
assertEntities(entities, "CODE_4", "CODE_3", "CODE_2", "CODE_1");
}
@Test @Test
public void testCriteriaAnyAll() public void testCriteriaAnyAll()
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment