mirror of
https://github.com/foomo/typesense.git
synced 2025-10-16 12:45:37 +00:00
pr fixes
This commit is contained in:
parent
51e1dca878
commit
7ba353715a
@ -313,7 +313,7 @@ func (b *BaseAPI[indexDocument, returnType]) ExpertSearch(
|
||||
results := make([]returnType, 0, len(*searchResponse.Hits))
|
||||
scores := make(pkgtypesense.Scores)
|
||||
|
||||
for _, hit := range *searchResponse.Hits {
|
||||
for i, hit := range *searchResponse.Hits {
|
||||
docMap := *hit.Document
|
||||
|
||||
// Extract document ID safely
|
||||
@ -331,7 +331,7 @@ func (b *BaseAPI[indexDocument, returnType]) ExpertSearch(
|
||||
continue
|
||||
}
|
||||
|
||||
results = append(results, doc)
|
||||
results[i] = doc
|
||||
index := 0
|
||||
if hit.TextMatchInfo != nil && hit.TextMatchInfo.Score != nil {
|
||||
if score, err := strconv.Atoi(*hit.TextMatchInfo.Score); err == nil {
|
||||
|
||||
@ -41,14 +41,8 @@ func (c ContentServer[indexDocument]) Provide(
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ids := make([]string, 0, len(documentInfos))
|
||||
for _, documentInfo := range documentInfos {
|
||||
ids = append(ids, string(documentInfo.DocumentID))
|
||||
}
|
||||
|
||||
uriMap, err := c.contentserverClient.GetURIs(ctx, string(indexID), ids)
|
||||
urlsByIDs, err := c.fetchURLsByDocumentIDs(ctx, indexID, documentInfos)
|
||||
if err != nil {
|
||||
c.l.Error("failed to get URIs", zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -57,7 +51,7 @@ func (c ContentServer[indexDocument]) Provide(
|
||||
if documentProvider, ok := c.documentProviderFuncs[documentInfo.DocumentType]; !ok {
|
||||
c.l.Warn("no document provider available for document type", zap.String("documentType", string(documentInfo.DocumentType)))
|
||||
} else {
|
||||
document, err := documentProvider(ctx, indexID, documentInfo.DocumentID, uriMap)
|
||||
document, err := documentProvider(ctx, indexID, documentInfo.DocumentID, urlsByIDs)
|
||||
if err != nil {
|
||||
c.l.Error(
|
||||
"index document not created",
|
||||
@ -125,3 +119,31 @@ func createFlatRepoNodeMap(node *content.RepoNode, nodeMap map[string]*content.R
|
||||
}
|
||||
return nodeMap
|
||||
}
|
||||
|
||||
func (c ContentServer[indexDocument]) fetchURLsByDocumentIDs(
|
||||
ctx context.Context,
|
||||
indexID typesense.IndexID,
|
||||
documentInfos []typesense.DocumentInfo,
|
||||
) (map[typesense.DocumentID]string, error) {
|
||||
ids := make([]string, len(documentInfos))
|
||||
|
||||
for i, documentInfo := range documentInfos {
|
||||
ids[i] = string(documentInfo.DocumentID)
|
||||
}
|
||||
|
||||
uriMap, err := c.contentserverClient.GetURIs(ctx, string(indexID), ids)
|
||||
if err != nil {
|
||||
c.l.Error("failed to get URIs", zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return convertMapStringToDocumentID(uriMap), nil
|
||||
}
|
||||
|
||||
func convertMapStringToDocumentID(input map[string]string) map[typesense.DocumentID]string {
|
||||
output := make(map[typesense.DocumentID]string, len(input))
|
||||
for key, value := range input {
|
||||
output[typesense.DocumentID(key)] = value
|
||||
}
|
||||
return output
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user