JoelBlogs - Joel Jeffery's Microsoft 365 Blog

Microsoft 365, SharePoint, Teams and Office 365 Architecture, Development, Administration and Training

  • Home
    • Sitemap
  • Articles
    • #SPThingADay
    • SharePoint Online
      • SharePoint Online – Drag and Drop and Large File Uploads
    • SharePoint 2016
    • SharePoint 2013
      • Content Database Changes to the AllUserData Table
    • SharePoint 2010
      • Administration
        • Disable CRL Checking
        • Excel 2010 & PowerPivot
        • Limits & Thresholds
        • PeoplePicker AD Errors
        • Recycle Bin Behaviour
        • Renaming a Server
        • Service Pack 1
        • Unattended Installs
        • Uninstall All SharePoint 2010 Solutions via PowerShell
        • User Alert Management
        • Virtualised SharePoint
        • Visio Stencils for Administrators
      • Development
        • Audience Membership Workflow Activity
        • Base Types, Lists & Content Types
        • BCS & Offline Sync
        • Debugger Skipping Lines
        • Development Laptop Spec
        • Enabling JavaScript IntelliSense
        • Event Receivers & Deployment Jobs
        • FavIcons & SPUrl
        • Google Maps Sandbox Web Part
        • Group By Content Type for List Views
        • Locale Stapler / Master or Default Locale
        • Removing Default Editor Parts
        • Sandbox Embedding Resources
        • Solution Sandbox Introduction
        • SPPersistedObject
        • Restoring Deleted SPSites in SP1
        • SPWebConfigModification 1
        • SPWebConfigModification 2
        • STSADM copyappbincontent vs. Install-SPApplicationContent
        • Workflows for Beginners
        • Workflow InitiationData Seralizer
    • SharePoint 2007
      • Alternate Access Mappings
      • Excel Services
      • Excel Services UDFs & Excel Client 2007
      • Experiences from the Field
      • InfoPath & Forms Server
      • Kerberos & SSRS
      • Records Management
      • Web Application Service
      • WSS vs MOSS
  • Training
    • SharePoint Admin Links
  • Downloads
    • Summary Slides for PowerPoint
    • CodePlex Projects
      • Audience Membership Workflow Activity
      • Google Maps Sandbox Web Part
      • Group By Content Type in List Views
      • Locale Stapler / Master or Default Locale
      • SharePoint Outlook Connector
  • Hire Me!
    • MCP Transcript
    • Résumé/CV

Audience Targeted Searches in Modern SharePoint Online

December 8, 2019 by Joel Jeffery

Did you know that you can use SharePoint search query language to bring back audience targeted content?

So, you’ve implemented Audience Targeting in your Modern SharePoint Libraries.

As a recap, you can do this by going to Library Settings -> Audience targeting settings:

Audience Targeted Searches in Modern SharePoint Online

And then check the box to “Enable audience targeting”:

Now you’ve enabled audience targeting, you can use SharePoint search query language to bring back audience targeted content.

For example, a search for all published news pages can be accomplished with the following KQL query:

PromotedState:2

To augment this to include only audience targeted new pages, try this:

(PromotedState:2 AND ModernAudienceAadObjectIds:{User.Audiences})

And to also include pages that are not targeted at all:

(PromotedState:2 AND (ModernAudienceAadObjectIds:{User.Audiences} OR NOT IsAudienceTargeted:true))

You can use this trick from search boxes:

And of course you can also use it from custom code (including projects like the excellent Modern Search Web Part on GitHub).

The Highlighted Content Web Part has this functionality built in:

Happy audience targeting!

Filed Under: SharePoint Online Tagged With: Audience Targeting, Modern Pages, Search, SharePoint Online

Automatically Generating Thesaurus Files from Taxonomy for SharePoint Search

July 4, 2012 by Joel Jeffery

A while ago, a student of mine asked if it was possible to use the taxonomic alternative labels from the Managed Metadata Service as thesaurus items in SharePoint Server Search.

There’s no built-in way to do this, but it is possible to generate the required Xml with a little PowerShell.

The Concept

The Term Store contains Term Group, which content Term Sets, which in turn contain nested Terms. Each Term can have (optional) synonyms called Labels.

If we find all the Terms with Labels, we can write them out in the correct format as a chunk of Xml, and pipe it into a thesaurus file.

Thesaurus files for SharePoint Server Search are kept under the file path:

%ProgramFiles%\Microsoft Office Servers\14.0\Data\Office Server\Applications\GUID-query-0\Config

A sample thesaurus file is shown below:

<XML ID="Microsoft Search Thesaurus">
    <thesaurus xmlns="x-schema:tsSchema.xml">
        <diacritics_sensitive>0</diacritics_sensitive>
        <expansion>
            <sub>Internet Explorer</sub>
            <sub>IE</sub>
            <sub>IE8</sub>
        </expansion>
        <replacement>
            <pat>NT5</pat>
            <pat>W2K</pat>
            <sub>Windows 2000</sub>
        </replacement>
    </thesaurus>
</XML>

You can see the rationale for how this file works on and how to manage thesaurus files at TechNet.

The Script

The script below shows the principle. It iterates over the Terms in each Term Store and finds their Labels. Where the Label is not the same as the name of the Term itself, it represents a synonym and we add it to the Xml.

function Extract-SPThesaurusFromTermLabels
{
  param([string] $webUrl);
  $ts = Get-SPTaxonomySession -Site $webUrl;
  Write-Output "<XML ID='Microsoft Search Thesaurus'>"; 
  Write-Output "<thesaurus xmlns='x-schema:tsSchema.xml'>"; 
  $ts.TermStores | 
  % { $_.Groups | 
    % { $_.TermSets | 
      % { $_.Terms | 
        % { $_.Labels | 
          ? {$_.Term.Name -ne $_.Value} |
          % { 
            Write-Output ("<expansion><sub>" + $_.Term.Name + 
              "</sub><sub>" + $_.Value + "</sub><expansion>");
          } 
        } 
      } 
    } 
  }; 
  Write-Output "</thesaurus>"; 
  Write-Output "</XML>";
}

You can then pipe the output of this command to an Xml file, and optionally use this in the place of your existing Thesaurus file with something like this:

Extract-SPThesaurusFromTermLabels http://sharepoint > tsLANG.xml

As always, please back up your original Thesaurus files and check the output of this before you use it! Smile

Filed Under: SharePoint 2010 Tagged With: PowerShell, Search, SharePoint, SharePoint 2010, SharePoint Administration, SharePoint Administrator

Next Page »

Joel is a full-stack cloud architect who codes. He is a Microsoft Certified SharePoint Online, SharePoint Server and Azure specialist and Microsoft Certified Trainer.
He has over 20 years' experience with SharePoint and the Microsoft .NET Framework.
He's also co-founder of Microsoft Gold Partner JFDI Consulting Ltd. Read More…

Recent Posts

  • Microsoft Flow Tip #1 – Word Templates and Hiding Empty Repeating Sections
  • SharePoint PowerShell Tip #1 – Select-Object and FieldValues
  • Popular Misconceptions – Microsoft Teams relationship with SharePoint
  • Course: Microsoft 365 Certified Teamwork Administrator
  • Audience Targeted Searches in Modern SharePoint Online
MCT 2020-2021
Microsoft Teamwork Administrator Associate
Joel's Acclaim Profile
Joel's Microsoft Profile

Tags

Administration Architecture Certification Cloud Development freetraining Information Architecture intranets MCP Microsoft Microsoft Architecture Microsoft Azure microsoftsharepoint migration Mobile Development MOSS Office 365 office365 Office 365 Permissions PowerShell SaaS SharePoint SharePoint 2010 SharePoint 2010 Training SharePoint 2013 SharePoint Administration SharePoint Administrator SharePoint Architecture SharePoint Developer SharePoint Development sharepointia SharePoint Online sharepointonline SharePoint Search SharePoint Training SharePoint Videos Silverlight SOA SPThingADay TechEd 2007 Training Videos Windows Phone 7 WSS

Copyright © 2022 Joel Jeffery, SharePoint Architect