Tuesday, March 3, 2015

Setting custom scope in Advanced Search Web part and metadata property on Created Date of items in SharePoint 2010.

Some days back I have written about how to hide unnecessary links from a Advance Search Web part. Here I am adding some more points to make this search more user friendly and usable with minor tweaks.

Very first one is related to narrow down the scope of our search Web part. By default an advanced  search web part search for the whole Content source. We can not limit the scope of a Content source to a particular list or library. To get this we need to create scopes in SharePoint. While creating a scope if you want to narrow it down to a list level, then you need to put the URL of the list refer below:


Add Url in the marked way, press OK and rule will be added to your scope.

Now we need to add this scope into our Advanced Search web part to narrow down the scope. For achieving  this we need to modify the XML for it. Top open the XML we need to edit the web part and click on area marked with arrow :

Once you click it will open the customized XML you are using for it. Below is the by default XML after adding your managed properties which you want to add on it.

<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">  <PropertyDefs>    <PropertyDef Name="Path" DataType="text" DisplayName="URL"/>    <PropertyDef Name="Size" DataType="integer" DisplayName="Size (bytes)"/>    <PropertyDef Name="Write" DataType="datetime" DisplayName="Last Modified Date"/>    <PropertyDef Name="FileName" DataType="text" DisplayName="Name"/>    <PropertyDef Name="Description" DataType="text" DisplayName="Description"/>    <PropertyDef Name="Title" DataType="text" DisplayName="Title"/>    <PropertyDef Name="Author" DataType="text" DisplayName="Author"/>    <PropertyDef Name="DocSubject" DataType="text" DisplayName="Subject"/>    <PropertyDef Name="DocKeywords" DataType="text" DisplayName="Keywords"/>    <PropertyDef Name="DocComments" DataType="text" DisplayName="Comments"/>    <PropertyDef Name="CNACreatedDate" DataType="datetime" DisplayName="Created Date"/>    <PropertyDef Name="CNAClientName" DataType="text" DisplayName="Client Name"/>    <PropertyDef Name="CNAClientNumber" DataType="text" DisplayName="Client Number"/>    <PropertyDef Name="CNACountry" DataType="text" DisplayName="Country"/>    <PropertyDef Name="CNACurrency" DataType="text" DisplayName="Currency"/>    <PropertyDef Name="CNAEMLTMSref" DataType="text" DisplayName="EML or TMS Ref "/>    <PropertyDef Name="CNAGBPEquivalent" DataType="text" DisplayName="GBP Equivalent"/>    <PropertyDef Name="CNAIPType" DataType="text" DisplayName="IP Type"/>    <PropertyDef Name="CNAManualCredit" DataType="text" DisplayName="Manual Credit"/>    <PropertyDef Name="CNAProjectReference" DataType="text" DisplayName="Project Reference"/>    <PropertyDef Name="CNARequestor" DataType="text" DisplayName="Requestor"/>    <PropertyDef Name="CNAStatus" DataType="text" DisplayName="Status"/>    <PropertyDef Name="CNATeam" DataType="text" DisplayName="Team"/>  </PropertyDefs>  <ResultTypes>    <ResultType DisplayName="Credit Note Approval" Name="Credit Note Approval">      <KeywordQuery />      <PropertyRef Name="CNACreatedDate" />      <PropertyRef Name="CNAClientName" />      <PropertyRef Name="CNAClientNumber" />      <PropertyRef Name="CNACountry" />      <PropertyRef Name="CNACurrency" />      <PropertyRef Name="CNAEMLTMSref" />      <PropertyRef Name="CNAGBPEquivalent" />      <PropertyRef Name="CNAIPType" />      <PropertyRef Name="CNAManualCredit" />      <PropertyRef Name="CNAProjectReference" />      <PropertyRef Name="CNARequestor" />      <PropertyRef Name="CNAStatus" />      <PropertyRef Name="CNATeam" />    </ResultType>  </ResultTypes></root>

In the above you just need to find the bold text and replace it with below text:

<KeywordQuery>Scope:"Your Scope Name"</KeywordQuery>

It will set search scope to only particular URl which we have added in our Scope Rule URL at that time.

Now we will talk about second part of this blog related to search on Created Date of list items. Its about finding the right crawled property to map it with our created date. For the List Items its always indexed in crawled property Basic:15(Date and Time):

For Author or Created By in a list:

 Hope it helps someone.

No comments:

Post a Comment