eintopf.info@v0.13.16/service/indexo/place.go (about) 1 // Copyright (C) 2022 The Eintopf authors 2 // 3 // This program is free software: you can redistribute it and/or modify 4 // it under the terms of the GNU Affero General Public License as 5 // published by the Free Software Foundation, either version 3 of the 6 // License, or (at your option) any later version. 7 // 8 // This program is distributed in the hope that it will be useful, 9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 // GNU Affero General Public License for more details. 12 // 13 // You should have received a copy of the GNU Affero General Public License 14 // along with this program. If not, see <https://www.gnu.org/licenses/>. 15 16 package indexo 17 18 import ( 19 "strings" 20 21 "eintopf.info/service/place" 22 ) 23 24 func (s *service) indexPlace(place *place.Place) error { 25 return s.searchService.Index(placeDocumentFromPlace(place)) 26 } 27 28 func placeDocumentFromPlace(place *place.Place) *PlaceDocument { 29 return &PlaceDocument{ 30 ID: place.ID, 31 Published: place.Published, 32 Name: place.Name, 33 Link: place.Link, 34 Email: place.Email, 35 Address: place.Address, 36 Lat: place.Lat, 37 Lng: place.Lng, 38 Image: place.Image, 39 Description: place.Description, 40 Listed: place.Listable(), 41 } 42 } 43 44 type PlaceDocument struct { 45 ID string `json:"id"` 46 Published bool `json:"published"` 47 Name string `json:"name"` 48 Address string `json:"address"` 49 Lat float64 `json:"lat"` 50 Lng float64 `json:"lng"` 51 Link string `json:"link"` 52 Email string `json:"email"` 53 Description string `json:"description"` 54 Image string `json:"image"` 55 OwnedBy []string `json:"ownedBy"` 56 Listed bool `json:"listed"` 57 } 58 59 // Identifier returns an id which should uniquely identify the object for 60 // its type. 61 func (p *PlaceDocument) Identifier() string { 62 return p.ID 63 } 64 65 // Type returns the type of the object. 66 func (p *PlaceDocument) Type() string { 67 return "place" 68 } 69 70 // QueryText returns the string to index for a text search. 71 func (p *PlaceDocument) QueryText() string { 72 var b strings.Builder 73 b.WriteString(p.Name) 74 b.WriteString(" ") 75 b.WriteString(p.Description) 76 return b.String() 77 } 78 79 // SearchFields returns a map of fields to be index for searching. 80 func (p *PlaceDocument) SearchFields() map[string]interface{} { 81 return map[string]interface{}{ 82 "is": p.Type(), 83 "name": p.Name, 84 "id": p.ID, 85 "listed": p.Listed, 86 "published": p.Published, 87 } 88 }