Wednesday, 19 November 2014

How to retrieve the crawl log values from Search Service application in SharePoint 2010



In this article we will be seeing how to retrieve the crawl log values for a content source from search service application in SharePoint 2010.

If you go to Central Administration => Application Management => Manage service applications => Search Service Application => Crawling => Crawl Log you could see all the content sources.

image1.gif

C# code:

  • Open Visual Studio 2010.
  • Go to File => New => Project.
  • Select Console Application from the installed templates.
  • Enter the Name and click Ok.
  • Add the following references.

    o Microsoft.SharePoint.dll
    o Microsoft.Office.Server.dll
    o Microsoft.Office.Server.Search.dll
     
  • Add the following namespaces.

    o using Microsoft.Office.Server.Search.Administration;
    o using Microsoft.Office.Server;
    o using Microsoft.SharePoint;
     
  • Replace the code with the following.

    //  search service application name   
                string ssaName ="Search Service Application";
                SearchContext context =SearchContext.GetContext(ssaName);
    Content ssaContent = new Content(context);
                ContentSourceCollection ssaContentSources = ssaContent.ContentSources;
                   ContentSource cs = ssaContentSources["Local SharePoint Sites"];
                  Console.WriteLine("Successes: " + cs.SuccessCount.ToString());
                Console.WriteLine("Warnings: " + cs.WarningCount.ToString());
                Console.WriteLine("Errors: "+cs.ErrorCount.ToString());
                Console.WriteLine("TopLevelErrors: " + cs.LevelHighErrorCount.ToString());
                Console.WriteLine("Deletes: " + cs.DeleteCount.ToString());         
                Console.ReadLine();

     
  • Build the solution.
  • Hit F5.

    image2.gif


Reference:

http://www.c-sharpcorner.com/uploadfile/anavijai/how-to-retrieve-the-crawl-log-values-from-search-service-application-in-sharepoint-2010/

How to retrieve the crawl log values from Search Service application in SharePoint 2010



In this article we will be seeing how to check the crawl status values for content sources in SharePoint 2010.

If you go to Central Administration => Application Management => Manage service applications => Search Service Application => Crawling => Content Sources you could see all the content sources.

1.gif

To check the crawl status values for a content source

  • Open Visual Studio 2010.
  • Go to File => New => Project.
  • Select Console Application from the installed templates.
  • Enter the Name and click Ok.
  • Add the following references.

    o Microsoft.SharePoint.dll
    o Microsoft.Office.Server.dll
    o Microsoft.Office.Server.Search.dll
     
  • Add the following namespaces.

    o using Microsoft.Office.Server.Search.Administration;
    o using Microsoft.Office.Server;
    o using Microsoft.SharePoint;
     
  • Replace the code with the following.

    //  search service application name   
                string ssaName ="Search Service Application";
                SearchContext context =SearchContext.GetContext(ssaName);
    Content ssaContent = new Content(context);
                ContentSourceCollection ssaContentSources = ssaContent.ContentSources;
                   ContentSource cs = ssaContentSources["Local SharePoint Sites"];
                Console.WriteLine(cs.CrawlCompleted.ToString());
                Console.WriteLine(cs.CrawlStarted.ToString());
                Console.WriteLine(cs.CrawlStatus);
                Console.WriteLine(cs.CrawlPriority);


     
  • Build the solution.
  • Hit F5.

    2.gif
     


Reference:

http://www.c-sharpcorner.com/uploadfile/anavijai/how-to-retrieve-the-crawl-log-values-from-search-service-application-in-sharepoint-2010/

SharePoint 2010 - Create Crawl Schedule


In this article we explore how to create a Crawl Schedule for the Search.

The following are the steps involved:

1. Open Central Administration web site as shown below:

CrwlShr1.jpg

2. Click on the Manage service applications link as highlighted above:

CrwlShr2.jpg

3. Click on the Search Service Application as highlighted above:

CrwlShr3.jpg

4. Click on the Content Sources link as highlighted above:

CrwlShr4.jpg

