Delen via


SharePoint 2013 Search: Even Better Best Bets with Exact Matching

First, full credit goes to Mikael Svenson and Petter Skodvin-Hvammen for the original solution.  This blog details a small modification to Mikael's "Better Best Bets" blog found here: https://blogs.msdn.com/b/mvpawardprogram/archive/2014/07/21/better-best-bets-with-lists-in-sharepoint-2013.aspx.

Today's blog is a bare-bones, step-by-step process modifying the Better Best Bets solution to do exact matches on keywords.  The "Better Best Bets" solution can only do "contains" matches on keywords since the keyword column type is a taxonomy and has taxIds in the indexed content preventing exact matches.   

From the "Better Best Bets" blog:

If you have multi-word trigger terms, make sure all words are pretty good/unique to avoid unwanted partial matches. Or stick with the out of the box query rule matching with a promoted result instead.

 From <https://blogs.msdn.com/b/mvpawardprogram/archive/2014/07/21/better-best-bets-with-lists-in-sharepoint-2013.aspx>

For example, if you have the Best Bet Keywords "United", "United States" and "Manchester United", the contains operator and the keyword "United" will match all three.  This may be undesired behavior.  Having the ability to use the exact match operator, the Keyword "United" will only match the "United" Best Bet Keyword.

The steps below detail how to use SharePoint lists to manage best bets which will do exact matches on multi-value keywords.  For simplicity, the example below doesn't included the Date properties like the "Better Best Bets" solution, but they can be added and used just like they were previously.

This solutions uses two SharePoint lists.  The first list contains all the keywords.  The second list has a lookup column using the keywords in the first list.  This is required so multi-valued data will be preserved during content processing and the exact match operator will match the multi-valued keywords correctly.

From a non-search site create a List that will be a source for the individual keywords.

  1. Create Site Column for Keyword Source List
    1. Site Settings > Site Columns > Create
      1. Name: ebbbKeywordSource
      2. Type: Single line of text
      3. Put this site column into:
        1. New Group: Even Better Best Bets
      4. Require that this column…: Yes
      5. Enforce unique values: Yes
      6. OK
  2. Create Content Type for Keyword Source List
    1. Site Settings > Site content types > Create
      1. Name: EBBBKeywordSource
      2. Select parent content type…: List Content Types
      3. Parent Content Type: Item
      4. New Group: Even Better Best Bets
      5. OK
    2. Site Content Types > Site Content Type (Even Better Best Bets Keyword Source)
      1. Select Title column
        1. Select Hidden
        2. OK
      2. Add from existing site columns
        1. Select ebbbKeywordSource
        2. Click Add
        3. OK
  3. Create a Custom Keyword Source List
    1. List name: Even Better Best Bets Keyword Source List
    2. Select List (Even Better Best Bets Keyword Source List)
      1. List tab > List Settings
      2. Advanced Settings
        1. Allow management of content types: Yes
        2. Allow items from this list to appear in search results: No
        3. OK
      3. Add from existing site content types
        1. Select EBBBKeywordSource
        2. Click Add
        3. OK
    3. Click Change new button order and default content type
      1. Content Type: Item
        1. Uncheck Visible
      2. Content Type: EvenBetterBestBets
        1. Position from Top: 1
      3. OK
    4. Views > All Items
      1. Title
        1. Uncheck Display
      2. ebbbKeywordSource
        1. Check Display
      3. OK
    5. Enter Keyword values in ebbbKeywordSource column
      1. Click "new item"
        1. Enter a unique word or phrase
        2. Save
      2. Repeat

 

