Archive for Sharepoint 2010 Search

Working with SharePoint 2010 search web service

In this article we will discuss how to user search web service in SharePoint 2010. We will search by using SharePoint search web service. Also you can check about FAST search here. SharePoint 2010 search is very useful and advanced in SharePoint 2010.
There are different search web services available for SharePoint search and SharePoint Enterprise Search. The service url for sharepoint search is:

http://[URL]/_vti_bin/spsearch.asmx
The web service url for sharepoint enterprise search is:
http://[URL]/_vti_bin/search.asmx
For this demo we will use client object model and we will bind the search result to a datagridview in a windows application.
You can put a Textbox where user can put the search text, a button and a datagridview where user can see the search result as output. see the figure for reference.

In the next step we need to add reference to the web service.
For this Right click on the project and click Add service reference. This will open the Add Service Reference dialog box. On that box click on Advanced… as shown in the figure below:

This will open the Service Reference Settings dialog box, from there click on Add Web Reference… as shown in the figure below.

The above step will open the Add Web Reference dialog box.

In that window enter the URL of the web service and click on the green arrow. This will search and found the web service if present. Then click on Add Reference as shown in the figure below:

This finishes our reference to the web service.
Now open the Button click code.
First give reference to the web service like:
using SearchPOC.QueryWebServiceProxy;
Here we will use the QueryService class and pass the DefaultCredentials as the parameter.
Then it will take an XML as an search input parameter which is shown in the full code below.
Then here in this example we are calling the QueryEx method which returns the results as a DataSet. We also can use Query method which returns results as an XML document.
Full code:


private void btnSearch_Click(object sender, EventArgs e)
        {
            try
            {                      
            QueryService queryService = new QueryService();
            queryService.Credentials = System.Net.CredentialCache.DefaultCredentials;
            StringBuilder queryXml = new StringBuilder();
            queryXml.Append(““);
            queryXml.Append(““);
            queryXml.Append(““);
            queryXml.Append(““);
            queryXml.Append(“urn:Microsoft.Search.Response.Document.Document”);
            queryXml.Append(“
“);
            queryXml.Append(“
“);
            queryXml.Append(““);
            queryXml.Append(“5000“);
            queryXml.Append(“
“);
            queryXml.Append(““);
            queryXml.Append(““);
            queryXml.Append(txtSiteURL.Text);
            queryXml.Append(“
“);
            queryXml.Append(“
“);
            queryXml.Append(“
“);
            queryXml.Append(“
“);
            System.Data.DataSet queryResults = queryService.QueryEx(queryXml.ToString());
            dataGridView1.DataSource = queryResults.Tables[0];
            }
            catch (Exception ex)
            {
                string s = ex.InnerException.ToString();
            }
        }

Targeting SharePoint search scopes to different audiences – Part 1


Part 1 – Creating a Content Source and Scope

This blog post series details how to target search tabs in SharePoint enterprise search to specific groups of people. I have provided a guide as to how to set this up from start to finish.

The search tabs in SharePoint relate to pages where scopes can be defined for narrowing down results as shown below.

image

Firstly you need to create a content source for the scope to use of the site you wish to crawl / index. In my case this was a non SharePoint website. So for the purposes of the demo I’ll create a content source called ‘Pauls Blog’ and crawl http://www.paulgrimley.com.

image

Once the content source is created run a full crawl and make sure that you successfully crawl by checking the crawl log.

image

Whilst the content source is crawling next thing to do is create a scope that contains the content source (make sure you compile the scope from search administration).

From the search navigation on the left hand select scopes under ‘Queries and Results’. From here click ‘New Scope’.

image

We’ll come back to the search results page later as this will need configuring. On the next page one thing that can trip you up assuming that you’ve created you’re scope and its ready. Before its ready to be used the scope needs two things – rules and compiling once the rules are in place. Firstly select ‘Add Rules’ which is where I will assign the content source created earlier to the scope.

image

On the next page simply select the content source option and pick Pauls Blog from the drop down and click ok.

image

Notice on the next page it will state the scope is not ready until the next scheduled compile which in this case is 8 minutes.

