fix: search fix for magazines and other docs
This commit is contained in:
+8
-3
@@ -107,10 +107,13 @@ func main() {
|
|||||||
}
|
}
|
||||||
defer mongoDB.Close()
|
defer mongoDB.Close()
|
||||||
|
|
||||||
// Create Typesense client
|
// Create Typesense client.
|
||||||
|
// Default connection timeout is 5s — too short for large content imports
|
||||||
|
// (magazines and other_documents can ship multi-MB batches).
|
||||||
tsClient := typesense.NewClient(
|
tsClient := typesense.NewClient(
|
||||||
typesense.WithServer(cfg.TypesenseURL),
|
typesense.WithServer(cfg.TypesenseURL),
|
||||||
typesense.WithAPIKey(cfg.TypesenseAPIKey),
|
typesense.WithAPIKey(cfg.TypesenseAPIKey),
|
||||||
|
typesense.WithConnectionTimeout(5*time.Minute),
|
||||||
)
|
)
|
||||||
|
|
||||||
// Determine which collections to index
|
// Determine which collections to index
|
||||||
@@ -909,7 +912,8 @@ func indexMagazines(sugar *zap.SugaredLogger, tsClient *typesense.Client, mongoD
|
|||||||
}
|
}
|
||||||
|
|
||||||
sugar.Infof("[magazines] Read %d documents from MongoDB", len(docs))
|
sugar.Infof("[magazines] Read %d documents from MongoDB", len(docs))
|
||||||
importBatch(sugar, tsClient, "magazines", docs, 500)
|
// Smaller batch size: each magazine issue can have very large paragraphs
|
||||||
|
importBatch(sugar, tsClient, "magazines", docs, 25)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ==================== OTHER DOCUMENTS ====================
|
// ==================== OTHER DOCUMENTS ====================
|
||||||
@@ -983,7 +987,8 @@ func indexOtherDocuments(sugar *zap.SugaredLogger, tsClient *typesense.Client, m
|
|||||||
}
|
}
|
||||||
|
|
||||||
sugar.Infof("[other_documents] Read %d documents from MongoDB", len(docs))
|
sugar.Infof("[other_documents] Read %d documents from MongoDB", len(docs))
|
||||||
importBatch(sugar, tsClient, "other_documents", docs, 500)
|
// Smaller batch size: each chapter can have very large paragraphs
|
||||||
|
importBatch(sugar, tsClient, "other_documents", docs, 25)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ==================== HELPERS ====================
|
// ==================== HELPERS ====================
|
||||||
|
|||||||
@@ -181,6 +181,8 @@ func (h *SearchHandler) multiSearch(ctx context.Context, collections []string, q
|
|||||||
}
|
}
|
||||||
|
|
||||||
exhaustive := true
|
exhaustive := true
|
||||||
|
prioritizeExact := true
|
||||||
|
prioritizeTokenPos := true
|
||||||
searches := make([]api.MultiSearchCollectionParameters, 0, len(collections))
|
searches := make([]api.MultiSearchCollectionParameters, 0, len(collections))
|
||||||
for _, col := range collections {
|
for _, col := range collections {
|
||||||
queryBy := collectionQueryByFields[col]
|
queryBy := collectionQueryByFields[col]
|
||||||
@@ -196,6 +198,10 @@ func (h *SearchHandler) multiSearch(ctx context.Context, collections []string, q
|
|||||||
Prefix: stringPtr("true"),
|
Prefix: stringPtr("true"),
|
||||||
NumTypos: stringPtr("2"),
|
NumTypos: stringPtr("2"),
|
||||||
ExhaustiveSearch: &exhaustive,
|
ExhaustiveSearch: &exhaustive,
|
||||||
|
// Boost docs whose tokens are exact matches and appear early in the field
|
||||||
|
// so "karma" outranks "karmic" and frequent matches outrank single ones.
|
||||||
|
PrioritizeExactMatch: &prioritizeExact,
|
||||||
|
PrioritizeTokenPosition: &prioritizeTokenPos,
|
||||||
}
|
}
|
||||||
if weights != "" {
|
if weights != "" {
|
||||||
params.QueryByWeights = stringPtr(weights)
|
params.QueryByWeights = stringPtr(weights)
|
||||||
@@ -254,6 +260,8 @@ func (h *SearchHandler) singleSearch(ctx context.Context, collection, query stri
|
|||||||
}
|
}
|
||||||
|
|
||||||
exhaustive := true
|
exhaustive := true
|
||||||
|
prioritizeExact := true
|
||||||
|
prioritizeTokenPos := true
|
||||||
params := &api.SearchCollectionParams{
|
params := &api.SearchCollectionParams{
|
||||||
Q: stringPtr(query),
|
Q: stringPtr(query),
|
||||||
QueryBy: stringPtr(queryBy),
|
QueryBy: stringPtr(queryBy),
|
||||||
@@ -262,6 +270,10 @@ func (h *SearchHandler) singleSearch(ctx context.Context, collection, query stri
|
|||||||
Prefix: stringPtr("true"),
|
Prefix: stringPtr("true"),
|
||||||
NumTypos: stringPtr("2"),
|
NumTypos: stringPtr("2"),
|
||||||
ExhaustiveSearch: &exhaustive,
|
ExhaustiveSearch: &exhaustive,
|
||||||
|
// Boost docs whose tokens are exact matches and appear early in the field
|
||||||
|
// so "karma" outranks "karmic" and frequent matches outrank single ones.
|
||||||
|
PrioritizeExactMatch: &prioritizeExact,
|
||||||
|
PrioritizeTokenPosition: &prioritizeTokenPos,
|
||||||
}
|
}
|
||||||
if weights := collectionQueryByWeights[collection]; weights != "" {
|
if weights := collectionQueryByWeights[collection]; weights != "" {
|
||||||
params.QueryByWeights = stringPtr(weights)
|
params.QueryByWeights = stringPtr(weights)
|
||||||
|
|||||||
Reference in New Issue
Block a user