in

SharePoint Blogs

The Best Place for SharePoint-related Blogs

Aaron Robertson-Hodders SharePoint Blog

Custom Search Web Part

Been a while since my last post. Mostly because we have been working very hard to complete a custom search solution.

The requirements for the solutions were:

- Data from Treeview controls that is entered into items must be able to be search using the Treeview control to select the search terms.

- Where there are Choice fields in the item columns these must be rendered as multiple select choices in the search UI.

- Values must be searchable based on a fixed set of ranges, eg. 1 million to 5 million.

- Date columns must be searchable based on a from date/to date range.

- Wildcards using * should be possible but no assumed.

- People fields should be searchable based on part of the name.

- Export results to Word and Excel documents.

Here's a sample of the sort of thing we came up with:

Along the way we discovered some things about MOSS searching:

- You cannot use the OOB web part to render your results unless you pass the query as a keyword query in the URL to a results page.

- You cannot search ranges using the Keyword Syntax.

- You cannot use FreeText or Contains to search People fields. LIKE works fine.

- Using FreeText and Contains makes handling wildcards and phrases very easy when building your SQL query string.

- You can stop Lists appearing in results by adding a search scope rule to exclude items where contentclass = STS_List_GenericList.

- The ListID for the item does not get returned in the search results. So we created an event receiver to add this to a hidden column so we could use it to build a custom export URL. If you know of a better/easier way, let me know!

- The StartRow for the SQL Query object is zero based, not 1 as I found much to my embarassment when no results came back from my single item list!

- The sample XSL in the SDK for rendering results is a better place to start than the XSL in the core results web part, just because it's less complex.

- Make sure you select the data type for a Managed Property Mapping before trying to find the property to map, as the list is filtered for you on data type - bit embarassing there too, esp the second time round!

- You can re-use the date picker control that is used in MOSS. Although we did have some problem with the rendering of the DatePicker CSS on our production server...

The best part of the solution is that it's all based on supported technologies (and no CAML in sight!) - Web Parts, Custom Field Controls, Custom ASP.Net Web Controls, XSL for rendering, Custom Search Scopes and Custom Search Tabs and Pages. Nice!

Comments

 

Carl said:

How did you do it?

July 17, 2007 1:59 PM
 

adrh said:

I created a webpart which renders controls for the UI based on XML configuration. The users selections generate a query string and then it uses the MOSS query object model to execute the query and return the results.

July 31, 2007 7:54 PM
 

Amkate said:

I also tried to make custom search.

I used CAML for creating query.

Did you used same query object or it is better to use SQL query directly?

August 20, 2007 9:47 AM
 

ibu said:

Its interesting that you find that OOB web part cannot be used in results page unless we pass the query as a keyword query in the URL to a results page. I have added the custom Core Search result web part in the results.aspx and added the OOB Search Action Link Web part in the results.aspx. Now when i am coming from default search (Keyword Query) the Search Action Link Web part is visible but when i am coming from Advance search page then OOb Search Action Link is not Visible.(The same behaviour what you mentioned). How should i get the Search Action Link web part Visible when i am navigating from Advance Search Web part, Can i send a Empty Query String , Will it work ? Thanks in Advance

October 2, 2007 7:49 PM
 

AlanP said:

Hello ADRH,

We have also built a custom Enterprise Search Webpart but we are having some problems. The FullTextSqlQuery errors when more than 10 properties in the where clause.

We have successfully implemented a fulltextsqlquery webpart allowing users to add filter conditions based on multichoice properties (mapped to managed properties).  However we have found that once a user selects more than 10 properties you get a “query is malformed” error message.

This is a sample query:

SELECT WorkId, Rank, Title, Author, Size, Path, Description, Write, SiteName, CollapsingStatus, HitHighlightedSummary, HitHighlightedProperties, ContentClass, IsDocument, PictureThumbnailURL, DocType, Year, Source FROM Scope () WHERE (\"scope\" ='Reports') AND  FREETEXT (defaultproperties, 'any') AND ( Geography ='Belgium'  OR  Geography ='Brazil' OR Geography ='Canada' OR  Geography ='Chile' OR  Geography ='China' OR  Geography ='Colombia' OR  Geography ='Croatia') AND ( DocType ='Pulse Documents' OR  DocType ='Annual' OR  DocType ='Country Reports' ) ORDER BY Rank DESC

If you run this query we get results back however if the user adds one more property selection e.g. one more country the results error.

We’ve tried putting these into comparison arrays but again the same error occurs.

I’ve checked in the advanced search web part (looking at the executed query in the logs) and you can get a working query with a lot more than 10 properties together.

Does anyone have any ideas as to what is doing this????

October 3, 2007 8:54 AM
 

Avi said:

Hi

Can you please share the code? It it is not against your ethics?

April 21, 2008 10:31 AM
 

Chris said:

Aaron Robertson-Hodders-

How did you get the research results exported into excel? I'd like to do the same.

April 30, 2008 12:24 PM
 

Coki said:

if i want display datepicker at webpart, using combination xslt and xml, how i do it ? any suggestion or sample code to do it ?? Thanks...

August 13, 2008 4:12 AM
 

Subbu said:

Hi Aron,

Could you please let us know how you customised the advanced search page? Basically we found that creating a custom search page and passing a FullTextSqlQuery string to results page isn't that easy.

August 23, 2008 2:09 PM
 

adrh said:

You cannot in any useful way (other than layout etc) customize the Advanced Search Web Part because they depend on a shared XML object for passing query and result data around. The only way is by creating a completely new web part (or web parts) that provide all the functionality, which is what we did...

August 24, 2008 6:04 PM
 

Jason said:

Thanks for taking the time to post this Aaron.  Aside from the list of tips, this doesn't help us much unless you are willing to share your code to some extent.  Please consider supporting the MOSS community by sharing your excellent findings.  You don't have to expose the client's solution, just create something smaller in scope and provide a how-to that covers the main points in step-by-step detail.  

Thanks

September 4, 2008 8:34 AM

Leave a Comment

(required )  
(optional )
(required )  
Add

About adrh

I'm a Kiwi, living in Australia (for the past 10 years). I work for MacroView, a consulting firm in Sydney specialising in SharePoint solutions, products (WISDOM Document Management extensions, Custom Search solutions) and consulting around Enterprise Search. My background includes experience developing solutions in VB, VB.Net C#, ASP, ASP.Net, SharePoint (from V1) and Office.

Need SharePoint Training? Attend a SharePoint Bootcamp!

Posts (c) their respective authors. Everything else (c) 2007 SharePoint Experts