From a non-search site create a List that will reference the Keywords Source List and hold the data used to create the Best Bets.

  1. Create Site Columns
    1. Site Settings > Site Columns > Create
      1. Name: ebbbTitle
      2. Type: Single line of text
      3. Put this site column into:
        1. Existing Group: Even Better Best Bets
      4. Require that this column…: Yes
      5. Enforce unique values: Yes
      6. OK
    2. Site Settings > Site Columns > Create
      1. Name: ebbbURL
      2. Type: Single line of text
      3. Put this site column into:
        1. Existing Group: Even Better Best Bets
      4. Require that this column…: Yes
      5. OK
    3. Site Settings > Site Columns > Create
      1. Name: ebbbKeywordsMatch
      2. Type: Lookup
      3. Put this site column into:
        1. Existing Group: Even Better Best Bets
      4. "Require that this column…": Yes
      5. Get information from: Even Better Best Bets Keyword Source List
      6. In this column: ebbbKeywordSource
        1. Allow multiple values: Yes
  2. Create Content Type
    1. Site Settings > Site content types > Create
      1. Name: EBBBList
      2. Select parent content type…: List Content Types
      3. Parent Content Type: Item
      4. New Group: Even Better Best Bets
      5. OK
    2. Site Content Types > Site Content Type (EBBBList)
      1. Click Title column
        1. Select Hidden
        2. OK
      2. Add from existing site columns
        1. Select ebbbKeywordsMatch, ebbbTitle, ebbbURL
        2. Click Add
        3. OK
  3. Create Best Bets List
    1. List name: Even Better Best Bets List
    2. Create
    3. Select List (Even Better Best Bets List)
      1. List tab > List Settings
      2. Advanced settings > Allow management of content types: Yes
      3. OK
      4. Add from existing site content types
        1. Select EBBBList
        2. Click Add
        3. OK
      5. Click Change new button order and default content type
        1. Content Type: Item
          1. Uncheck Visible
        2. Content Type: EBBBList
          1. Position from Top: 1
      6. Views > All Items
        1. Title
          1. Uncheck Display
        2. ebbbKeywordsMatch, ebbbTitle, ebbbURL
          1. Check Display
        3. OK
  4. Enter data for Even Better Best Bets List
    1. Click "new item"
    2. Add data for ebbbKeywordsMatch, ebbbTitle and ebbbURL
    3. Save
    4. Repeat
  5. SSA Admin > Content Sources > Local SharePoint sites > Full Crawl (or Content Source pointing to your site)
    1. Once crawl has completed, the query spcontenttype:ebbbList will return all items in Even Better Best Bets List
  6. SSA Admin > Search Schema > Crawled Properties (or at the desired Tenant level)
    1. Search for ebbb
    2. For each ows_ebbb* field
      1. Uncheck "Include in full-text index"
  7. SSA Admin > Search Schema > Managed Properties (or at the desired Tenant level)
    1. Verify fields ebb*OWSTEXT exists for Title and URL with Query and Retrieve properties (not Search) with a mapping.
    2. New Managed Property
      1. Name: ebbbKeywords
      2. Type: Text
      3. Check Queryable
      4. Check Retrievable (optional, good for debugging)
      5. Check Allow multiple values
      6. Add a Mapping
        1. Select ows_ebbbKeywordsMatch
        2. OK
      7. OK
  8. SSA Admin > Content Sources > Local SharePoint sites > Full Crawl (or Content Source pointing to your site)
    1. Once crawl has completed, the query ebbbKeywords="<keywords>"spcontenttype:ebbbList will return all items in Even Better Best Bets List that match <keywords>. Supports exact match on multivalues.

 

From the Search Center Site

  1. Create Display Template
    1. Search Center > Site Settings > Master pages and page layouts > Display Templates > Search > Item_BestBets.html > Download a Copy > Save as Item_EvenBetterBestBets.html.
    2. Edit Item_EvenBetterBestBets.html
      1. <title>Even Better Best Bets</title>
      2. <mso:ManagedPropertyMapping msdt:dt="string">'bbTitleOWSTEXT':'bbTitleOWSTEXT','bbURLOWSTEXT':'bbURLOWSTEXT'</mso:ManagedPropertyMapping>
      3. Save
    3. Display Templates > File Tab > Upload Document
      1. Select file
      2. OK
      3. Save
  2. Create Result Type
    1. Search Center > Site Settings > Site Collection Administration > Search Result Types > New Result Type
      1. Name: Even Better Best Bets
      2. Show more conditions
        1. Which custom properties should match: Content Type
        2. (Value): EBBBList
      3. What should these results look like: Even Better Best Bet Item
      4. Check Optimize for frequent use
      5. Save
  3. Create Result Source
    1. Search Center > Site Settings > Site Collection Administration > Search Result Sources > New Result Source
      1. Name: Even Better Best Bets
      2. Query Transform: ebbbKeywords="{searchTerms}" spcontenttype=ebbblist
      3. Save
  4. Create Query Rule
    1. Search Center > Site Settings > Site Collection Administration > Search Query Rules
      1. Select "Local SharePoint Results" > New Query Rule
        1. Rule Name: Even Better Best Bets
        2. Remove Condition
        3. Add Result Block
          1. Title: Best Bets for "{subject Terms}"
          2. Search this Source: Even Better Best Bets
          3. Items: 5
          4. Click Settings
            1. Select This block is always shown above core results
          5. OK
        4. Change ranked results by changing the query (hide best bets content and list AllItems.aspx from "default" search results).
          1. Query Text: {searchTerms} -spcontenttype:ebbblist -ListURL:"Even Better Best Bets List"
          2. OK
        5. Save
  5. Test Best Bets from Search Box

Comments

  • Anonymous
    February 01, 2016
    Hi Eric! Thank you for your interesting post. I've tried to set up hte solution and I've almost succeded, but have one challenge which I hope you can help me with. In my source list I have entries containing one word or multiple words - for example "sourcelist" and "source list". The problem is that only queries matching the entries with muktiple words triggers the best bet query rule - not single word entries. So "source list" works but "sourcelist" doesn't. Any suggestions?

  • Anonymous
    February 02, 2016
    Sorry.  Nothing specific jumps to mind.  The scenario you describe works for me.  I know that doesn't help you.  :( I'd review the steps and make sure your lists are indexed correctly and your data is formatted correctly, You can use the SharePoint 2013 Search Query Tool to easily see the custom Managed Property data.  Your query will look something like 'ebbbKeywords="<keywords>" spcontenttype:ebbbList'.  Make sure Query Rules are turned OFF for your tests or you wont see results.  You should see your multi-value terms delimited by a semi-colon in the results.  

  • Anonymous
    February 08, 2016
    Thank you for answer. I've tried the Search Query Tool which confirms my observations. Furthermore I've found out that 'ebbbKeywords:"sourcelist"' works (":" instead of "=") so the single word entry is indexed and queryable but it doesn't work as an exact match.

  • Anonymous
    February 25, 2016
    Hi Peter, if ':' works, but '=' doesn't, you are probably using the wrong Column and/or List Content Types in your SP lists.  The point of the exercise above it to be able to use the '=' or exact match operator because the ':' or contains operator, while it will work, leads to ambiguity in certain scenarios.  Other content types will add metadata (e.g. taxonomical data) to the column value, so only ':' will work.

  • Anonymous
    February 06, 2017
    Hi Eric,We've been using this solution for about 6 months now and it's worked really well. Ideally we'd like to expand it so that it could cover queries starting and ending with other phrases. For instance, our defined phrase is "harassment policy" and we'd like that to also match English discrimination & harassment policy. Is there any way to do that? In other words, we'd like to still cover our multi-word trigger terms like this solution allows us to do, but also accept if the user has appended other words to the query.Thanks!

    • Anonymous
      February 27, 2017
      Hi Bryn, I believe you could, but please thoroughly test. I haven't tested this out.First, you need to do a "contains" match on the key words list, but this reintroduces the problem that the solution is trying to solve (see the "United”, “United States” and “Manchester United" example above). The original Better Best Bet addresses your scenario. So, I would create a second list of terms that you know are unique and/or are phrases and repeat the process defined in the original solution or what is stated above for the second list, except for step 3.a.ii under the "From the Search Center Site" section. In that step, change the operator from an equals (=) to a colon (:).