image

To speed up this process you can force an immediate update of the job by compiling scopes from the search administration home page. Simply select Start update now and this should compile your scope within a small space of time.

image

So now the scope should be available for use within the enterprise search site collection. In Part 2 I will discuss creating a separate results page that can be secured and targeted at specific individuals.

Targeting SharePoint search scopes to different audiences – Part 3


Part 3 – Adding tabs to Search Center

Following on from Part 2 this post in the series describes how to create the tabs and secure them to only be seen by certain users (In my case ‘sales’).

To create a tab there is quite a simple process and to do this all you need to do is edit a couple of lists stored in the search center called ‘Tabs in Search Pages’ and ‘Tabs in Search Results’

image

Select the first list above and add a new item to the list.

Tabs in Search Pages

image

At this stage you need to remember the name of the page you created in Part 2 as you will need to enter this in the next screen.

image

Once you’ve entered the information correctly click save.

This is the crucial bit where we set the security on tab to targeted users. On the list where the item ‘Pauls blog’ appears select this item and from the ribbon click item permissions.

image

Remove permissions to all users and add the sales AD group.

Follow the same steps as Tabs for Search Pages above for Tabs for Search Results list.

Once you have followed the steps above you should now have a newly created targeted tab within your enterprise search center as shown below.

Tabs in Search Page

image

Tabs in Results Page

image

Real world examples

To put some real world on this the sort of scenarios this could apply to may be rolling out people finder (My Sites) to certain departments or searching of legacy systems to specific users.

It’s also worth noting that this is series of posts focuses on non SharePoint (anonymous) related content where security trimming results do not apply. If security m ay be an issue this needs to be considered as part of the design.

Conclusion

This scope is not necessarily 100% secure as you could drop a search web part into a site and narrow it down this way but to do this you would need site collection admin rights so the risk is minimal.

This blog does not focus on additional security trimming of content and without testing and design you may be providing users to unauthorised results so the advice here is use an account to access other systems with minimal rights. If you do need an elevated results pane why not create 2 scopes / results pages and use different crawl accounts providing access only to authorised users to the elevated results.

I hope this has been of use to you.

Targeting SharePoint search scopes to different audiences–Part 2


Part 2 of the series focuses on creating the results page for use with the targeted audiences.

Within the enterprise search center create a new page from site actions on the ribbon and give it a name.

image

You’ll then be presented with a new results page which if your not used to may look a little daunting. From this page what we need to do is tailor the results web part to only display results for the newly created scope.

Locate the web part search core results shown below and select edit web part from the drop down.

image

On the right hand side you need to enter the scope exactly as you did for part 1, as this is a manual entry this can easily be entered incorrectly so pay special attention to this.

image

Click ok at the bottom of the properties noting that if the content source has completed results may not be displayed until the page is saved and reloaded PLEASE DONT SAVE THE PAGE YET THOUGH!

The next step I describe I didn’t originally do and this caught me out as the tab I describe in a later part to the series kept reverting back to the default results page and the tab would highlight the wrong scope so a new search would search the wrong source!

Locate the web part search box and edit the web part properties. From here expand the section miscellaneous. Modify the search results page to be the name of the page you are in the middle of creating, this basically means that once a search is committed on this page the scope will remain on the same scope. In this case the scope is Pauls blog.

image

So at this stage the page is configured with the correct parameters however we’re not quite finished yet, although at this stage you can now go ahead and save / publish the page. To secure who can see the page we need to edit permissions. Let’s assume we are going to show this to sales but restrict access to marketing. All we need to do is edit the permissions on the page as you would do with any other item in SharePoint you wish to secure.

So in my case I’m going to give all users part of the sales AD group access to the page. Navigate to the pages library via site settings -> view all site content –> pages. Select the newly created page and from the drop down select manage permissions.

image

From manage permissions select stop inheriting permissions.

image

Remove all the users you do not wish to view this results page / scope and add the sales AD group as readers. This now only allows sales users to be able to see the page.

Part 3 will discuss creating the tab that appear in the search center and aligning this to the newly created page described here.