-->

14/03/2017

SharePoint Online Search Basics

          If you are a SharePoint 2010 Developer and trying to figure out how search works in Sharepoint Online, this is for you. As i am one of you and like i said in my first post on my blog, the content is not to show what i know, but to share what i have learned.

         We will refer to 2010 concepts like "Managed Properties", "Content Sources", "Search Scopes", "Search Result webparts" and see how we going to achieve the same results in Sharepoint online.

        Before you jump into solutions / development, you should know how things were changed from SP2010 to SP Online. You (Admin) used to manage everything in Sharepoint On-Premises from Central Admin, but not in SP Online. Below image will depict what will be your responsibility as a Global administrator of your tenant.

        Looking at the Admin portal of your tenant, you may figure out that you cannot do everything you can do in SP2010 Central Admin.


       As far as search is concerned below are the changes. Please note that we will not be going through every new aspect of search in SP Online. We look at things to learn on day one to display results from a set of site collections and avoid unwanted files like (.aspx) in search results.

  •        No more content sources, as you cannot control the frequency of crawls.
  •        No more Search scopes
  •        Managed properties and Crawl properties are now listed under Search Schema.
  •        Result sources is now combination of Content sources and Search Scopes.
      Enough of theory, lets jump into implementation. My objective is to create a search page where i can search for documents from a set of site collections.

Step 1: Create "Search Result Source".
                    Go to your admin site. "https://tenantname-admin.sharepoint.com". Click on searchon left pane. You will see a bunch of options with nice description.


        Click on Manage Result sources. Click "New Result source" on top of the page. A new page will be opened where

  • you give the name of the "Result Source". 
  • Select protocol as "Local Results" which means from your tenant. 
  • Select credentials as default authentication as if you want results to be security trimmed.
  • Select credentials as specific account if you want to show same results to everyone and bypass scurity trimming. 

       Now comes most important part: Query transform, which defines what need to be fetched for this specific result source. Click the Query Builder to launch the window which does 90% of the work for us.
       I have 2 site collections from which results should be fetched. Results should omit .aspx files, Site or Library urls. I want only documents. Below is the sample of how its done. Using all the Keyword Filters and property filters, i have created a perfect query string for my result source.
The results will be instantly shown on the right hand pane.



      Let me explain my Query text in brief.
{searchTerms} FileExtension<>.aspx   
(Path:"https://1yearsub.sharepoint.com/sites/MCFArchive01" OR
 Path:"https://1yearsub.sharepoint.com/sites/MCFArchive02")  
(contentclass:STS_ListItem OR IsDocument:True)

{searchTerm} - This part will be replaced by the text from search box when you use it on search page.
Next part signifies to omit any site pages from results.
Path -  This is where we mention from which site collections , results should be fetched.
Last line - says just get me Documents and items as results thus avoiding the site and Library urls as results.

You can even replace {searchTerms} with s standard search term and test the out comes immediately as shown below. You can see that no of results were changed by using the search term "Sharepoint" instead of "{searchTerms}".

         Sorting tab will give you provision where you can set a default sort order based on various managed properties. Test tab will allow just to run your query text against various keywords, but it wont support Keyword filter or Property filter modifications. Save all the changes done on Query builder and also the edit Result source page.
         With this we are done with configuring our result source.

Step 2: Create a Search page
           First we need to enable the publishing infrastructure (both site coll feature and site feature) to get pages library. I want publishing to be enabled as i don't want any one to see pages which were in progress before i publish.
          When you click create page, now you will be presented various page layouts to create a page and i choose "Search Results" page layout.  when you are done, you see a search page.
          In current stage, this search page will retrieve all the results from current tenant. But that's not what we want.

Step 3: Modify search results webpart
Go to properties window and click on "Change Query" button. A popup will be opened similar to Query builder. Here all you need to do is to select the pre-created  result source which has all the information of what documents we want to see in results. You still get filters to use , if you have any specific rules as per current search page.
       There are so many other options in properties window, like below:

  • Display templates - Custom templates to display results (which is specific topic by itself, so later)
  • Settings - Decide how many results to be displayed at once.
  • Layout - Where on page should the results webpart be displayed. 
  • Advanced - Generic stuff like Allow minimize, Allow move etc.,

      Now save the webpart changes and save the page and we got the final result.


 Step 4: Some basic observations / Tips

  • When you rename your Result source in Search Admin, it will be automatically reflected in webparts. You don't need to go and modify all the webparts using that results source.
  •  You cannot control the crawl frequency in SP Online, so know that Incremental crawl will happen at tenant level.
  •  If you add a new Managed property , a full crawl is required in Sharepoint 2010 to make use of it in results display. In SP Online since there is no full crawl, you need to re-index the respective list by going into its "Library Settings" => "Advanced Settings" => "Re-Index List" button.
  •  Please note that it will take more than 24 Hours for a new Managed property to start picking up values and display in results. So plan your deployments accordingly.
  • As there are no search scopes in SP Online, most of the webparts from SP2010 will not work as expected when you migrate.
  • Please note that there is no Continues crawl unlike SP2013 or SP2016. Incremental crawl will be done at tenant level and it might take a wahile to see the newly uploaded docs in search results.

   Advanced search topics like Display templates, Query Suggestions,  Query Rules , Results Promotion etc will be posted next. Display templates were discussed in my next post "Tabular Custom Search Display"

No comments:

Post a Comment