5. Click on the Local SharePoint sites cell and in the page on the right side you will see the Crawl Schedules.

CrwlShr5.jpg

You will see two items: Full Crawl and Incremental Crawl

Full Crawl

To start with we have to use a Full Crawl. This will be time-consuming and provides the starting point for the Incremental Crawls. A Full Crawl replaces all existing crawl contents regardless of whether they have changed or not.

Incremental Crawl

These are faster crawls as they crawl only modified crawls. A Full Crawl has to be performed previously to do the Incremental Crawl.

6. Use the Create Schedule link to create a new Crawl Schedule:

CrwlShr6.jpg

7. Enter the details in the dialog that appears and click the OK button:

CrwlShr7.jpg

8. Click the OK button on the page:

CrwlShr8.jpg

You will see that the site is reflected with the new Crawl Schedule:

CrwlShr9.jpg

References

http://social.technet.microsoft.com/wiki/contents/articles/full-and-incremental-crawls-in-microsoft-office-sharepoint-server-2007-search.aspx

Summary

In this article we have seen how to create a Crawl Schedule.


Reference:

http://www.c-sharpcorner.com/UploadFile/40e97e/sharepoint-2010-create-crawl-schedule/

How to check the crawl status values for a Content Sources in SharePoint 2010



In this article we will be seeing how to check the crawl status values for content sources in SharePoint 2010.

If you go to Central Administration => Application Management => Manage service applications => Search Service Application => Crawling => Content Sources you could see all the content sources.

1.gif

To check the crawl status values for a content source

  • Open Visual Studio 2010.
  • Go to File => New => Project.
  • Select Console Application from the installed templates.
  • Enter the Name and click Ok.
  • Add the following references.

    o Microsoft.SharePoint.dll
    o Microsoft.Office.Server.dll
    o Microsoft.Office.Server.Search.dll
     
  • Add the following namespaces.

    o using Microsoft.Office.Server.Search.Administration;
    o using Microsoft.Office.Server;
    o using Microsoft.SharePoint;
     
  • Replace the code with the following.

    //  search service application name   
                string ssaName ="Search Service Application";
                SearchContext context =SearchContext.GetContext(ssaName);
    Content ssaContent = new Content(context);
                ContentSourceCollection ssaContentSources = ssaContent.ContentSources;
                   ContentSource cs = ssaContentSources["Local SharePoint Sites"];
                Console.WriteLine(cs.CrawlCompleted.ToString());
                Console.WriteLine(cs.CrawlStarted.ToString());
                Console.WriteLine(cs.CrawlStatus);
                Console.WriteLine(cs.CrawlPriority);


     
  • Build the solution.
  • Hit F5.

    2.gif
     


Reference:

http://www.c-sharpcorner.com/uploadfile/anavijai/how-to-check-the-crawl-status-values-for-a-content-sources-in-sharepoint-2010/

Create Content Sources in SharePoint 2010 using PowerShell



In this article we will be seeing how to create Content Sources for Enterprise Search Service Application in SharePoint 2010 using PowerShell.

Automating the Content Source creation in SharePoint 2010

A content source is used to specify what type of content is crawled, what URLs to crawl, how and when to crawl.

We can create Content Sources for Enterprise Search Service Application in SharePoint 2010 from Central Administration.

Go to Central Administration => Application Management => Manage Service Applications => Enterprise Search Service Application.

Create Content Sources in SharePoint 2010 using PowerShell

On the Quick Launch Menu, go to Crawling and then click on Content Sources.

Create Content Sources in SharePoint 2010 using PowerShell

You could be able to see the Content Sources. By clicking on New Content Source link we can create a new Content Source.

Another way is we can create the content sources for Search Service Application using SharePoint Object Model.

Here we will be seeing about automating the content source creation using powershell script.

Steps Involved:

  1. Create the input XML file which contains the inputs for content source creation.
  2. Create ps1 file which contains the script for content source creation.
CreateContentSources.xml

<?xml version="1.0" encoding="utf-8" ?>
<ContentSources>
  <
