SharePoint Developer Center > SharePoint Products and Technologies Forums > SharePoint - Search > Will custom Advanced Search break other OOTB functionality?
Ask a questionAsk a question
 

AnswerWill custom Advanced Search break other OOTB functionality?

  • Tuesday, November 03, 2009 11:51 AMkmcknight Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi all,

    I'm looking to start on the right foot here. I plan to write a custom Advanced Search Webpart, but I still want other functionality OOTB to still work like (Search stats, stemming, 'Did you mean this?' and Best Bets etc).

    I found an example below: http://stackoverflow.com/questions/641924/advanced-search-option-programatically-sharepoint-search

    Before I even spend time on this, has anyone else done this? Will the example code still work with the OOTB functionality?

    Any pointers would be greatly appreciated.
    Cheers.

    K.

Answers

  • Tuesday, November 03, 2009 2:55 PMCoreyRoth Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    The Wildcard Search web part that I put on CodePlex can definitely get you started in the right direction.  It changes the query that is executed by using reflection to get to the internal properties in the CoreResultsWebPart.  It already has the ability to specify a custom sort order which is done in the query.  I think you would prefer to sort using the API in this case rather than XSL since it executes server side and sorts the entire result set (not just the current page).  As for saving the user's query that's just a matter of storing it somewhere which you should be able to easily do.
    Corey Roth blog: www.dotnetmafia.com twitter: twitter.com/coreyroth

All Replies

  • Tuesday, November 03, 2009 12:16 PMCharlie Holland Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    I haven't tried the code you've included but looking at it, it's trying to do the whole search in one control. It wont' break the built in functionality but it's not exactly leveraging the other search web parts if thats what you're after.

    What additional functionality are you looking to add? there may be easier ways to do it.


    Ch. - My Blog
  • Tuesday, November 03, 2009 1:18 PMkmcknight Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi Charlie,

    What I am after is a way to sort the search results and have an option to save the search (for later use) via the advanced search results page which are the main goals.

    What isn't clear is whether writing a custom search results page (for advance search) would break other dependant web parts\functionality that rely on the results (e.g. best bets, stemming, 'Did you mean...' and search stats etc...). If they do get broken then it'll be a non-starter.

    Thanks.
    K.


  • Tuesday, November 03, 2009 1:27 PMBrian Bedard Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    As long as your web part derives from advance search web part and you return the same data shape as the original web part, you can't break it.

    To do sorting, I recommend using XSLT on the XML generated by the search query.  Just make sure you include all the same elements and attributes as the normal web part.  You might even be able to just bolt on XSLT without writing a new web part (haven't tried that).  Can you use SharePoint designer (writing XSLT is non-trivial)

    Saving is definitely custom.  But you may be able to get away with just adding a custom action and consume the search results for serialization and storage.  I would probably just add a button on the web part but there may be a better way.

    If you want to create a new search results page, you just need to update the search box to point to the new page instead of the default.  I believe you will still have to provision a search center to do this.

  • Tuesday, November 03, 2009 1:34 PMPaul Lucas Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    The search web parts utilise a special type of web part connection via a control called "SearchResultHiddenObject". This object is stored on the HttpContext which allows all the search web parts on a page to connect to the same search data.

    If your custom advanced search does not use this control (ie pass the search query to it), I'm afraid none of the OOB web parts will work. What's even worse, the SearchResultHiddenObject is marked internal, so cannot be used with your custom code.

    Hope this makes sense. You can read more about it here.

    http://blogs.msdn.com/mortens/archive/2008/02/22/hidden-search-object.aspx

    You can however workaround this issue. Tom Clarkson provides a good example.

    http://www.tqcblog.com/archive/2007/10/25/creating-a-custom-advanced-search-box-in-moss-2007.aspx



    Paul.
  • Tuesday, November 03, 2009 2:02 PMkmcknight Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    As long as your web part derives from advance search web part and you return the same data shape as the original web part, you can't break it.

    To do sorting, I recommend using XSLT on the XML generated by the search query.  Just make sure you include all the same elements and attributes as the normal web part.  You might even be able to just bolt on XSLT without writing a new web part (haven't tried that).  Can you use SharePoint designer (writing XSLT is non-trivial)

    Saving is definitely custom.  But you may be able to get away with just adding a custom action and consume the search results for serialization and storage.  I would probably just add a button on the web part but there may be a better way.

    If you want to create a new search results page, you just need to update the search box to point to the new page instead of the default.  I believe you will still have to provision a search center to do this.

    Hi Brain,

    Yes you can sort the results for that page via XSLT, but I'll need to sort all results prior to paging the results. Hence different approach. I've been here before with the People's search, but it's another possible approach.

    Thanks for the feedback tho.

    K.

  • Tuesday, November 03, 2009 2:09 PMkmcknight Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    The search web parts utilise a special type of web part connection via a control called "SearchResultHiddenObject". This object is stored on the HttpContext which allows all the search web parts on a page to connect to the same search data.

    If your custom advanced search does not use this control (ie pass the search query to it), I'm afraid none of the OOB web parts will work. What's even worse, the SearchResultHiddenObject is marked internal, so cannot be used with your custom code.

    Hope this makes sense. You can read more about it here.

    http://blogs.msdn.com/mortens/archive/2008/02/22/hidden-search-object.aspx

    You can however workaround this issue. Tom Clarkson provides a good example.

    http://www.tqcblog.com/archive/2007/10/25/creating-a-custom-advanced-search-box-in-moss-2007.aspx



    Paul.

    Hi Paul,
    Yes, this hidden object does make sense as this was the approach I used for People's search. So, I'll have a deeper dig around and see what I get.

    Another good source of info is this: http://senthilmani.wordpress.com/
    Looking at the code it was also taken from Codeplex's Wildcard Search.

    Cheers for the feedback.
    K.
  • Tuesday, November 03, 2009 2:55 PMCoreyRoth Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    The Wildcard Search web part that I put on CodePlex can definitely get you started in the right direction.  It changes the query that is executed by using reflection to get to the internal properties in the CoreResultsWebPart.  It already has the ability to specify a custom sort order which is done in the query.  I think you would prefer to sort using the API in this case rather than XSL since it executes server side and sorts the entire result set (not just the current page).  As for saving the user's query that's just a matter of storing it somewhere which you should be able to easily do.
    Corey Roth blog: www.dotnetmafia.com twitter: twitter.com/coreyroth
  • Thursday, November 12, 2009 11:48 AMkmcknight Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Thanks for the feedback... It's very much appreciated.