Configuring portal search redirection

Loading

In Power Pages (formerly PowerApps Portals), configuring search redirection allows you to customize the behavior of the search functionality. When a user performs a search, you might want to redirect them to a different page based on their query or provide custom handling for search results. By using Power Pages features like search configurations and Liquid templates, you can control the search behavior and improve the user experience.

Here’s a step-by-step guide on how to configure portal search redirection in Power Pages:


Step 1: Understand Portal Search Capabilities

Power Pages provides a built-in search feature that allows users to search across the content in the portal, including web pages, list records, and custom data entities. When a user enters a search term, Power Pages automatically queries the indexed data and returns results.

However, sometimes you might want to redirect users to a different page based on their search input or handle searches in a custom manner, like:

  • Redirecting to a product category page when the user searches for a specific product.
  • Showing specific content or filtering results based on the search query.

Step 2: Customize the Search Page

Power Pages provides a Search page where all search results are displayed. To configure search redirection, you can modify the search page template or use Liquid templates to dynamically handle redirection.

Example: Customizing the Search Page Template

  1. Go to the Portal Management: Open the Portal Management area for your Power Pages.
  2. Locate the Search Page: Under Web Pages, find the search page (usually named Search or something similar).
  3. Modify the Search Results Display: You can modify the Liquid template used to render the search results.

Step 3: Redirect Users Based on Search Terms

If you want to redirect users to a different page based on their search query, you can use JavaScript to monitor the search term and trigger a redirection.

Example: Redirect Based on Search Term Using JavaScript

In your search page template, you can embed JavaScript to detect the search term and redirect the user accordingly.

window.onload = function() {
var searchTerm = window.location.search.split('=')[1]; // Extract search term from query string

if (searchTerm) {
if (searchTerm.toLowerCase() === 'laptop') {
window.location.href = '/products/laptops'; // Redirect to laptops category
} else if (searchTerm.toLowerCase() === 'shoes') {
window.location.href = '/products/shoes'; // Redirect to shoes category
}
// Add more conditions as needed for redirection
}
};

Explanation:

  • window.location.search: This gets the search query from the URL (e.g., ?q=laptop).
  • searchTerm.toLowerCase(): Converts the search term to lowercase for case-insensitive matching.
  • window.location.href: Redirects the user to the appropriate page based on the search term.

Step 4: Customize Search Results Using Liquid Templates

If you prefer to handle the redirection at the Liquid template level, you can use Liquid code to evaluate the search query and return specific results or redirect users.

Example: Redirect Using Liquid

{% assign searchTerm = request.params.q %}  <!-- Get search query from the URL -->

{% if searchTerm == 'laptop' %}
<meta http-equiv="refresh" content="0; url='/products/laptops'" />
{% elsif searchTerm == 'shoes' %}
<meta http-equiv="refresh" content="0; url='/products/shoes'" />
{% else %}
<p>No specific redirection set for this search term.</p>
{% endif %}

Explanation:

  • request.params.q: This gets the search term entered by the user.
  • <meta http-equiv="refresh" content="0; url=..." />: The meta tag refreshes the page and redirects the user to a new URL.
  • The Liquid conditionals ({% if %}, {% elsif %}, {% else %}) check for the search term and apply different redirects based on the query.

Step 5: Create Custom Search Pages for Specific Categories

Instead of just redirecting the user, you can create custom search result pages that display results based on categories or certain filters. For example, if the user searches for a specific product type, you can filter the search results to show relevant data.

Example: Filtering Search Results by Category Using Liquid

{% assign searchTerm = request.params.q %}
{% assign category = request.params.category %}

{% if category == 'electronics' %}
<h1>Search Results for Electronics</h1>
<ul>
{% for product in site.products %}
{% if product.category == 'electronics' and product.name contains searchTerm %}
<li>
<a href="{{ product.url }}">{{ product.name }}</a>
</li>
{% endif %}
{% endfor %}
</ul>
{% elsif category == 'clothing' %}
<h1>Search Results for Clothing</h1>
<ul>
{% for product in site.products %}
{% if product.category == 'clothing' and product.name contains searchTerm %}
<li>
<a href="{{ product.url }}">{{ product.name }}</a>
</li>
{% endif %}
{% endfor %}
</ul>
{% else %}
<p>No results found for your search.</p>
{% endif %}

Explanation:

  • category == 'electronics': Filters results based on the category passed in the URL.
  • product.name contains searchTerm: Filters products where the name contains the search term.

Step 6: Test and Monitor Search Behavior

Once you have implemented the search redirection or filtering logic, it’s important to test the behavior thoroughly:

  1. Test different search queries: Ensure that search queries trigger the correct redirection or display relevant results.
  2. Monitor user behavior: Track the effectiveness of search redirection. If needed, you can modify the search handling to make it more efficient.
  3. SEO Considerations: Be cautious when using redirects (especially JavaScript-based) as it could impact search engine optimization (SEO) rankings. Consider SEO-friendly redirects if necessary.

Step 7: Additional Considerations

  • Security: Ensure that the query string parameters are properly sanitized to avoid potential security risks like URL injection.
  • Custom Search Engines: If you need more advanced search capabilities, consider integrating custom search engines like Azure Cognitive Search for more fine-tuned results and filtering options.

Leave a Reply

Your email address will not be published. Required fields are marked *