Skip to content

[IOS] : Filter is not working in IOS #237

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
ShivaniNTT opened this issue Apr 15, 2025 · 2 comments
Open

[IOS] : Filter is not working in IOS #237

ShivaniNTT opened this issue Apr 15, 2025 · 2 comments

Comments

@ShivaniNTT
Copy link

I am currently using
"typesense-instantsearch-adapter": "^2.8.0"
"expo": "~51.0.28",
"react-native": "0.75.1",
"algoliasearch": "^5.20.4",

I tried to apply filter for that I have added this code here which is totally working fine for android but not working on ios

export const typesenseInstantSearchAdapter = new TypesenseInstantsearchAdapter({
	server: {
		apiKey: process.env.TYPESENSE_API_KEY,
		nodes: [
			{
				host: process.env.TYPESENSE_HOST,
				port: 443,
				protocol: 'https',
			},
		],
	},
	collectionSpecificSearchParameters: {
		news_and_articles: {
			query_by: 'title',
		},
		videos: {
			query_by: 'name, description',
		},
		players: {
			query_by: 'forename, middle_name, surname',
		},
		fixtures: {
			query_by: 'opponent',
		},
	},
});
const results = await typesenseInstantSearchAdapter.typesenseClient
	.collections(collection)
	.documents()
	.search(searchParameters ?? {}, {});

if(searchParameters?.filter_by){
	if(Platform.OS === 'android')console.log("results.found ANDROID ===>>>", results.found, displayCollection);
	if(Platform.OS === 'ios')console.log("results.found IOS ===>>>", results.found, displayCollection);
}

I am getting console log for these

Android ==>

LOG  results.found ANDROID ===>>> 19 fixtures
 LOG  results.found ANDROID ===>>> 4 news_and_articles
 LOG  results.found ANDROID ===>>> 0 players
 LOG  results.found ANDROID ===>>> 2 videos

IOS ==>

 LOG  results.found IOS ===>>> 0 news_and_articles
 LOG  results.found IOS ===>>> 0 videos
 LOG  results.found IOS ===>>> 0 players
 LOG  results.found IOS ===>>> 0 fixtures
 LOG  collection ===> news_and_articles
 LOG  searchParameters ===> {"filter_by": "test_team:=['Women']", "page": 1, "q": "test", "query_by": "title"}
 LOG  collection ===> videos
 LOG  searchParameters ===> {"filter_by": "team:=['Women']", "page": 1, "q": "test", "query_by": "name, description"}
 LOG  collection ===> players
 LOG  searchParameters ===> {"filter_by": "team:=['Women']", "page": 1, "q": "test", "query_by": "forename, middle_name, surname"}
 LOG  collection ===> fixtures
 LOG  searchParameters ===> {"filter_by": "team:=['Women']", "page": 1, "q": "test", "query_by": "opponent"}

this is how filter by param is getting passed in api call

Can anyone please check this and let me know what is wrong and what can be solution ?

@jasonbosco
Copy link
Member

This sounds similar to the issues reported in this thread, could you try the workarounds mentioned there:

typesense/typesense-js#272 (comment)

@ShivaniNTT
Copy link
Author

ShivaniNTT commented Apr 16, 2025

This sounds similar to the issues reported in this thread, could you try the workarounds mentioned there:

typesense/typesense-js#272 (comment)

I tried this solution but it did not work I hope what I am doing is fine

export const typesenseInstantSearchAdapter = new TypesenseInstantsearchAdapter({
	server: {
		apiKey: process.env.TYPESENSE_API_KEY,
		nodes: [
			{
				host: process.env.TYPESENSE_HOST,
				port: 443,
				protocol: 'https',
			},
		],
	},
	collectionSpecificSearchParameters: {
		news_and_articles: {
			query_by: 'title',
		},
		videos: {
			query_by: 'name, description',
		},
		players: {
			query_by: 'forename, middle_name, surname',
		},
		fixtures: {
			query_by: 'opponent',
		},

	},
	// ...(Platform.OS === "ios" &&
    //     parseInt(Platform.Version, 10) >= 17 && {
    //         paramsSerializer: (params: Record<string, any>) => {
    //             const serializedParams = new URLSearchParams(params).toString();
    //             console.log("iOS 17+ paramsSerializer:", serializedParams);
    //             return serializedParams;
    //         },
    //     }),

		...(Platform.OS === "ios" && parseInt(Platform.Version, 10) >= 17 && {
			paramsSerializer: (params: any) =>
				qs.stringify(params, { format: "RFC3986" }),
		}),
});

I tried both qs and URLSearchParams

const results = await typesenseInstantSearchAdapter.typesenseClient
.collections(collection)
.documents()
.search(searchParameters ?? {}, {});

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

No branches or pull requests

2 participants