SSAName>EnterPrise Search Service Application</SSAName>
  <ContentSource Name="Sample1 SharePoint Sites" />
  <ContentSource Name="Sample2 SharePoint Sites" />
  <ContentSource Name="Sample3 SharePoint Sites" />
</ContentSources>

CreateContentSources.ps1

 #----------------Get the xml file---------------------------------------------------------------
 [xml]$xmlData=Get-Content "C:\Users\Desktop\ContentSources\CreateContentSources.xml"
 #----------------Create New Content Source function---------------------------------------------
 function CreateNewContentSource
 {
       
$flag=0
       
$ssa=Get-SPEnterPriseSearchServiceApplication -Identity $xmlData.SSAName
       
$ssaContent = new-object Microsoft.Office.Server.Search.Administration.Content($ssa)
       
$xmlData.ContentSources.ContentSource | ForEach-Object {
             
$contentSourceName=$_.Name
             
foreach ($availableContentSource in $ssaContent.ContentSources)
             {
                 
if ($availablecontentSource.Name.ToString() -eq $contentSourceName)
                  {
                         
write-host -f Yellow $contentSourceName "content source already exists"
                    
write-host -f Yellow Deleting $contentSourceName content source                   
                    
$availablecontentSource.Delete()
                    
write-host -f Green $contentSourceName content source is deleted successfully
                     write-host -f yellow Creating $contentSourceName 
                    
$ssaContent.ContentSources.Create([Microsoft.Office.Server.Search.Administration.SharePointContentSource], $contentSourceName)
                    
write-host -f green $contentSourceName  "content source is added successfully"
                     $Flag=1
                    
break
                  }
             }
             
if($Flag -eq 0)
             {
                   
write-host -f yellow Creating $contentSourceName 
                   
$ssaContent.ContentSources.Create([Microsoft.Office.Server.Search.Administration.SharePointContentSource], $contentSourceName)
                   
write-host -f green $contentSourceName  "content source is added successfully"
             }
       }
 }
 #----------------Calling the function---------------------------------------------
CreateNewContentSource


Run the Script:

  1. Go to Start.
  2. Click on All Programs.
  3. Click on Microsoft SharePoint 2010 Products and then click on SharePoint 2010 Management Shell.
  4. Run the C:\Users\Desktop\ContentSources\CreateContentSources.ps1
Output:

Create Content Sources in SharePoint 2010 using PowerShell

And in the Central Administration you could see the newly added content sources as shown in the following

Create Content Sources in SharePoint 2010 using PowerShell



Reference:

http://www.c-sharpcorner.com/uploadfile/anavijai/create-content-sources-in-sharepoint-2010-using-powershell/

Sharepoint Search - Content Sources


In this article we can explore Content Sources and how to add a new Content Source.

Content Sources

Content Source represents the origin of content. As SharePoint handles various contents like Database, File System etc. there should be a Indexing Service to handle all these sources.

Please have a note that SQL Server is having Full Text Search index, but SharePoint has its own Indexing engines.

By default SharePoint searches in the site collection and document libraries.

Using Custom Content Source configuration we can make SharePoint search the possible areas:

  • File System Drives
  • Network Drives
  • Lotus Notes Data
  • Web Sites
Adding new Content Source

In this example we are trying to add a File System content source. After adding, the user will be able to search on the files and contents inside it.

The following are the steps involved:

  1. Create a Share Folder named Contents with a Text File inside it and make Read/Write permissions for Everyone:

    ShrCntSr1.jpg

    Ensure that the above folder contains a text file with data for eg: MyTodo
     
  2. Open the Central Administration web site and click on the Manage Service Applications link:

    ShrCntSr2.jpg
     
  3. Click on the Search Service Applications from the page that appears:

    ShrCntSr3.jpg
     
  4. Click the Content Sources link from the left pane:

    ShrCntSr4.jpg
     
  5. Click on the New Content Source link from the page that appears:

    ShrCntSr5.jpg
     
  6. Enter the following details in the Content Source page:

    ShrCntSr5.1.jpg

    Click the OK button and the Crawler will be performing a crawl.
     
  7. Go back to the main site and enter the keyword to search for (MyToDo). You can view the following results:

    ShrCntSr6.jpg


