When running two distinct queries at same time, with different ranking, they both come back with same ranking sort

Hello we are using the js npm package algoliasearch. We have a page where we show two query results, one is sorted by last modified and one is sorted by viewed. Each query uses its own algoliasearch client and index objects and also sets the index.setSettings ranking to different values: ‘desc(modified)’ and ‘desc(viewed)’. We also await each setSettings call.

When the queries come back BOTH queries are shown to have the same ranking value either modified or viewed, even though they were set differently. And those ranking values sometimes flip, sometime coming back as modified and sometimes as viewed but ALWAYS for both queries. Which seems to indicate that there is some kind of delay to set those values on your end.

I’ve tried running the query dozens of times without changing code and it’s always the same behavior: both queries have the same rank (but sometimes its modified and sometimes its viewed).
Note we have other screens where multiple queries are not done, only one query with one specific ranking is done, and those pages work without issue.

Again each call has its own instance of client and index objects. We do not share across calls. This is the code, note it has extra boiler plate for logging purposes.

import algoliasearch, { SearchClient, SearchIndex } from 'algoliasearch';

// note: Algolia dashboard and index settings will use an environment prefix in the name
// for example staging_docs_by_modified
export enum SortingReplicas {
    DocsByModified = 'docs_by_modified',
    DocsByViewed = 'docs_by_viewed'
};

export default class AlgoliaSearch {
    // note: you must set the the facet fields in the dashboard if you are to filter on them!!!
    private requestOptions: { headers: { "x-algolia-application-id": string }, createIfNotExists?: boolean, filters?: string };
    private client: SearchClient;
    private index: SearchIndex
    private mainIndexName: string

    // env is the deployment environment: staging, production, etc.
    constructor(appId: string, apiKey: string, indexName: string, env: string) {
        this.requestOptions = { headers: { "x-algolia-application-id": appId } };
        this.client = algoliasearch(appId, apiKey);     
        this.mainIndexName = indexName;        
        this.index = this.client.initIndex(this.mainIndexName);


        this.index.setSettings({
            attributesForFaceting: [
                'searchable(parentSection)',
                'filterOnly(group)'
            ],
            replicas: [
                env.toLocaleLowerCase() + "_" + SortingReplicas.DocsByModified,
                env.toLocaleLowerCase() + "_" + SortingReplicas.DocsByViewed
            ]
        });
    }

    async saveObjects(docs: any[]) {
        const response = await this.index.saveObjects(docs, this.requestOptions);
        return response.objectIDs;
    }

    async findObject(searchPredicate: (hit: any) => boolean) {
        return await this.index.findObject(searchPredicate, this.requestOptions);
    }

    async updateObjectsPartially(objs: any[], createIfNotExists: boolean = true) {
        const requestOptions = { ...this.requestOptions };
        requestOptions.createIfNotExists = createIfNotExists;
        return await this.index.partialUpdateObjects(objs, requestOptions);
    }

    async search(query: string, sortingReplica: SortingReplicas, filters?: string) {
        await this.resetIndexForSorting(sortingReplica);

        const requestOptions = { ...this.requestOptions };
        if (filters) {
            requestOptions.filters = filters;
        }
        
        console.log("search requestOptions", requestOptions);        
        return await this.index.search(query, requestOptions);
    }

    private async resetIndexForSorting(replica: SortingReplicas) {
        const currentIndexSetting = await this.index.getSettings();
        console.log(replica, "before set", currentIndexSetting);
        if (replica === SortingReplicas.DocsByViewed) {
            if (!currentIndexSetting.ranking?.includes('desc(viewed)')) {
                const response = await this.index.setSettings({
                    ranking: [
                        'desc(viewed)'
                    ]
                });
            }            
            console.log(replica, "viewed after set", await this.index.getSettings());
        } else if (replica === SortingReplicas.DocsByModified) {
            if (!currentIndexSetting.ranking?.includes('desc(modified)')) {
                const response = await this.index.setSettings({
                    ranking: [
                        'desc(modified)'
                    ]
                });
            }
            console.log(replica, "modified after set", await this.index.getSettings());
        }
    }
}