This tutorial explain the approach to enable Geo Location based redirects with CloudFront and Apache.
Geo IP based redirection
Geo IP based redirection is the process of automatically redirecting a website visitor by their geolocation.
There are multiple options to enable the location based redirects in Apache, one of the option is using Geo IP database like MaxMind Geo IP database to map users’s IP to their location. Maxmind Geo IP database can be enabled through Apache module.
If you are using any of the CDN e.g CloudFront provides specific headers with request location, CloudFront will detect the user’s country of origin and pass along the county code to origin server in the CloudFront-Viewer-Country header. You can use this information to customize your responses e.g redirecting the users to specific URL based on origin country.
Prerequisites
Website enabled with CloudFront CDN and Apache
CloudFront Configurations
As a first step white list the CloudFront-Viewer-Country header in Cloudfront distribution
RewriteCond %{REQUEST_URI} ^/content/we-retail.html RewriteCond %{HTTP:CLOUDFRONT-VIEWER-COUNTRY} ^US$ RewriteRule ^.*$ https://test.albinsblog.com/content/we-retail/us/en.html [R=302,L] RewriteCond %{REQUEST_URI} ^/content/we-retail.html RewriteCond %{HTTP:CLOUDFRONT-VIEWER-COUNTRY} ^IT$ RewriteRule ^.*$ https://test.albinsblog.com/content/we-retail/it/it.html [R=302,L] RewriteCond %{REQUEST_URI} ^/content/we-retail.html RewriteCond %{HTTP:CLOUDFRONT-VIEWER-COUNTRY} ^CA RewriteRule ^.*$ https://test.albinsblog.com/content/we-retail/ca/en.html [R=302,L] RewriteCond %{REQUEST_URI} ^/content/we-retail.html RewriteCond %{HTTP:CLOUDFRONT-VIEWER-COUNTRY} ^FR$ RewriteRule ^.*$ https://test.albinsblog.com/content/we-retail/fr/fr.html [R=302,L] <Directory /> Options Indexes FollowSymLinks Includes # Set includes to process .html files AddOutputFilter INCLUDES .html AddOutputFilterByType INCLUDES text/html AllowOverride None </Directory>
</VirtualHost>
I am using some VPN tool to initiate the connection from different origin country.
Connected the VPN to Canada
Now the user is redirected to Canada specific URL
The user is redirected to the country specific URL based on the users country of origin, CloudFront will detect the user’s country of origin and pass along the county code to origin server(Apache) in the CloudFront-Viewer-Country header. The Apache server redirect the user to the country specific URL’s based on the country code values in CloudFront-Viewer-Country header.
The dynamic facet is used to create new range selections automatically at the time of search. The facets are included dynamically based on the search result.
The Dynamic Facets feature is not enabled in Adobe Search&Promote, by default. Contact Technical Support to activate the feature for your use.
In our previous tutorial, we have seen how to enable static facet for the search results. Refer the below link for the details, the steps are going to be same for Dynamic facet with small changes.
Facets that are sparsely populated across your website and only appear for a subset of searches are good candidates to make dynamic.
In our example, the product with type “Watch” will have an additional attribute with name “size” and the facet associated with “size” is applicable only for the searches with keyword “Watch”.
The search with key word “Watch” will shows two facets “productType”(static) and “size”(dynamic) but the search with “Book” will shows only “productType”(static) facet.
Configuring Dynamic Facet
Some additional configuration required to enable Dynamic Facet compared to Static Facet(Refer Static facet tutorial for basic configurations)
Enabled additional product attribute to the feed file based on the product Type — “size”, “size” attribute is applicable only for the productType “Watch”
Create a new meta data definition for “size” field, Settings → Metadata →Definitions
Enable Dynamic Facet option for the metadata
Update the IndexConnector configurations with new meta data field “size”, Settings → Crawling →Index Connector
Configure facet with name “size” — there is no “Dynamic Facet” setting in Facet, only the configuration is in the underlying metadata configuration(already enabled), Design →Navigation →Facets
Configure a new Query Cleaning rule, Rules → Query Cleaning , to set the backend parameter “sp_sfvl_df_count”, the sp_sfvl_df_count parameter determines the total number of dynamic facet fields to return.
Update the back end transport with Dynamic Facet Support
The configuration can be pushed live after successful validation and run a live index →Full Index →Live Index →Run Full Index
The URL to access live data http://xxxxxxxxxxx.guided.ss-omtrdc.net/do=json&sp_q=Watch
The facet data in the response can be used to present the filtering options to users to narrow down the website search. The Dynamic Facet option enables the facets based on the search data.
How to implement autocompletion and search suggestion in AEM through Lucene | Predictive Search in AEM | AEM Search Suggestions
This tutorial explain the approach to implement autocompletion and search suggestion in AEM through Lucene.
When you start typing something in search form most of the applications helps you by suggesting the data matching to your search term.
The purpose of autocomplete is to resolve a partial query , i.e., to search within a controlled vocabulary for items matching a given character string.
Starting from AEM 6.1 the feature of suggestion is available through the suggest module of Lucene. Prior to AEM 6.1, all the possible combination of the words needs to be indexed to support the autocompletion.
The Lucene Suggest module provides a dedicated and optimized data structure allows the engine to give autocompletion and suggestion feature without indexing all the possible combination of a word.
There is a specific analyzer (AnalyzingInfixSuggester) used that loads the completion values from the indexed data and then build the optimized structure in memory for a fast lookup.
In order to implements the autosuggestion, feature you need to define an index of type Lucene and for each property X of nodes that you are indexing you can add a specific property useInSuggest to tell to the engine to use X for suggesting query to the user.
I have already enabled a custom Lucene index(testindex) for the property "id", add a property "useInSuggest" to tell the engine to use id for suggesting query to the user.
An additional property suggestUpdateFrequencyMinutes define the frequency of updating the indexed suggestions - useful to mitigate performance issues that can arise if indexed properties are frequently updated by the users of your application. The default value is 10 minutes but the values can be modified as required.
To enable the property "suggestUpdateFrequencyMinutes ", create a node with name "suggest" of type "nt:unstructured" under "testindex" and update the value as required
In order to use Lucene index to perform search suggestions, the index definition node (the one of type oak:QueryIndexDefinition) needs to have the compatVersion set to 2.
Let us now execute the query to find the suggestions - either one of the below query can be used.
The testindex was defined for the content path "/content/sampledata" so the query will be executed based on the "testindex" but the index name is explicitly defined in the first query.
SELECT [rep:suggest()] FROM [nt:unstructured] WHERE SUGGEST('te') OPTION(INDEX NAME [testindex]) /* oak-internal */
SELECT [rep:suggest()] FROM [nt:unstructured] WHERE SUGGEST('te') AND ISDESCENDANTNODE('/content/sampledata')
The above query uses path restriction to filter the data, it requires evaluatePathRestrictions property should enabled as true on index definition.
The Query tool shows the total number of unique suggestions matching with the search data but it wont displays the matching node details
The below Servlet can be used to fetch the suggestion data through QueryManager API
How to configure Navigation Facet in Adobe Search and Promote?
The Facets can be used to customize your presentation layer and provide your users with a Guided Search that lets them drill down into their search results.
This tutorial explains the approach to configure the facets in Adobe Search & Promote.
The website users can narrow down their search results with enabled facets, there are two types of facets in Search and Promote — Static and Dynamic, we are going to use Static facets for this tutorial.
Refer the below screen shot for example on the facets, the users can narrow down the search based on the brands they interested.
Facet Configuration
The facet is defined based on the metadata, as a first step, define a metadata e.g productType
The meta data’s can be managed from Settings →Metadata →Definitions
The metadata crawled and indexed through URL entry points — URL entry point can be a website URL or feed data through Index Connector, using Index Connector for this tutorial.
The met data is ready now let us configure a facet based on the meta data defined “productType”
Navigate to Design →Navigation →Facets
Add a new Facet
Facet Name — Select the meta data filed based on which the facet should be defined.
Display Label — Enter display label
Behavior — there are different behaviors like Normal, Category, Category Multi-Select, Sticky and Multi-Select, I am going with Normal behavior for this tutorial
Normal — When a customer clicks a facet, whose behavior is set to Normal, it drills into the search results for that item. From there, the customer can further refine and narrow the number of search results.
Category — Category facets act like navigational elements. These facets are top-level facets that customers typically drill through before revealing facets with attribute options. Category facets do not narrow when other facets are selected and remain open. Clicking a different value within a category facet deselects all other facets on the page except for that category facet’s parents.
Category Multi-Select — facets are category facets that support the selection of multiple items from the facet where the items are “ORed” together.
Sticky — When a customer clicks a facet, whose behavior is set to Sticky, the facet with the selected option remains open during the drill-down. This option is useful when you want to let a customer changes a previous choice.
Multi-Select — Allows the selection of multiple items from a facet, where the items within the facet are “ORed” together. This option is useful for a facet that may show a minor attribute such as colors and you want to let the customer have the ability to build a query that lets them “show shoes in my size that are red or black”.
Show Always — For a normal or sticky facet, sets the facet to remain visible to the customer at all times. This option is only available if you selected Normal, Category, or Sticky from the Behavior drop-down list.
Refer the UI for details on other fields, I am only configuring the Facet Name and Facet Label for this tutorial, enable other fields as required.
Click Add, now the facet is enabled based on the meta data field “Product Type”
JSON Transport Template
Transport templates can be either XML or JSON templates that pass data from the back-end search to the Guided Search presentation layer. By default, your account is configured to use XML transport templates. However, JSON Transport template can be enabled if required.
Created a JSON template(custom_backend_json.tpl) with minimal data to support the search data
The new template can be added by navigating to Designs à Templates à Add Template
Select Template Type as Transport
Sample Template Content with minimal configuration– modify based on your requirement, even you can use the existing Transport Template with required customization
Enabled with a single facet — update the template with additional required facets, also add the additional meta data’s and other configurations e.g. breadcrumbs, menus etc
Pre-Search Rules are typically used to select which presentation template displays the results based on the incoming query. More advanced features can be used to alter the query that is used for a search that is being done for a presentation template. The backend CGI parameter can be set from pre-search rules e.g the backend parameter sp_t to select the appropriate backend template can be configured
Define a pre-search rule to configure the presentation and Transport template for the search, the rule is execute when the search request has a parameter “do=json”(the rule can be fired for every search request also)
The configurations are ready, let us now run a Stage indexing (note the configuration are not pushed to live yet)