Commit af153c2a authored by Jérémy Destin's avatar Jérémy Destin
Browse files

fix: Change the query use to get the germplasm list and use filter to have...

fix: Change the query use to get the germplasm list and use filter to have more accurate result. GNP-4309
parent 4b535c5a
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<annotationProcessing>
<profile name="Gradle Imported" enabled="true">
<outputRelativeToContentRoot value="true" />
<processorPath useClasspath="false">
<entry name="$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.springframework.boot/spring-boot-configuration-processor/2.1.2.RELEASE/db9671c321defb942a6700fae8a7700a137a25e/spring-boot-configuration-processor-2.1.2.RELEASE.jar" />
</processorPath>
<module name="faidare.backend.main" />
</profile>
</annotationProcessing>
<bytecodeTargetLevel>
<module name="faidare.backend.main" target="1.8" />
<module name="faidare.backend.test" target="1.8" />
......
......@@ -64,7 +64,7 @@ public class ESGenericQueryFactory<C> implements ESQueryFactory<C> {
List<QueryBuilder> queries = createQueryFromMapping(criteria, null, null, voMappingToCriteria, documentMetadata);
if (!queries.isEmpty()) {
return orQueries(queries);
return germplasmFilterQueries(queries);
} else {
return matchAllQuery();
}
......@@ -103,7 +103,7 @@ public class ESGenericQueryFactory<C> implements ESQueryFactory<C> {
List<QueryBuilder> queries = createQueryFromMapping(criteria, null, excludedDocumentFields, voMappingToCriteria, documentMetadata);
if (!queries.isEmpty()) {
return orQueries(queries);
return germplasmFilterQueries(queries);
} else {
return matchAllQuery();
}
......@@ -142,7 +142,7 @@ public class ESGenericQueryFactory<C> implements ESQueryFactory<C> {
List<QueryBuilder> queries = createQueryFromMapping(criteria, includedDocumentFields, null, voMappingToCriteria, documentMetadata);
if (!queries.isEmpty()) {
return orQueries(queries);
return germplasmFilterQueries(queries);
} else {
return matchAllQuery();
}
......@@ -367,21 +367,44 @@ public class ESGenericQueryFactory<C> implements ESQueryFactory<C> {
*
* @return null if not queries given; the first query if only one query is given; a bool query otherwise
*/
public static QueryBuilder orQueries(List<QueryBuilder> queries) {
public static QueryBuilder germplasmFilterQueries(List<QueryBuilder> queries) {
if (queries == null || queries.isEmpty()) {
return null;
} else if (queries.size() == 1) {
return queries.get(0);
} else {
List<String> shouldCriterion = Arrays.asList("commonCropName",
"species", "germplasmGenus", "genusSpecies", "subtaxa", "genus",
"genusSpeciesSubtaxa", "taxonSynonyms", "panel", "collection", "population",
"germplasmName", "accessionNumber", "synonyms");
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
BoolQueryBuilder boolShouldQueryBuilder = QueryBuilders.boolQuery();
List<QueryBuilder> filterQueries = new ArrayList<>();
for (QueryBuilder query : queries) {
boolQueryBuilder.should(query);
boolean isShouldCriterion = stringContainsItemFromList(query.toString(), shouldCriterion);
if (isShouldCriterion){
boolShouldQueryBuilder.should(query);
} else {
filterQueries.add(query);
}
}
boolQueryBuilder.must(boolShouldQueryBuilder);
for (QueryBuilder query: filterQueries) {
boolQueryBuilder.filter(query);
}
return boolQueryBuilder;
}
}
public static QueryBuilder orQueries(QueryBuilder... queries) {
return andQueries(Arrays.asList(queries));
public static boolean stringContainsItemFromList(String inputStr, List<String> items)
{
for(String item: items)
{
if(inputStr.contains(item))
{
return true;
}
}
return false;
}
}
......@@ -117,8 +117,7 @@ export class GermplasmResultPageComponent implements OnInit {
accessionNumbers: asArray(criteria.accessions),
synonyms: asArray(criteria.accessions),
// Do not use the source as a criterion because of the ES should request.
// sources: asArray(criteria.sources)
sources: asArray(criteria.sources)
};
this.germplasmSearchCriteria$.next(this.localCriteria);
......@@ -197,31 +196,4 @@ export class GermplasmResultPageComponent implements OnInit {
this.localCriteria.pageSize = pageSize;
this.germplasmSearchCriteria$.next(this.localCriteria);
}
// Format facets by renaming and merging some facets in one facet.
/*formatFacets(facets: DataDiscoveryFacet[]): DataDiscoveryFacet[] {
const bioStatusAndGeneticNature = [];
let newFacets: DataDiscoveryFacet[] = [];
for (const facet of facets) {
if (facet.field === 'biologicalStatus' || facet.field === 'geneticNature') {
for (const term of facet.terms) {
bioStatusAndGeneticNature
.push(term);
}
} else if (facet.field === 'holdingInstitute') {
facet.field = 'holding institute';
newFacets.push(facet);
} else {
newFacets.push(facet);
}
}
newFacets = [
{
field: 'Biological status / Genetic nature',
terms: bioStatusAndGeneticNature
},
...newFacets
];
return newFacets;
}*/
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment