Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ES to filter schools so that limit is correct #557

Merged
merged 1 commit into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/main/java/uk/ac/cam/cl/dtg/segue/api/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@ public enum EventFilterOption {
public static final String SCHOOL_URN_FIELDNAME_POJO = "urn";
public static final String SCHOOL_ESTABLISHMENT_NAME_FIELDNAME_POJO = "name";
public static final String SCHOOL_POSTCODE_FIELDNAME_POJO = "postcode";
public static final String SCHOOL_CLOSED_FIELDNAME_POJO = "closed";

// User School Reporting

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,9 @@

import java.io.IOException;
import java.util.List;
import java.util.Map;

import static uk.ac.cam.cl.dtg.segue.api.Constants.DEFAULT_RESULTS_LIMIT;
import static uk.ac.cam.cl.dtg.segue.api.Constants.SCHOOLS_INDEX_BASE;
import static uk.ac.cam.cl.dtg.segue.api.Constants.SCHOOL_ESTABLISHMENT_NAME_FIELDNAME_POJO;
import static uk.ac.cam.cl.dtg.segue.api.Constants.SCHOOLS_INDEX_TYPE;
import static uk.ac.cam.cl.dtg.segue.api.Constants.SCHOOL_POSTCODE_FIELDNAME_POJO;
import static uk.ac.cam.cl.dtg.segue.api.Constants.SCHOOL_URN_FIELDNAME;
import static uk.ac.cam.cl.dtg.segue.api.Constants.SCHOOL_URN_FIELDNAME_POJO;
import static uk.ac.cam.cl.dtg.segue.api.Constants.UNPROCESSED_SEARCH_FIELD_SUFFIX;
import static uk.ac.cam.cl.dtg.segue.api.Constants.*;

/**
* Class responsible for reading the local school list csv file.
Expand Down Expand Up @@ -95,22 +89,15 @@ public List<School> findSchoolByNameOrPostCode(final String searchQuery, @Nullab

Integer queryLimit = limit == null ? DEFAULT_RESULTS_LIMIT : limit;

// FIXME: for one release cycle, we need backwards compatibility and so cannot use the fieldsThatMustMatch property
// It should be set to ImmutableMap.of("closed", ImmutableList.of("false"))
List<String> schoolSearchResults = searchProvider.fuzzySearch(SCHOOLS_INDEX_BASE, SCHOOLS_INDEX_TYPE.SCHOOL_SEARCH.toString(),
searchQuery, 0, queryLimit, null, null, SCHOOL_URN_FIELDNAME_POJO,
searchQuery, 0, queryLimit, Map.of(SCHOOL_CLOSED_FIELDNAME_POJO, List.of("false")), null, SCHOOL_URN_FIELDNAME_POJO,
SCHOOL_ESTABLISHMENT_NAME_FIELDNAME_POJO, SCHOOL_POSTCODE_FIELDNAME_POJO)
.getResults();

List<School> resultList = Lists.newArrayList();
for (String schoolString : schoolSearchResults) {
try {
School school = mapper.readValue(schoolString, School.class);
if (school.isClosed() != null && school.isClosed()) {
// FIXME: this filtering will be unnecessary once the above fix is implemented!
continue;
}
resultList.add(school);
resultList.add(mapper.readValue(schoolString, School.class));
} catch (JsonParseException | JsonMappingException e) {
log.error("Unable to parse the school " + schoolString, e);
} catch (IOException e) {
Expand Down
Loading