private readonly bool[] _homeLocations; // indexed by location ID public LocationFieldHandler(string locationField, string relocationsField, IBooster booster, ILocationQuery locationQuery) { _locationFieldName = locationField; _relocationsFieldName = relocationsField; _booster = booster; // Build the world index. _worldIndex = new BitWorldIndex(); _worldIndex.BuildUp(locationQuery, true); // Mark locations in the home country. var homeCountry = locationQuery.GetCountry("Australia"); var homePointSet = _worldIndex.GetPointSet(homeCountry.Id, 0); var maxPointSetId = _worldIndex.GetMaxPointSetId(); _homeLocations = new bool[maxPointSetId + 1]; foreach (var location in _worldIndex.GetKnownLocations()) { if (location.Value.Overlaps(homePointSet)) { _homeLocations[location.Key] = true; } } }
public LocationFilter(string locationFieldName, string relocationsFieldName, BitWorldIndex worldIndex, bool[] homeLocations, int queryLocationId, IEnumerable <int> queryRelocationIds, int distance, bool includeRelocating, bool includeInternational) { _locationFieldName = locationFieldName; _relocationsFieldName = relocationsFieldName; _homeLocations = homeLocations; _includeInternational = includeInternational; var maxPointSetId = worldIndex.GetMaxPointSetId(); _matchingLocations = new bool[maxPointSetId + 1]; _includeRelocating = includeRelocating; if (includeRelocating) { _matchingRelocations = new bool[maxPointSetId + 1]; } var queryPointSet = worldIndex.GetPointSet(queryLocationId, distance); if (queryRelocationIds != null) { foreach (var queryRelocationId in queryRelocationIds) { queryPointSet.UnionWith(worldIndex.GetPointSet(queryRelocationId, 0)); } } foreach (var location in worldIndex.GetKnownLocations()) { if (MatchLocation(location.Value, queryPointSet)) { _matchingLocations[location.Key] = true; } if (includeRelocating && MatchRelocation(location.Value, queryPointSet)) { _matchingRelocations[location.Key] = true; } } }