typesense / typesense-js

JavaScript / TypeScript client for Typesense
https://typesense.org/docs/api
Apache License 2.0
393 stars 74 forks source link

`found_docs` not included in the SearchResponse interface #173

Closed Djones4822 closed 11 months ago

Djones4822 commented 11 months ago

Description

The optional property found_docs is not included in the SearchResponse interface. This property is included when the query includes the group_by parameter

Steps to reproduce

Run a query using group_by on a faceted field. The response object includes the found_docs field

{
    "facet_counts": [],
    "found": 14,
    "found_docs": 14,
    "grouped_hits": [
        {
            "found": 1,
            "group_key": [
                "..."
            ],
            "hits": [
                 ...
            ]
        }
    ],
    "out_of": 14,
    "page": 2,
    "request_params": {
        "collection_name": "companies",
        "per_page": 10,
        "q": "*"
    },
    "search_cutoff": false,
    "search_time_ms": 4
}

Beginning at line 120 in typesense/lib/Typesense/Documents.d.ts

export interface SearchResponse<T extends DocumentSchema> {
    facet_counts?: SearchResponseFacetCountSchema<T>[];
    found: number;
    out_of: number;
    page: number;
    request_params: SearchParams | SearchParamsWithPreset;
    search_time_ms: number;
    hits?: SearchResponseHit<T>[];
    grouped_hits?: {
        group_key: string[];
        hits: SearchResponseHit<T>[];
    }[];
}

Expected Behavior

All properties of the response object are included

Actual Behavior

Property is missing when using group_by

Metadata

Typesense Version: Server: 1.25.1 Client: 1.7.1

OS: Windows and Ubuntu 22.04

Djones4822 commented 11 months ago

I am sidestepping this issue for now with this snippet

import { DocumentSchema, SearchParams, SearchResponse } from 'typesense/lib/Typesense/Documents'
export interface SearchResponseFixed<T extends DocumentSchema> extends SearchResponse<T> {
    found_docs?: number
}
jasonbosco commented 11 months ago

@Djones4822 Thank you for catching this. I've pushed out a fix in 1.7.2-3.