Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

Union parameter not passed in multi-search queries

未關閉
#95 2 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
55/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
停滯
技術堆疊
python
領域
api

研究方向

Start at the MultiSearch.perform entry point shown in the issue and inspect how search_queries becomes the request body. Ensure the Union option is forwarded with the searches, then verify that multi-search requests using Union produce the expected grouped results.

由索引模型根據 Issue 內容生成。

描述

I tried to use multi-search with "Union" type on typesense==1.1.1.

Snippet:

        for model, collection in model_and_collection:
            query.append(
                {
                    "collection": collection.schema_name,
                    "query_by": collection.query_by_fields,
                    "q": q,
                }
            )
        results = client.multi_search.perform(
            {
                "union": True,
                "searches": query,
            }, {
                "per_page": self.paginate_by,
                "page": page_number,
            }
        )

But I realized that the result doesn't consider the union parameter. I have as many results as collection, and not a "grouped" hits results as expected.

After some investigation, I found out that the parameter "union" is not passed to the query.

    def perform(
        self,
        search_queries: MultiSearchRequestSchema,
        common_params: typing.Union[MultiSearchCommonParameters, None] = None,
    ) -> MultiSearchResponse:
        """
        Perform a multi-search operation.

        This method allows executing multiple search queries in a single API call.
        It processes the search parameters, sends the request to the Typesense API,
        and returns the multi-search response.

        Args:
            search_queries (MultiSearchRequestSchema):
                A dictionary containing the list of search queries to perform.
                The dictionary should have a 'searches' key with a list of search
                    parameter dictionaries.
            common_params (Union[MultiSearchCommonParameters, None], optional):
                Common parameters to apply to all search queries. Defaults to None.

        Returns:
            MultiSearchResponse:
                The response from the multi-search operation, containing
                    the results of all search queries.
        """
        stringified_search_params = [
            stringify_search_params(search_params)
            for search_params in search_queries.get("searches")
        ]
        search_body = {"searches": stringified_search_params}

        response: MultiSearchResponse = self.api_call.post(
            MultiSearch.resource_path,
            body=search_body,
            params=common_params,
            as_json=True,
            entity_type=MultiSearchResponse,
        )
        return response

In the code above, you can see that "union" is not put into search_body.

Adding a line like that fixed it:

search_body["union"] = search_queries.get('union', False)

I will try to submit a MR about it.

主要語言
Python
星號
247
分支
66
平均合併
22 小時 47 分鐘
30 天內合併 PR
8

環境準備

這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

typesense/typesense-python 的其他 Issue

查看 typesense/typesense-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。