This concludes our article on adding Content Source and doing a sample search.

Viewing Crawl History

We can always view the crawl log to check the activity was successful and view the errors if not. Use the View Crawl Log command to view this.

ShrCntSr7.jpg

Starting Crawls

We can start, stop, and pause crawls manually by using the command bar as shown below. Please note that the data will not be searchable until after a full crawl.

ShrCntSr8.jpg

Summary

In this article we have explored how to add a content source in a SharePoint site.


Reference:

http://www.c-sharpcorner.com/UploadFile/40e97e/sharepoint-search-content-sources/

Configure a Crawl Schedule for Enterprise Search Content Source in SharePoint 2010


In this article we will be seeing how to configure a crawl schedule for enterprise search content source in SharePoint 2010 using C#.

In the Search service application, you can schedule a full or incremental crawl of a content source. There are four types of Schedules:

  • DailySchedule - Used to specify the number of days between crawls.
  • WeeklySchedule - Used to specify the number of weeks between crawls.
  • MonthlyDateSchedule - Used to specify the days of the month and months of the year when the crawl should occur.
  • MonthlyDayOfWeekSchedule - Used to specify the days of the month, the weeks of the month, and the months of the year when the crawl should occur.
Through UI:
  • Go to Central Administration => Application Management => Manage service applications => Search Service Application.
  • In the Navigation go to Crawling => Content Sources.
  • You could be able to see the content sources.
  • I am going to edit the content source "Local SharePoint sites" and schedule the crawl.
  • Go to ECB menu of Local SharePoint Sites =>Edit.

    1.gif
     
  • You could see "Crawl schedule section" where you could schedule the Full Crawl and Incremental Crawl.

    2.gif
C# code:
  • Open Visual Studio 2010.
  • Go to File => New => Project.
  • Select Console Application from the installed templates.
  • Enter the Name and click Ok.
  • Add the following references.

    o Microsoft.SharePoint.dll
    o Microsoft.Office.Server.dll
    o Microsoft.Office.Server.Search.dll
     
  • Add the following namespaces.

    o using Microsoft.Office.Server.Search.Administration;
    o using Microsoft.Office.Server;
    o using Microsoft.SharePoint;
     
  • Replace the code with the following.


    //  search service application name   
                    string ssaName = "Search Service Application";
                    SearchContext context=SearchContext.GetContext(ssaName);
                    //  Represents a crawl schedule used to specify the number of days between crawls
                    DailySchedule daily =new DailySchedule(context);             
                    daily.BeginDay = 25;               
                    daily.BeginMonth = 1;              
                    daily.BeginYear = 2010;              
                    daily.StartHour = 2;
                    daily.StartMinute = 30;              
                    daily.DaysInterval = 1;
                    //  Represents a crawl schedule used to specify the number of weeks between crawls.
                    WeeklySchedule weekly =new WeeklySchedule(context);               
                    weekly.BeginDay = 25;               
                    weekly.BeginMonth = 1;
                    weekly.BeginYear = 2010;             
                    weekly.StartHour = 23;
                    weekly.StartMinute = 15;           
                    weekly.WeeksInterval = 1;
                    Content ssaContent =new Content(context);
                    ContentSourceCollection ssaContentSources = ssaContent.ContentSources;  
        
                    //  Getting the content source
                    ContentSource cs = ssaContentSources["Local SharePoint Sites"];
                    //  Incremental Crawl Schedule
                    cs.IncrementalCrawlSchedule = daily;
                    //  Full Crawl Schedule
                    cs.FullCrawlSchedule = weekly;
                    cs.Update();  

     
  • Build the solution.
  • Hit F5.
  • You could see the Full Crawl and Incremental Crawl has been scheduled successfully which is also reflected in the UI.

    3.gif
     


Reference:

http://www.c-sharpcorner.com/uploadfile/anavijai/configure-a-crawl-schedule-for-enterprise-search-content-source-in-sharepoint-2010/