diff --git a/cmd/indexer/main.go b/cmd/indexer/main.go index ff5ec8d..0659892 100644 --- a/cmd/indexer/main.go +++ b/cmd/indexer/main.go @@ -107,10 +107,13 @@ func main() { } 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( typesense.WithServer(cfg.TypesenseURL), typesense.WithAPIKey(cfg.TypesenseAPIKey), + typesense.WithConnectionTimeout(5*time.Minute), ) // 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)) - 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 ==================== @@ -983,7 +987,8 @@ func indexOtherDocuments(sugar *zap.SugaredLogger, tsClient *typesense.Client, m } 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 ==================== diff --git a/internal/handler/search.go b/internal/handler/search.go index 51035e5..8fdbeee 100644 --- a/internal/handler/search.go +++ b/internal/handler/search.go @@ -181,6 +181,8 @@ func (h *SearchHandler) multiSearch(ctx context.Context, collections []string, q } exhaustive := true + prioritizeExact := true + prioritizeTokenPos := true searches := make([]api.MultiSearchCollectionParameters, 0, len(collections)) for _, col := range collections { queryBy := collectionQueryByFields[col] @@ -196,6 +198,10 @@ func (h *SearchHandler) multiSearch(ctx context.Context, collections []string, q Prefix: stringPtr("true"), NumTypos: stringPtr("2"), 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 != "" { params.QueryByWeights = stringPtr(weights) @@ -254,6 +260,8 @@ func (h *SearchHandler) singleSearch(ctx context.Context, collection, query stri } exhaustive := true + prioritizeExact := true + prioritizeTokenPos := true params := &api.SearchCollectionParams{ Q: stringPtr(query), QueryBy: stringPtr(queryBy), @@ -262,6 +270,10 @@ func (h *SearchHandler) singleSearch(ctx context.Context, collection, query stri Prefix: stringPtr("true"), NumTypos: stringPtr("2"), 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 != "" { params.QueryByWeights = stringPtr(weights)