Skip to content

Union#2051

Merged
kishorenc merged 16 commits into
typesense:v28from
happy-san:union
Dec 16, 2024
Merged

Union#2051
kishorenc merged 16 commits into
typesense:v28from
happy-san:union

Conversation

@happy-san

@happy-san happy-san commented Nov 6, 2024

Copy link
Copy Markdown
Contributor

Change Summary

  • Sample request:
curl 'http://localhost:8108/multi_search?page=1&per_page=2' -X POST -H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" -d '
{
  "union": true,
  "searches": [
    {
      "collection": "posts",
      "q": "*",
      "filter_by": "user_name:stark_indus"
    },
    {
      "collection": "posts",
      "q": "*",
      "filter_by": "user_name:rogers_steve"
    }
  ]
}' | jq
  • Sample response:
{
  "found": 3,
  "hits": [
    {
      "document": {
        "content": "USA",
        "id": "124",
        "likes": 5215,
        "user_name": "stark_indus"
      },
      "highlight": {},
      "highlights": []
    },
    {
      "document": {
        "content": "CA",
        "id": "125",
        "likes": 2133,
        "user_name": "rogers_steve"
      },
      "highlight": {},
      "highlights": []
    }
  ],
  "out_of": 3,
  "page": 1,
  "search_cutoff": false,
  "search_time_ms": 0,
  "union_request_params": [
    {
      "collection": "posts",
      "first_q": "*",
      "per_page": 2,
      "q": "*"
    },
    {
      "collection": "posts",
      "first_q": "*",
      "per_page": 2,
      "q": "*"
    }
  ]
}
  • Only global pagination parameters "page", "per_page", "offset", "limit", and the parameter "limit_hits" are taken into consideration in union. They are ignored when passed with individual searches.

  • "sort_by" with union requires all the searches to have the same type and number of fields and sorting order to work. For example:

{
  "union": true,
  "searches": [
    {
      ...
      "sort_by": "user_name:asc"
      ...
    },
    {
      ...
      "sort_by": "rating:asc"
      ...
    }
  ]
}

will return an error.

PR Checklist

@happy-san happy-san force-pushed the union branch 2 times, most recently from ce6826a to 198393a Compare November 21, 2024 04:56
@happy-san happy-san force-pushed the union branch 6 times, most recently from 0945e15 to 8254dd2 Compare December 6, 2024 12:00
@happy-san happy-san force-pushed the union branch 3 times, most recently from 81bd9a9 to 3722228 Compare December 12, 2024 11:59
@kishorenc kishorenc merged commit 0855aef into typesense:v28 Dec 16, 2024
@youradds

youradds commented Feb 4, 2025

Copy link
Copy Markdown

Is it possible to "merge" the results so we don't end up with duplicated ids? (whilst still preserving the number of results asked for)

Here is an example from when I do multiple searches using the union option, and multi_search:

Cartoon Bookworm Reading - 139324
Cartoon Bookworm Reading - 139324
vector kid working the computer cartoon - 393724
vector kid working the computer cartoon - 393724
Man holding a big birthday cake - 369271
Man holding a big birthday cake - 369271
kid carrying a stack books - 390647
kid carrying a stack books - 390647
Ipad touch screen - 380274
Ipad touch screen - 380274
Royalty Free RF Clipart Illustration Happy Geek Boy Waving Flat Design - 395758
Royalty Free RF Clipart Illustration Happy Geek Boy Waving Flat Design - 395758
Royalty Free RF Clipart Illustration Smiling Geek Boy Head - 395896
Royalty Free RF Clipart Illustration Smiling Geek Boy Head - 395896
cartoon-children 002 - 381567
cartoon-children 002 - 381567
child a computer - 389841
Cartoon Pencil Character Reading ABC Book - 388921
child a computer - 389841
Cartoon Pencil Character Reading ABC Book - 388921
image college student universitario - 393944
image college student universitario - 393944
kid reading paper - 393978
kid reading paper - 393978
small boy playing a computer cartoon - 397608
small boy playing a computer cartoon - 397608
female college student - 393905
female college student - 393905
vector black white kid working the computer cartoon - 393688
AI Human Integration Concept - 153496
vector black white kid working the computer cartoon - 393688
AI Human Integration Concept - 153496
male college student - 394785
male college student - 394785
cartoon nerd girl head vector clipart - 413043
cartoon nerd girl head vector clipart - 413043

I could obviously filter out the duplicates before rendering them, but that would throw the number of results off by however many duplicates I have (as an example , I had 55 results - but after removing dupes, I ended up with 28, whereas ideally I'd like 55 still :))

Thanks!

@happy-san

Copy link
Copy Markdown
Contributor Author

Hi @youradds That is not possible right now. Can you create a feature request regarding this?

@youradds

youradds commented Feb 5, 2025

Copy link
Copy Markdown

Hi @youradds That is not possible right now. Can you create a feature request regarding this?

Thanks - I've just opened an issue: #2173

@marrishiva3

marrishiva3 commented Apr 25, 2025

Copy link
Copy Markdown

I’m using union search across multiple collections and would like to retrieve facet results. Could you please let me know the correct approach for this?

Specifically:

How can I get facet results when performing a union search?

Is it possible to get combined facet counts across all collections?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants