@@ -10,9 +10,9 @@ import (
10
10
"github.com/whosonfirst/go-whosonfirst-geojson-v2/feature"
11
11
wof_index "github.com/whosonfirst/go-whosonfirst-index"
12
12
"github.com/whosonfirst/go-whosonfirst-sqlite"
13
- "github.com/whosonfirst/go-whosonfirst-uri"
14
13
wof_tables "github.com/whosonfirst/go-whosonfirst-sqlite-features/tables"
15
14
sql_index "github.com/whosonfirst/go-whosonfirst-sqlite-index"
15
+ "github.com/whosonfirst/go-whosonfirst-uri"
16
16
"github.com/whosonfirst/warning"
17
17
"io"
18
18
"io/ioutil"
@@ -24,6 +24,11 @@ type SQLiteFeaturesLoadRecordFuncOptions struct {
24
24
StrictAltFiles bool
25
25
}
26
26
27
+ type SQLiteFeaturesIndexRelationsFuncOptions struct {
28
+ Reader reader.Reader
29
+ Strict bool
30
+ }
31
+
27
32
func SQLiteFeaturesLoadRecordFunc (opts * SQLiteFeaturesLoadRecordFuncOptions ) sql_index.SQLiteIndexerLoadRecordFunc {
28
33
29
34
cb := func (ctx context.Context , fh io.Reader , args ... interface {}) (interface {}, error ) {
@@ -82,8 +87,16 @@ func SQLiteFeaturesLoadRecordFunc(opts *SQLiteFeaturesLoadRecordFuncOptions) sql
82
87
83
88
func SQLiteFeaturesIndexRelationsFunc (r reader.Reader ) sql_index.SQLiteIndexerPostIndexFunc {
84
89
90
+ opts := & SQLiteFeaturesIndexRelationsFuncOptions {}
91
+ opts .Reader = r
92
+
93
+ return SQLiteFeaturesIndexRelationsFuncWithOptions (opts )
94
+ }
95
+
96
+ func SQLiteFeaturesIndexRelationsFuncWithOptions (opts * SQLiteFeaturesIndexRelationsFuncOptions ) sql_index.SQLiteIndexerPostIndexFunc {
97
+
85
98
seen := new (sync.Map )
86
-
99
+
87
100
cb := func (ctx context.Context , db sqlite.Database , tables []sqlite.Table , record interface {}) error {
88
101
89
102
geojson_t , err := wof_tables .NewGeoJSONTable ()
@@ -137,7 +150,7 @@ func SQLiteFeaturesIndexRelationsFunc(r reader.Reader) sql_index.SQLiteIndexerPo
137
150
}
138
151
139
152
seen .Store (id , true )
140
-
153
+
141
154
sql := fmt .Sprintf ("SELECT COUNT(id) FROM %s WHERE id=?" , geojson_t .Name ())
142
155
row := conn .QueryRow (sql , id )
143
156
@@ -158,10 +171,16 @@ func SQLiteFeaturesIndexRelationsFunc(r reader.Reader) sql_index.SQLiteIndexerPo
158
171
return err
159
172
}
160
173
161
- fh , err := r .Read (ctx , rel_path )
174
+ fh , err := opts . Reader .Read (ctx , rel_path )
162
175
163
- if err != nil {
164
- return err
176
+ if err != nil {
177
+
178
+ if opts .Strict {
179
+ return err
180
+ }
181
+
182
+ log .Printf ("Failed to read '%s' because '%v'. Strict mode is disabled so skipping\n " , rel_path , err )
183
+ continue
165
184
}
166
185
167
186
defer fh .Close ()
@@ -170,9 +189,15 @@ func SQLiteFeaturesIndexRelationsFunc(r reader.Reader) sql_index.SQLiteIndexerPo
170
189
171
190
// check for warnings in case this record has a non-standard
172
191
// placetype (20201224/thisisaaronland)
173
-
174
- if err != nil && ! warning .IsWarning (err ){
175
- return err
192
+
193
+ if err != nil && ! warning .IsWarning (err ) {
194
+
195
+ if opts .Strict {
196
+ return err
197
+ }
198
+
199
+ log .Printf ("Failed to load feature for '%s' because '%v'. Strict mode is disabled so skipping\n " , rel_path , err )
200
+ continue
176
201
}
177
202
178
203
to_index = append (to_index , ancestor )
0 commit comments