Searching Quickly on Specific Properties

The search box that is available to users at first glance seems very plain. Type in search terms and possibly select a scope, click the search button, and get back results. This behavior is fine for many situations, and for more complex searches the Advanced Search page can be used. However, the problem with the Advanced Search page is that it can be difficult to understand for users who are unfamiliar with the finer points of SharePoint searching.

As mentioned earlier, you can expose some of the advanced search functionality by manipulating the variables passed in the URL string. This example shows how to take advantage of the advanced searching capabilities of MOSS in a more user-friendly manner. This example demonstrates how to create a custom search box that allows users to search only on the Title field.

To provide the functionality required, you’ll be using a technique that includes using the Content Editor Web Part to create a custom search string based on user input.

Exercise: Custom Advanced Search Using the Content Editor Web Part and JavaScript

For this example, you’ll add a Web Part to the home page that will allow users to do a quick search based on title. This example requires some basic JavaScript, but the specific code used was actually pulled from one of the countless free resources on the Internet and modified to fit the example.

1.
To begin, from a site collection with publishing enabled, select Site Actions > Create Page, and then select the Blank Web Part Page layout. Call the page “CustomSearch.”

2.
Add a new Content Editor Web Part to the page.

3.
Press Edit from the upper right hand corner of the Web Part and select Modify Shared Web Part.

4.
Select Source Editor from the Web Part tool pane. For this example, we’ll be adding some custom JavaScript code that will create an entry box and a button that, when selected, will process a search for any item with our entry in the title field. To get started, Enter the following code into the source editor:

Title:<input name=input1 />

<INPUT id="Submit1" onclick='Redirect(form.input1.value)'
type="button" name="schButton" value="Search" />

<SCRIPT LANGUAGE="javascript">

function Redirect(input)
{
 var baseURL = "/searchcenter/pages/Results.aspx?k=Title%3A"+input

    top.location.href = baseURL;

return true;
}

</SCRIPT>

The preceding code is configuring the search to be displayed on the search results page of the Search Center associated with a specific site. This could be updated to use any page that has a Core Search Results Web Part on the page.


5.
In the Appearance section of the Web Part Settings menu, change the Title from Content Editor Web Part to Quick Search on Title. Click Apply, and either publish the page, or check the page in as a draft.

6.
To test the Web Part, enter a word into the text box, and select the Search button. In this example, you’ll use “proposal” as the search term. The search results page specified in the JavaScript code will open. Notice that the search box contains the search query restricted to the title property (see Figure 8.15).

Figure 8.15. Search results from the Content Editor Web Part.


For this example, we restricted the search based on the Title property. The same concept could be used to build quick searches based on any of the properties included in the Advanced Search options. By combining a few of the OOB tools, powerful solutions can quickly be created that don’t require custom development.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.227.24.209