Location search must only return results with known location
This commit is contained in:
parent
977b220c51
commit
feda86f0e2
3 changed files with 25 additions and 16 deletions
|
@ -42,13 +42,14 @@
|
|||
return {
|
||||
zoom: 15,
|
||||
position: null,
|
||||
center: L.latLng(52.5259279, 13.414496),
|
||||
center: L.latLng(0, 0),
|
||||
url: 'https://{s}.tile.osm.org/{z}/{x}/{y}.png',
|
||||
attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors',
|
||||
options: {
|
||||
icon: {
|
||||
iconSize: [40, 40]
|
||||
}
|
||||
iconSize: [50, 50]
|
||||
},
|
||||
minZoom: 3,
|
||||
},
|
||||
photos: [],
|
||||
results: [],
|
||||
|
@ -57,7 +58,7 @@
|
|||
q: q,
|
||||
},
|
||||
offset: 0,
|
||||
pageSize: 100,
|
||||
pageSize: 101,
|
||||
lastQuery: {},
|
||||
bounds: null,
|
||||
minLat: null,
|
||||
|
@ -74,7 +75,7 @@
|
|||
if ("geolocation" in navigator) {
|
||||
const self = this;
|
||||
this.$alert.success('Finding your position...');
|
||||
navigator.geolocation.getCurrentPosition(function(position) {
|
||||
navigator.geolocation.getCurrentPosition(function (position) {
|
||||
self.center = L.latLng(position.coords.latitude, position.coords.longitude);
|
||||
self.position = L.latLng(position.coords.latitude, position.coords.longitude);
|
||||
});
|
||||
|
@ -96,19 +97,19 @@
|
|||
this.maxLong = null;
|
||||
},
|
||||
fitBoundingBox(lat, long) {
|
||||
if(this.maxLat === null || lat > this.maxLat) {
|
||||
if (this.maxLat === null || lat > this.maxLat) {
|
||||
this.maxLat = lat;
|
||||
}
|
||||
|
||||
if(this.minLat === null || lat < this.minLat) {
|
||||
if (this.minLat === null || lat < this.minLat) {
|
||||
this.minLat = lat;
|
||||
}
|
||||
|
||||
if(this.maxLong === null || long > this.maxLong) {
|
||||
if (this.maxLong === null || long > this.maxLong) {
|
||||
this.maxLong = long;
|
||||
}
|
||||
|
||||
if(this.minLong === null || long < this.minLong) {
|
||||
if (this.minLong === null || long < this.minLong) {
|
||||
this.minLong = long;
|
||||
}
|
||||
},
|
||||
|
@ -152,8 +153,11 @@
|
|||
this.center = photos[0].location;
|
||||
this.bounds = [[this.maxLat, this.minLong], [this.minLat, this.maxLong]];
|
||||
|
||||
this.$alert.info(photos.length + ' photos found');
|
||||
|
||||
if (photos.length > 100) {
|
||||
this.$alert.info('More than 100 photos found');
|
||||
} else {
|
||||
this.$alert.info(photos.length + ' photos found');
|
||||
}
|
||||
},
|
||||
|
||||
refreshList() {
|
||||
|
@ -169,6 +173,7 @@
|
|||
const params = {
|
||||
count: this.pageSize,
|
||||
offset: this.offset,
|
||||
location: 1,
|
||||
};
|
||||
|
||||
Object.assign(params, this.query);
|
||||
|
@ -187,9 +192,5 @@
|
|||
this.refreshList();
|
||||
},
|
||||
};
|
||||
|
||||
/* L.icon({
|
||||
html: '<div style="background-image: url(/api/v1/thumbnails/square/40/cc1a022c30fff3d5603f1c3f722ec1960e3fa95e);"></div>',
|
||||
className: 'leaflet-marker-photo' }), */
|
||||
</script>
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
// Query parameters for GET /api/v1/photos
|
||||
type PhotoSearchForm struct {
|
||||
Query string `form:"q"`
|
||||
Location bool `form:"location"`
|
||||
Tags string `form:"tags"`
|
||||
Cat string `form:"cat"`
|
||||
Country string `form:"country"`
|
||||
|
|
|
@ -118,7 +118,14 @@ func (s *Search) Photos(form forms.PhotoSearchForm) ([]PhotoSearchResult, error)
|
|||
Where("photos.deleted_at IS NULL AND files.file_missing = 0").
|
||||
Group("photos.id, files.id")
|
||||
|
||||
if form.Query != "" {
|
||||
if form.Location == true {
|
||||
q = q.Where("location_id > 0")
|
||||
|
||||
if form.Query != "" {
|
||||
likeString := "%" + strings.ToLower(form.Query) + "%"
|
||||
q = q.Where("LOWER(locations.loc_display_name) LIKE ?", likeString)
|
||||
}
|
||||
} else if form.Query != "" {
|
||||
likeString := "%" + strings.ToLower(form.Query) + "%"
|
||||
q = q.Where("tags.tag_label LIKE ? OR LOWER(photo_title) LIKE ? OR LOWER(files.file_main_color) LIKE ?", likeString, likeString, likeString)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue