Wednesday, December 23, 2015

SharePoint 2013: how to build a basic search-driven list


This procedure walks through the steps for building a basic search-driven listing.  The specific case presented here involves a need to present in one site collection a filtered view of a listing in another site collection.  The listing is a service ticket listing, and the filtered view will show only those list rows (i.e., tickets) having specific values for the row's Admin Category and SD Status columns, both of which are type Choice.  The approach presented here involves first building a new search result source, and then configuring a a search results web part to use this result source.



  1. Obtain the target list URL
    1. Navigate to the target list.
    2. Copy the list URL, but leave out the page that will be a part of this URL.  For example, if the URL is ...[MyWebsite]/Lists/[MyList]/MyView.aspx, leave off the MyView.aspx.
  2. Identify the target list columns and their search property mappings
    1. Navigate to the target list.
    2. Note down the names of the columns that you want to filter by.
      In this case, both columns are Choice columns.  That's a good thing because the Search service automatically creates managed properties for these column types.  You need to have managed properties so that you can filter on these properties when you configure the result source.  Having them created automatically by Search means less work for you to go in and create them yourself.
    3. Now go to Central Administration: CA > Search Administration > Search Schema.  The Search Service: Managed Properties page is presented.
    4. In the Managed property Filter box, enter the name of a property and perform a search for this property.  Look in the Property Name column.  You'll find the column name without any spaces between the property names, and this will be concatenated to some other characters.  For example, a Choice column type named Admin Category would then be indexed as AdminCategoryOWSCHCS.  Note the formulation of this property name: you'll see this again and again.  The SD Status column would then be indexed as SDStatusOWSCHCS.  Finding it verifies that Search has found the list column and has automatically created a managed property for it.  That's all you need to do.  Repeat for each other column that you want to filter by.
      Note: if the column is one of these types: Lookup, Calculated, Task outcome, Summary Links data, or Rich media data for publishing, Search will not automatically create a managed property for it and you will need to do this yourself.  Creating a managed property is outside the scope of this procedure.  However, plenty of guidance is offered in the references listed below.
  3. Create a new result source
    1. Navigate to the site collection, in which you want to build the search-drive list.
    2. Go: Settings > Site Settings > Site Collection Administration > Search Result Sources.
    3. Click New Result Source.
    4. Add a name, and then click the Launch Query Builder button.  The Build Your Query popup appears.

      Looking in the Query text box, you only see this:
    5. From the Property filter dropdown, select Path.
    6. Immediately below this dropdown, you'll see two other dropdowns.  The first one has "Contains" selected and the second has "Select value" selected by default. From the second dropdown, select Manual value.  A new text box appears immediately below it.
    7. Into this textbox, paste the URL you copied previously, and then click the Add property filter button.
      Looking in the Query text box, you now see this:
      {searchTerms} Path:http://[MyWebsite]/Lists/[MyList]/
    8. From the Property filter dropdown, select --Show all managed properties--.  This expands the dropdown.  You'll now see listed all of the managed properties.
    9. Scroll through this list until you find the managed list column property.  For example, I would look for AdminCategoryOWSCHCS.  Select this.
    10. Now, make sure that the first dropdown underneath this displays Contains.  From the second dropdown, select Manual value.  When you do that, a textbox will appear underneath this.  Into this text box, enter the appropriate column value. In my case, i wanted to find tickets categorized as Website Update.
    11. Once you enter the appropriate text, click the Add property filter button to update the Query text box.  You'll now see this:
      {searchTerms} Path:http://[MyWebsite]/Lists/[MyList]/ AdminCategoryOWSCHCS:Website update 
    12. Repeat for the next list column that you want to filter on.  For my case, I wanted to filter on the SD Status column, for those tickets having status Engaged.  Adding that property value to the query obtains this:
      {searchTerms} Path:http://[MyWebsite]/Lists/[MyList]/ AdminCategoryOWSCHCS:Website update SDStatusOWSCHCS:Engaged
    13. Click the Test query button to see the results displayed in the Query Builder popup.
    14. Now click OK.  This closes the Query Builder.
    15. Click Save.  This adds the new result source to the list of managed result sources.  Since this result source was created in a site collection, it will only be visible to web parts used on website pages within that site collection.
  4. Add and configure the Search
    1. Navigate to the page on which you want to present the filtered list view.
    2. Click on the gear icon (Settings), and then select Site Settings.
    3. On the page, click on the Add a Web Part link for the desired zone.
    4. On the Categories group, in the ribbon, select Search, then select Search Results from the Parts group, and then click the Add button.  An instance of the Search Results web part appears on the page.
      Don't worry about the extra text that you see in the web part: this appears only while in edit mode. Once you save the page and go back to view mode, this extra text no longer appears.
    5. On the Search Results web part, look on the title bar and you will see a small down arrow. Click this arrow, and then select Edit Web Part.
    6. Now look for the Properties for Search Results configuration box.  On this box, click the Change query button.
    7. On the BASICS tab, look for the Select a query section and the dropdown in this section.  It might have Local SharePoint Results already selected.  Open this dropdown and note all of the result sources that are listed.
      Result sources created at the farm level will have "(service)" next to their names.  Result sources created at the site collection level will have "(site collection)" next to their names.
    8. From this dropdown, select the result source that you created previously.  There is nothing more that needs to be done here as the result source is already configured to retrieve the list items that you want.
    9. Click the Test query button, lower down, and then wait a few seconds.  The desired items will appear in the SEARCH RESULTS PREVIEW pane.
    10. Click OK.  You now have a basic search-driven listing.  


  • Don't confuse "level" here with the scope of the search index that is available for querying. "Level" as used here only involves the visibility of the result source; not the scope of the result source.  For example, a result source created at the site collection level will only be visible to web parts added to website pages within that site collection.  It would not be visible to a web part on a website page in a different site collection.  If you want to make result sources visible to web parts on website pages in all site collections, you must create the result source directly through the search service application itself, which means at the farm level.
  • You don't need to specifically map the list properties (AKA Columns) that are crawled. As noted in Overview of the search schema in SharePoint Server 2013: Managed properties and property mapping,
    Some crawled property types automatically generate a new managed property and a mapping between the crawled and managed property. For example, all site columns from SharePoint libraries have this automatic generation and mapping. When you create a site column in a list, and you crawl that list, a crawled property, a managed property, and a mapping between the crawled and managed property is automatically created for the site column
    Well, not all.  Lookup columns, for example, do not automatically have managed properties created for them.
  • This listing is only as current as the crawl interval.
  • To modify the way in which the results are presented, you will need to create a customized display template.

No comments: