Skip to content
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

AdvancedSearch: Add a feature to hide products based on parameters #11

Open
Draykee opened this issue Mar 16, 2023 · 0 comments
Open

AdvancedSearch: Add a feature to hide products based on parameters #11

Draykee opened this issue Mar 16, 2023 · 0 comments

Comments

@Draykee
Copy link

Draykee commented Mar 16, 2023

Usecase:

  • Specific: In order to publish an app to the iOS AppStore the app is required to allow blocking users. In this case, we can't display the products of another user anymore.
  • General: We need a feature, that hides products from a user. Maybe because he doesn't want to see it anymore, because it's blocked content, or maybe because of other parameters that are disallowing access.

Implementation with elasticsearch
In the past, we used the elasticsearch plugin like this:

// Overwrote the search query:
if (ctx.activeUserId) {
    const owner = await this.productOwnerService.getOwner(ctx);
    // Apply list of blocked users for search input
    searchInput.blocked = owner.customFields.blockedUsers ?? [];
    searchInput.blockedBy = owner.customFields.blockedBy ?? [];
}

const result = await this.elasticsearchService.search(ctx, searchInput, true);
// Inside the elasticsearch config:
mapQuery: (query: any, input: ExtendedSearchInput, searchConfig: DeepRequired<SearchConfig>) => {
    // Don't display product of a block user
    const { blocked = [], blockedBy = [] } = input;
    if (blocked.length > 0 || blockedBy.length > 0) {
        query.bool = {
            ...query.bool,
            must_not: {
                terms: {
                    'product-ownerId.keyword': [...blocked, ...blockedBy],
                },
            },
        };
    }
}
@Draykee Draykee changed the title AdvancedSearch: Allow contains search operation AdvancedSearch: Add a feature to hide products based on parameters Mar 16, 2023
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

1 participant