Skip to content

Commit 18316a6

Browse files
committed
Fix the discounts a little bit
1 parent 53e223a commit 18316a6

1 file changed

Lines changed: 21 additions & 11 deletions

File tree

uploader/uploader.go

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,17 +96,27 @@ func UploadData[T any](client *mongo.Client, ctx context.Context, fptr *os.File,
9696

9797
// If we inserted discounts, text-index the collection so we can search for keywords
9898
if fileName == "discounts" {
99-
_, err := collection.Indexes().CreateOne(ctx, mongo.IndexModel{
100-
Keys: bson.D{
101-
{Key: "category", Value: "text"},
102-
{Key: "business", Value: "text"},
103-
{Key: "address", Value: "text"},
104-
{Key: "discount", Value: "text"},
105-
},
106-
})
107-
if err != nil {
108-
log.Panic(err)
109-
}
99+
/*
100+
// If the search indexes have been created, don't create again
101+
// TODO: Find a way to dynamically avoid creating one when is has been created
102+
_, err = collection.SearchIndexes().CreateOne(ctx, mongo.SearchIndexModel{
103+
Definition: bson.D{
104+
{Key: "mappings", Value: bson.D{
105+
{Key: "dynamic", Value: true},
106+
{Key: "fields", Value: bson.D{
107+
{Key: "category", Value: bson.D{{Key: "type", Value: "string"}}},
108+
{Key: "business", Value: bson.D{{Key: "type", Value: "string"}}},
109+
{Key: "address", Value: bson.D{{Key: "type", Value: "string"}}},
110+
{Key: "discount", Value: bson.D{{Key: "type", Value: "string"}}},
111+
}},
112+
}},
113+
},
114+
Options: options.SearchIndexes().SetName("discount_searches"),
115+
})
116+
if err != nil {
117+
log.Panic(err)
118+
}
119+
*/
110120
}
111121

112122
// Delete all documents from collection

0 commit comments

Comments
 (0)