#community-help

Overcoming Query String Error with Multi-Search in Flutter

TLDR Andrew was getting a query string error and tried to switch to multi-search. Jason helped them implement it correctly, clarifying the differences between single and multi-search, and confirmed that the multi-search is unbounded.

Powered by Struct AI

1

9
11mo
Solved
Join the chat
Nov 02, 2022 (11 months ago)
Andrew
Photo of md5-7766f890de99fa72a6d81315691a6758
Andrew
09:48 PM
hey guys, im getting this error:

"Query string exceeds max allowed length of 4000. Use the /multi_search end-point for larger payloads."

How would i get around this? Im using flutter so i dont know if i need to change the search function. For reference, that function looks like:

  Future<Map<String, dynamic>> search(
      Map<String, dynamic> searchParameters) async {
    return await _apicall.get(
      '$_endPoint/search',
      queryParams: searchParameters,
      shouldCacheResult: true,
    );
  }

Will changing /search to /multiSearch work?
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
09:52 PM
Correct, you would have to switch to using multi search
Andrew
Photo of md5-7766f890de99fa72a6d81315691a6758
Andrew
09:57 PM
Im having a bit of trouble editing the package's file. I created
Future<Map<String, dynamic>> multiSearch(
      Map<String, dynamic> searchParameters) async {
    return await _apicall.get(
      '$_endPoint/multi_search',
      queryParams: searchParameters,
      shouldCacheResult: true,
    );
  }

Inside of documents.dart, but when i try to call the method, i get
Error: The method 'multiSearch' isn't defined for the class 'Documents'.
lib/…
- 'Documents' is from 'package:typesense/src...').
package:typesense/src/documents.dart:1
Try correcting the name to the name of an existing method, or defining a method named 'multiSearch'.
        await _typesenseClient.collection('users').documents.multiSearch({
                                                             ^^^^^^^^^^^

Any idea why this doesnt work?
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
10:09 PM
Multi search is already implemented in the dart library, so you can use it directly like in the code sample here: https://typesense.org/docs/0.23.1/api/federated-multi-search.html
Andrew
Photo of md5-7766f890de99fa72a6d81315691a6758
Andrew
10:45 PM
I think i got it working, is there a drawback to using multisearch instead of normal search? Ie why not use it by default?
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
11:00 PM
We had single collection search first and we added multi search in a later version to search across collections efficiently. But you can still use multi search to search just one collection. There are no differences except that multi search uses post and single collection search uses GET
Andrew
Photo of md5-7766f890de99fa72a6d81315691a6758
Andrew
11:55 PM
Awesome, thanks!
11:55
Andrew
11:55 PM
And slightly related, but i had to switch because i hit the string length limit for a query on single search. Is multi search unbounded?
Nov 03, 2022 (11 months ago)
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
12:24 AM
Correct

1