Skip to content

Commit

Permalink
Modifications related to #253. Here the Cache is filled only with geo…
Browse files Browse the repository at this point in the history
…:name data; this removes the search by zip code, but avoids performance issues when searching by (not filtering by!) country -in odisp ALL cities and regions contain also the country : 'ville (zip) - country'.
  • Loading branch information
ilucatero committed Sep 1, 2015
1 parent 28af904 commit bb3d46e
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ public class GeographicalAreaCache {
/** ex. "http://data.ozwillo.com/dc/type/geocifr:Commune_0/FR/FR-38/Saint-Clair-de-la-Tour" */
@Value("${application.geoarea.searchCronField:@id}")
private String searchCronField; // "@id";
@Value("${application.geoarea.findOneTokenLimit:100}")
private int findOneTokenLimit;

@Autowired
private Tokenizer tokenizer;
Expand All @@ -106,7 +108,7 @@ public Stream<GeographicalArea> search(String country_uri, String modelType, Str
// 2. flatten the results into one big stream
// 3. reduce the stream into a list of pairs <Area, Frequency>
// 4. sort the stream in reverse frequency order so that results that match multiple query terms come first
// 4. turn this back into a stream of areas and return
// 5. turn this back into a stream of areas and return

class Pair {
GeographicalArea area;
Expand Down Expand Up @@ -192,9 +194,16 @@ private Stream<GeographicalArea> findOneToken(String countryUri, String modelTyp

criteria.and("nameTokens").regex(name);

return template.find(
query(criteria).limit(100).with(new Sort(Sort.Direction.ASC, "replicationTime")),
GeographicalArea.class )
List<GeographicalArea> foundAreas = template.find(
query(criteria).limit(findOneTokenLimit) // limit to prevent too much performance-hampering object scanning
.with(new Sort(Sort.Direction.ASC, "replicationTime")),
GeographicalArea.class);
if (foundAreas.size() == findOneTokenLimit) {
// should not happen
logger.warn("Hit findOneTokenLimit (so probably missing some results) on query " + query(criteria));
}

return foundAreas
.stream()
.map(DCUrlWrapper::new)
.distinct()
Expand Down Expand Up @@ -253,7 +262,7 @@ public void run() {
// 3. switch all "incoming" entries to "online"
long switchStart = System.currentTimeMillis();
this.switchToOnline();
logger.debug("Switch to online in {} ms", System.currentTimeMillis() - switchStart);
logger.debug("Switched to online in {} ms", System.currentTimeMillis() - switchStart);
logger.info("Finish replication of {} geographical records from data core", collection.getCount());
} catch (RestClientException e) {
logger.error("Error while updating the geo area cache", e);
Expand Down Expand Up @@ -288,7 +297,7 @@ private String fetchBatches(DBCollection collection, Set<String> loadedUris, Str

for (Languages language : Languages.values()) {

GeographicalArea area = geographicalDAO.toGeographicalArea(res, language.getLanguage(), displayNameField, nameField);
GeographicalArea area = geographicalDAO.toGeographicalArea(res, language.getLanguage(), nameField, null); // displayNameField is not taken
if (area == null) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

@Document(collection = "geographical_area")
@CompoundIndexes({
@CompoundIndex(name = "lang_nametokens", def = "{'lang':1, 'nameTokens':1}"),
@CompoundIndex(name = "lang_nametokens_country", def = "{'lang':1, 'nameTokens':1, country:1}")
})
public class GeographicalArea {
Expand Down Expand Up @@ -63,6 +62,7 @@ public class GeographicalArea {
private GeographicalAreaReplicationStatus status = GeographicalAreaReplicationStatus.INCOMING;

@JsonIgnore
@Indexed // used by result sort
private Instant replicationTime = Instant.now();

public GeographicalArea() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ public String toString() {
", name:'" + name + '\'' +
", type:" + type +
", territory_id:" + territoryId +
", dcId:" + dcId +
", status:" + status +
", admin:" + admin +
", members:" + members +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ application:
cityModel: geoci:City_0
countryField: geo:country
fallbackLanguage: en
#use: Seconds | Min | Hour | Day-of-month | Month | Day-of-week(sunday=0) | Year = http://www.quartz-scheduler.org/documentation/quartz-1.x/tutorials/crontrigger
replication: 0 0 1 1/5 * ? #Runs at 1am every 5 days every month, starting on the first day of the month
#replication: 0 0/1 * * * ? #Runs every minute
findOneTokenLimit: 100
# use: Seconds | Min | Hour | Day-of-month | Month | Day-of-week(sunday=0) | Year => 0 0/30 * * * (every 30 minutes) | 0 30 * * * (at the minute 30 of any hour)
# examples http://www.quartz-scheduler.org/documentation/quartz-1.x/tutorials/crontrigger
replication: 0 0 1 1/5 * ? #Runs at 1am every 5 days every month, starting on the first day of the month
#replication: 0 0/5 * * * ? #Runs every minute
dcOrg:
project: org
orgModel: org:Organization_0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ var CountrySelect = React.createClass({

render: function() {
var label = this.props.defLabel;
if(!this.props.value || this.props.value === ""){
if(label && (!this.props.value || this.props.value === "") ){
//This is to load the country_uri that couldn't be set |
this.props.value = (this.getValue(label)); // decodeURIComponent()
}
Expand Down

Large diffs are not rendered by default.

0 comments on commit bb3d46e

Please sign in to comment.