Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      The AI productivity paradox in software engineering: Balancing efficiency and human skill retention

      July 2, 2025

      The impact of gray work on software development

      July 2, 2025

      CSS Intelligence: Speculating On The Future Of A Smarter Language

      July 2, 2025

      Hallucinated code, real threat: How slopsquatting targets AI-assisted development

      July 1, 2025

      Xbox is cancelling Rare’s ‘Everwild’ and ZeniMax’s new MMORPG IP as part of broader cuts — with ‘Perfect Dark’ impacted as well

      July 2, 2025

      Microsoft is closing down Xbox studio The Initiative, with Perfect Dark killed as well — joining Everwild and ZeniMax’s new IP, and other unannounced projects

      July 2, 2025

      No, Microsoft and Xbox’s Phil Spencer isn’t stepping down any time soon — here’s the truth

      July 2, 2025

      Everwild’s cancellation has me worried for one of my favorite dev teams and Xbox itself — It needs creative new games to thrive and refresh its identity

      July 2, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      Trust but Verify: The Curious Case of AI Hallucinations

      July 2, 2025
      Recent

      Trust but Verify: The Curious Case of AI Hallucinations

      July 2, 2025

      From Flow to Fabric: Connecting Power Automate to Microsoft Fabric

      July 2, 2025

      Flutter Web Hot Reload Has Landed – No More Refreshes!

      July 2, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      Xbox is cancelling Rare’s ‘Everwild’ and ZeniMax’s new MMORPG IP as part of broader cuts — with ‘Perfect Dark’ impacted as well

      July 2, 2025
      Recent

      Xbox is cancelling Rare’s ‘Everwild’ and ZeniMax’s new MMORPG IP as part of broader cuts — with ‘Perfect Dark’ impacted as well

      July 2, 2025

      Microsoft is closing down Xbox studio The Initiative, with Perfect Dark killed as well — joining Everwild and ZeniMax’s new IP, and other unannounced projects

      July 2, 2025

      No, Microsoft and Xbox’s Phil Spencer isn’t stepping down any time soon — here’s the truth

      July 2, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»Development»Personalized Optimizely CMS Website Search Experiences Azure AI Search & Personalizer

    Personalized Optimizely CMS Website Search Experiences Azure AI Search & Personalizer

    April 10, 2025
    Personalized Optimizely CMS Website Search Experiences Azure AI Search & Personalizer

    In the last blog, we discussed Integrating the Optimizely CMS website with Azure AI search. Now let’s take a bit more advanced topic to serve Personalization experience with Azure AI search with Azure personalizer. Together, they enable you to serve dynamic customized content and search results across user  behaviour, preferences, and context.

    What is Azure Personalizer?

    Azure Personalizer Cognitive Service for Real-time Association using Reinforcement Learning. It gives you the ability to serve content or experiences that are most relevant to a user — informed by past behaviour and current context.

    Benefits of AI Personalizer:

    • So it can study and evolve as people engage with it.
    • Amazingly helpful for ranking search results.
    • Can customize direct calls to action, highlighted articles, or goods.

    How It Works with Azure AI Search and Optimizely

    1. The user performs a search on your Optimizely site.
    2. Azure AI Search simply gives a  list of matching documents
    3. These documents are sent to Azure Personalizer as “rankable actions.”
    4. The personalized orders results using the context of the user.
    5. Your app serves personalized results and the user’s feedback helps Personalizer to learn & evolve further.

    Set Up Azure Personalizer

    • Navigate to Azure Portal → Personalizer resource creation
    • Save your endpoint and API key.
    • In step 3, specify the Content that you want to be ranked (i.e., search results)

    Integration Code

    Model for Rankable Action

    public class RankableDocument
    {
        public string Id { get; set; }
        public string Title { get; set; }
        public string Summary { get; set; }
        public string Category { get; set; }
    }

    Send Info to Personalizer with Context:

    private object GetUserContext(HttpRequestBase request)
    {
        return new
        {
            timeOfDay = DateTime.Now.Hour,
            device = request.Browser.IsMobileDevice ? "mobile" : "desktop",
            userAgent = request.UserAgent,
            language = request.UserLanguages?.FirstOrDefault() ?? "en"
        };
    }
    public async Task<List<RankableDocument>> GetPersonalizedResultsAsync(List<RankableDocument> documents, string userId)
    {
        var contextFeatures = new[] { GetUserContext(Request) };
    
        var actions = documents.Select(doc => new
        {
            id = doc.Id,
            features = new[]
            {
                new { category = doc.Category },
                new { title = doc.Title }
            }
        });
    
        _eventId = Guid.NewGuid().ToString();
    
        var request = new
        {
            contextFeatures = contextFeatures,
            actions = actions,
            excludedActions = new string[] {},
            eventId = _eventId,
            deferActivation = false
        };
    
        var client = new HttpClient();
        client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", "--YOUR API KEY ---");
        var response = await client.PostAsync("--Endpoint--/personalizer/v1.0/rank",
            new StringContent(JsonSerializer.Serialize(request), Encoding.UTF8, "application/json"));
    
        var result = JsonDocument.Parse(await response.Content.ReadAsStringAsync());
        var topActionId = result.RootElement.GetProperty("rewardActionId").GetString();
    
        return documents.OrderByDescending(d => d.Id == topActionId).ToList();
    }

    Now let’s consider our previous example of search page controller & view and extend it

    Search Controller

    public class AzureSearchPageController : PageController<AzureSearchPage>
    {
        private static string _eventId;
    
        public async Task<ActionResult> Index(AzureSearchPage currentPage, string q = "")
        {
            var results = new List<RankableDocument>();
    
            if (!string.IsNullOrEmpty(q))
            {
                var url = $"https://<search-service>.search.windows.net/indexes/<index-name>/docs?api-version=2021-04-30-Preview&search={q}";
                using var client = new HttpClient();
                client.DefaultRequestHeaders.Add("api-key", "<your-query-key>");
                var response = await client.GetStringAsync(url);
    
                var doc = JsonDocument.Parse(response);
                results = doc.RootElement.GetProperty("value")
                    .EnumerateArray()
                    .Select(x => new RankableDocument
                    {
                        Id = x.GetProperty("id").GetString(),
                        Title = x.GetProperty("name").GetString(),
                        Category = x.GetProperty("type").GetString(),
                        Summary = x.GetProperty("content").GetString()
                    }).ToList();
    
                results = await GetPersonalizedResultsAsync(results, "user123");
            }
    
            ViewBag.Results = results;
            ViewBag.Query = q;
            ViewBag.EventId = _eventId;
            return View(currentPage);
        }
    
        [HttpPost]
        public async Task<ActionResult> Reward(string eventId, double rewardScore)
        {
            using var client = new HttpClient();
            client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", "<your-api-key>");
    
            var rewardUrl = $"<your-endpoint>/personalizer/v1.0/events/{eventId}/reward";
            var result = await client.PostAsync(rewardUrl, new StringContent(rewardScore.ToString(), Encoding.UTF8, "application/json"));
    
            return Json(new { success = result.IsSuccessStatusCode });
        }
    }

    Search Page View

    @model AzureSearchPage
    <h1>Personalized Search Results</h1>
    <form method="get">
        <input type="text" name="q" value="@ViewBag.Query" placeholder="Search..." />
        <button type="submit">Search</button>
    </form>
    
    <ul>
    @foreach (var result in ViewBag.Results as List<RankableDocument>)
    {
        <li>
            <h4>@result.Title</h4>
            <p>@result.Summary</p>
            <button onclick="sendReward('@ViewBag.EventId', 1.0)">Like</button>
            <button onclick="sendReward('@ViewBag.EventId', 0.0)">Not Relevant</button>
        </li>
    }
    </ul>
    <script>
    function sendReward(eventId, score) {
        fetch('/AzureSearchPage/Reward', {
            method: 'POST',
            headers: { 'Content-Type': 'application/json' },
            body: JSON.stringify({ eventId: eventId, rewardScore: score })
        }).then(r => {
            if (r.ok) alert("Thanks! Your feedback was recorded.");
        });
    }
    </script>

    With Azure AI Search delivering relevant results and Azure Personalizer re-ranking them based on real-time context, your Optimizely site becomes an intelligent experience engine.

    This blog has also been published here.

    Source: Read More 

    Facebook Twitter Reddit Email Copy Link
    Previous ArticleAgents bring the role of AI in development from reactive to proactive
    Next Article Android Development Codelab: Mastering Advanced Concepts

    Related Posts

    Security

    Cisco scores a perfect 10 – sadly for a critical flaw in its comms platform

    July 2, 2025
    Security

    Linux Servers Hijacked: Attackers Install Legitimate Proxy Software for Covert Operations

    July 2, 2025
    Leave A Reply Cancel Reply

    For security, use of Google's reCAPTCHA service is required which is subject to the Google Privacy Policy and Terms of Use.

    Continue Reading

    Fix: Windows Calculator Not Showing USD in Currency Converter

    Operating Systems

    CVE-2025-40579 – Siemens SCALANCE LPE9403 Stack-Based Buffer Overflow Vulnerability

    Common Vulnerabilities and Exposures (CVEs)

    Microsoft Sets Passkeys Default for New Accounts; 15 Billion Users Gain Passwordless Support

    Development

    How to Copy Objects in Python

    Development

    Highlights

    CVE-2025-4071 – PHPGurukul COVID19 Testing Management System SQL Injection Vulnerability

    April 29, 2025

    CVE ID : CVE-2025-4071

    Published : April 29, 2025, 4:15 p.m. | 31 minutes ago

    Description : A vulnerability has been found in PHPGurukul COVID19 Testing Management System 1.0 and classified as critical. This vulnerability affects unknown code of the file /test-details.php. The manipulation of the argument Status leads to sql injection. The attack can be initiated remotely. The exploit has been disclosed to the public and may be used.

    Severity: 7.3 | HIGH

    Visit the link for more details, such as CVSS details, affected products, timeline, and more…

    CVE-2024-1243 – Wazuh Agent for Windows UNC Path Manipulation Vulnerability

    June 11, 2025

    30% Faster Travel? Dubai’s AI Plan Is Blowing Minds

    April 24, 2025

    CVE-2025-5209 – Ivory Search WordPress XSS Vulnerability

    June 17, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.