Tom Clarkson is a SharePoint consultant and entrepreneur based in Sydney, Australia.

Contact Details

Links



Recent Searches



Archives




Past Posts







RSS Feed

Creating a Custom Advanced Search Box in MOSS 2007

SharePoint 2007
Friday October 26 2007
The Search Results Core web part is quite easy to customise with XSL, which makes it a good out of the box solution for displaying data that comes from multiple sites or even multiple farms.
 
Unfortunately specifying the query to use is not quite so easy, limiting you to a hardcoded query with the fixed keyword query properties or whatever the user can type in to the standard search box. Sometimes this is enough, but the keyword syntax is too limited if you want to do something like return results newer than a certain date. For that you need to be using the SQL search syntax.
 
The advanced search web part uses SQL syntax and can get just about any result set you want. However, the UI is not really simple enough for the average user and isn't that convenient for searching lookup fields. Time to try customising the advanced search interface.
 
My first thought was to override the Advanced Search webpart. However, I on looking through the code in reflector I noticed that the advanced search webpart doesn't contain any code to build the query. That happens in a control called SearchResultHiddenObject, which is marked internal so there is no way to modify the construction of queries in code. On the other hand, the fact that the Advanced Search webpart doesn't do any special processing means that it can be safely removed.
 
Copying the html source for the webpart into a content editor webpart works quite well, or at least it did once I removed some of the table structure - "?Contents=1" is a very useful query string if your html breaks the menus. Note that you probably shouldn't edit the html directly in the cewp source editor, as it is difficult to get at the editor again if it is wrong, and you probably don't want to delete all your code, which is the only option the recovery interface gives you.
 
As well as the web part itself, you need to copy some script and hidden fields - the script block starts with the function DisplayNextProp and the hidden fields are ASB_TextDTProps, ASB_DateTimeDT_Props and ASB_ResType_Query.
 
Next step is to make a cut down version, getting rid of the table structure, giving me a relatively easy to modify form with all the original fields. The javascript can also be safely removed as it is only for updating the UI, and the whole point of the customisation is to replace that UI. I'm not sure what ResetPageHashCode does, but removing it doesn't seem to have any effect.
 
What we are left with is a set of html controls that can be modified as needed. There is no need to register the controls anywhere and the first part of the name is ignored - the SRHO just checks the part of the name starting with "ASB". All of the fields are optional, and the SRHO will ignore any missing values. The numbering of the controls with multiple instances such as the property controls has no special requirements - as long as they match the pattern ASB_PS_ they will work.
 
ASB_TextDT_Props and ASB_DateTimeDT_Props Are lists separated by "#;#" which specify the properties which will be treated as text and datetimes respectively when building the query. All others are treated as numbers.
 
ASB_ResType_Query is set by the result type dropdown and can be used to include some raw SQL. However, the SRHO requires at least one other piece of the query to be used.
 
ASB_PS_lolb_0 is the operator to use between properties - either "And" or "Or". This is required if multiple properties are checked and the same operator is used for all properties.
 
 
ASB_TQS_AndQ_tb is the "All of these words" search box.
 
ASB_TQS_PhraseQ_tb is for an exact phrase.
 
ASB_TQS_OrQ_tb is for "Any of these words".
 
ASB_TQS_NotQ_tb is for words to exclude. It can only be used if another search term is also specified.

The language checkboxes are named in the format ASB_SS_lcb_0_12 with a value of "on". The first number is a zero based index, while the last number corresponds to langdef values in the properties of a default search box. I'm not sure where those values come from.
 
Search Scope checkboxes are similar, with the format ASB_SS_scb_0_16 but no value set. The last number is the scope ID, which you can find in shared service administration.
Finally there are the property selectors. You can have as many of these as you want - just change the number at the end.
 
ASB_PS_plb_1 is the internal name of the property to search
ASB_PS_olb_1 is the operator, which will be one of the following values:
  • WebPartPlatform.Current.GetLocResourceString(LocStringId.AdvancedSearch_OperatorContain)
  • WebPartPlatform.Current.GetLocResourceString(LocStringId.AdvancedSearch_OperatorNotContain)
  • WebPartPlatform.Current.GetLocResourceString(LocStringId.AdvancedSearch_OperatorEqual)
  • WebPartPlatform.Current.GetLocResourceString(LocStringId.AdvancedSearch_OperatorNotEqual)
  • WebPartPlatform.Current.GetLocResourceString(LocStringId.AdvancedSearch_OperatorLater)
  • WebPartPlatform.Current.GetLocResourceString(LocStringId.AdvancedSearch_OperatorGreater)
  • WebPartPlatform.Current.GetLocResourceString(LocStringId.AdvancedSearch_OperatorEarlier)
  • WebPartPlatform.Current.GetLocResourceString(LocStringId.AdvancedSearch_OperatorLess)
  • WebPartPlatform.Current.GetLocResourceString(LocStringId.AdvancedSearch_OperatorTrue)
  • WebPartPlatform.Current.GetLocResourceString(LocStringId.AdvancedSearch_OperatorFalse)
or in English:
  • Contains
  • Does not contain
  • Equals
  • Does not equal
  • Later than
  • Greater than
  • Earlier than
  • Less than
  • Is true
  • Is false
ASB_PS_pvtb_1 is the value to search for.
 

Putting this all together, we get the following code which when placed in a content editor webpart will provide a dropdown to choose from a list of known authors and display the results in a search core results web part on the same page (assuming the url in the submit button is set to the current page).
 
<input type="hidden" name="ASB_TextDT_Props" id="Hidden4" value="Title#;#Author#;#Region" />
<input type="hidden" name="ASB_DateTimeDT_Props" id="Hidden5" value="Write#;#Created" />
Author:
       <input name="nameprefix$ASB_PS_plb_1" type="hidden" value="Author" />
       <input name="nameprefix$ASB_PS_olb_1" type="hidden" value="Contains" />
           <SELECT name="nameprefix$ASB_PS_pvtb_1">
            <OPTION></OPTION>
             <OPTION>Carolyn</OPTION>
             <OPTION>Clinton</OPTION>
              <OPTION>Tom</OPTION>
           </SELECT>
       <input name="nameprefix$ASB_PS_lolb_0" type="hidden" value="And" />
           <INPUT id="Submit1" onclick='WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("nameprefix$ASB_BS_SRCH_1", "", false, "", "/sites/home/SearchTest/default.aspx", false, false))' type="submit" name="nameprefix$ASB_BS_SRCH_1" value="Search" />
 
 

Comments

On 09 Nov 2007 02:02, dattard said:
You, my friend are a saviour! This looks like a life-saver!
On 16 Nov 2007 09:52, nickpearce said:
Excellent, thanks for blogging this.
On 20 Nov 2007 06:38, jason said:
excellent blog. one question, how does one go about capturing the html for the web part?

On 21 Nov 2007 06:10, Tom Clarkson said:
All the important stuff is client side, so you can use the browser's view source feature to get everything you need. If finding the relevant html in notepad seems like too much trouble, the IE Developer Toolbar works quite well for capturing the html source of a single web part.
On 27 Nov 2007 05:06, Vee said:
Hi Tom,
I'm trying to put a custom advanced search web part since I have many look up fields and some other actions that I need to do on the my search web part. However I would like to use the SearchCoreresults web part to display my results. Not sure if i could still use it..Appreciate your help. Thanks..
On 30 Nov 2007 03:28, Tom Clarkson said:
This approach gives you a custom web part with exactly the same output as the standard advanced search box web part. The standard results web part will work with it, as will the various other web parts on the search center results page.
On 10 Dec 2007 09:58, john said:
This is veruy helpfull,but i am having trouble adding two dropdown menus. A sample with a number of search options would be great  
On 11 Dec 2007 06:04, Stefan said:
>> That happens in a control called SearchResultHiddenObject, which is marked internal so there is no way to modify the construction of queries in code. <<

That's not fully true... it is possible with reflection. I did it successfully to implement wildcard searching with MOSS. I know, reflection is evil, but - so what?
On 24 Dec 2007 09:03, Itay Shakury said:
Very nice!
Thank's for sharing
On 15 Jan 2008 10:46, Pär Wallin said:
This is great!
Is it possible to specify the property to sort by for the result or how is that best done when showing the result in the Core Results Web Part?
On 09 Feb 2008 03:12, Tom Clarkson said:
John: check out the examples on dattard's blog (link above)

Stefan: Good point. Sharepoint does have a way of making us use evil coding techniques.

Par: You might be able to do something with ASB_ResType_Query. Sorting in the results web part is probably easier, though some forms of sorting there only apply to a single page.

On 23 Feb 2008 12:57, John Ross said:
I got everything setup and it works perfect.  Any idea how to get the search results to work with the paging web part? It seems to render the correct number of links for the paging webpart, but clicking on any of them does work.

-John
On 23 Feb 2008 09:34, Tom Clarkson said:
I haven't noticed any issues with the paging, though the implementation I have been using more recently is slightly different. 

Could the issue be something to do with the keywords not persisting when you link to the next page? If that turns out to be the problem, you can use ASP.NET controls which automatically save their state rather than html fields.
On 24 Feb 2008 04:32, John Ross said:
Strangely, I dropped the CEWP on the out of the box search page and the paging worked just fine.  I have also customized my search core results web part to render differently and I wonder if that could be the problem?
On 24 Feb 2008 05:16, John Ross said:
The problem with paging seems to occur when I try to have two search boxes on the same page.  I was trying to have one search setup for one property and the other a different one.  Because of the data, this method made the most sense.  I'll just have to see if I can come up with a creative way around this.
On 24 Feb 2008 10:52, Tom Clarkson said:
Using two web parts likely means that you have more than one control with the same name, which can lead to unpredictable results when the form is submitted - since they are on the same form you will either get the two values stuck together or it will just use the first one it finds.

The advanced search customised in this way is quite flexible - you can certainly set it up to search multiple properties. Any search boxes left blank will be ignored, and you can set ASB_PS_lolb_0 to search for either rather than both of the properties.

On 26 Feb 2008 01:26, John Ross said:
I've been testing this out all weekend, and paging never works for me -- even with a single CEWP.  If you add the paging web part to the page, it will initially show the correct number of results, but if you click to page 2 it loses state completely.  
On 26 Feb 2008 08:24, Tom Clarkson said:
Sounds like you need to try using ASP.NET controls - you have to switch from a cewp to a custom webpart or smartpart, but it gets you saved state.
On 28 Feb 2008 08:58, Paul Davis said:
I created a new custom advance search page and added the CEWP with the HTML you provided.  I modified the value of the URL to go to my results page and am getting the following error when clicking on search:

Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.

Any thoughts on this?  I assume that none of you are doing this in a farm scenario maybe?
On 20 Mar 2008 12:44, Carl said:
I've got this working (limiting to a specific scope too). I would like to direct the results to a page in the SearchCenter. Whenever I try to use that URL in the postback function, I get an error.

What's happening here? On submitting the search form, is there a way to GET the values into the URL of the searchCenter page?
On 20 Mar 2008 05:24, Tom Clarkson said:
You might want to try a custom result page first - that way you can add the search center web parts one at a time and see where the conflict is.
On 25 Mar 2008 08:39, Jexter said:
Thanks for the great example.  Has anyone tried to get this to work while linking to a different page?  Meaning put this sample code on one page and change the URL in the submit button to a different site that has the core results webpart on it.

I have tried this but get the "An unexpected error has occurred" screen.

Side Note - If i add the advanced search box webpart to the page, it works as expected.  Missing some variables/resources?  Any help would be great, thx
On 31 Mar 2008 03:28, Caroline said:
Can this be used to search for more than one property using just one input box?  I need to allow users to enter a value in just one text box and then search across many properties for this value.
On 31 Mar 2008 04:35, Tom Clarkson said:
If you want to search any property, the keyword part of the search box will work. If you need to search just a specific set of properties, you will need multiple fields, but you can use hidden fields for most of them updated with javascript so that the user only sees the one field.
On 16 Apr 2008 04:08, Inquisitor said:
How would you search for a Yes/No field? How do you add them to the list of properties to search for?
On 23 Apr 2008 11:02, celerity said:
How do we search on two columns using two different text boxes in custom advance search and having AND in between. Let's say i wanna do a search on Columns C1 and C2 and user have two text box T1 AND T2 once the user enters the value and hits the search it should return only those items in the list which has both the values in the respective columns. Please provide the javascript or some hint!! appreciate your help
On 24 Apr 2008 02:54, Tom Clarkson said:
Just duplicate the author bit from the example, changing the names in the copy to end with 2 instead of 1 and using textboxes instead of the select control as appropriate. 

On 28 Apr 2008 12:26, RJ said:
Hi Tom..Great post. However when i try to use a custom Search Results page i get this error - " 
This Page has been modified since you opened it. You must open the page again. 
 
Refresh page.
 
Troubleshoot issues with Windows SharePoint Services. 
". 
Can you please help!
On 28 Apr 2008 12:43, RJ said:
Hi Tom..Great post. However when i try to use a custom Search Results page i get this error - " 
This Page has been modified since you opened it. You must open the page again. 
 
Refresh page.
 
Troubleshoot issues with Windows SharePoint Services. 
". 
Can you please help!
On 05 May 2008 04:22, Madhur Chadha said:
wonderful blog...
Any idea how can we customise search center with tabs webpart
On 06 May 2008 12:03, DC said:
Great blog Tom, I would like to ask if it is possible to direct the custom advanced search back to the default Search Centre results page instead of a custom results page?

I am receiving the following error when attempting to do so:
"This Page has been modified since you opened it. You must open the page again.
Refresh Page.

Troubleshoot issues with Windows SharePoint Services."

Any advice or ideas would be greatly appreciated.
On 27 May 2008 01:46, Jonthemoon said:
Hi,
I'm badly trying to run this on MOSS 2007 and I get this error: 
Validation of viewstate MAC failed.

Please help me!! I've already lost too much time on this one!
Thanks a lot!
On 27 May 2008 01:52, Jonthemoon said:
Hi,
I'm badly trying to run this on MOSS 2007 and I get this error: 
Validation of viewstate MAC failed.

Please help me!! I've already lost too much time on this one!
Thanks a lot!
On 27 May 2008 06:34, JTM said:
Hi,
I'm trying to get this to work on a site. It works on one that uses SearchCenter and doesn't on one without the searchcenter. Is it possible that it needs SearchCenter to work?
On 28 May 2008 03:27, Amit said:
Hi,

The blog is wonderful,but i am facing one very strange problem in this.I have created one sitecolumn and corresponding managed property.After running the full crawl i am able to see the page with this column in results when i do basic search.Within advanced search i have created a filter on this column.Within the advanced search results i am able to see the page after applying filter,but only n some specific cases.The page doesn't comes in following conditions:
If the sitecolumn contains string with number of characters greater than 67 and within the filter if i put any words which lies in first 67 characters,search results comes perfectly.But if the searched word does not lies in first 67 characters,results don't appear.
But the results always comes in basic search.
Don't know if it is the restriction of sharepoint that it is matching only first 67 characters or something is wrong with advanced search.
Any pointers on solving this?????
On 28 May 2008 03:36, Amit said:
Hi,

The blog is wonderful,but i am facing one very strange problem in this.I have created one sitecolumn and corresponding managed property.After running the full crawl i am able to see the page with this column in results when i do basic search.Within advanced search i have created a filter on this column.Within the advanced search results i am able to see the page after applying filter,but only n some specific cases.The page doesn't comes in following conditions:
If the sitecolumn contains string with number of characters greater than 67 and within the filter if i put any words which lies in first 67 characters,search results comes perfectly.But if the searched word does not lies in first 67 characters,results don't appear.
But the results always comes in basic search.
Don't know if it is the restriction of sharepoint that it is matching only first 67 characters or something is wrong with advanced search.
Any pointers on solving this?????
On 28 May 2008 10:18, Manish said:
Hi, This is awesome, it saved my lot of pains.
The only thing I am looking forward is how to get "scope Id" or how can I limit my search to specific library or list using above solution.
Your suggestions will be really helpful for me.
Thanks & Regards
Manish
On 31 May 2008 06:41, JTM said:
Hi,
I'm too trying to get the scope ID list by code. If someone find it please post! 

For the "viewstate error" I found that setting the viewstate field to "" works perfect on my site.
On 02 Jun 2008 06:36, Tom Clarkson said:
@RJ, DC, Jonthemoon - Page and viewstate validation errors are probably a side effect of faking the asp.net output in html - the server doesn't know about the input controls so validation may fail. This is one reason why shortly after writing this post I switched to using a serverside implementation that creates asp.net controls.

@Madhur Chadha - This is based on some of the search center web parts. For more extensive customisation of search center it's usually best to build a custom page using as many of the search center web parts as you need.

@JTM - I'm not sure if you need an actual instance of Search Center, but you do need some of the web parts that are used by the out of box search center.

@Amit - 67 is an unusual number to trigger an error. It's not likely to be related to the search customisations in this post. Try searching using all out of box components first.

@Manish, JTM - Scope Ids can be found in shared service administration. You may need to look at some query strings to get the value. I'm not sure where you would look to get the scope ID programmatically.
On 03 Jun 2008 12:48, celerity12 said:
Hi
 Could you please give me an example how do i search a keyword inside the document and at the same time search in custom columns ... quite urgent appreciate ur help
thanks
On 03 Jun 2008 01:03, Tom Clarkson said:
@celerity12 - I'm not sure if the keyword search and property search can be combined in that way. I suggest you try to work out what you can do with the out of box advanced search page before you try the customisation. You may get somewhere by looking for a property that includes the document body.
On 11 Jun 2008 02:51, Ryan said:
I'm not sure if anyone solved the pagng issue.  this works great *except* I lose all stage when paging.  I must be missing some vital ingredient here.

Thanks,
-Ryan
On 11 Jun 2008 04:10, Ryan said:
I meant I that I lose "state" when paging.  Because of the strict names of the input text boxes I'm having trouble using ASP.NET controls instead to help maintain viewstate.
On 11 Jun 2008 08:21, Tom Clarkson said:
The names aren't actually that strict. They need to be in the form nameprefix$ASB_PS_plb_1, but the prefix is completely ignored by the search result hidden object, which means that it can be whatever asp.net sets the name to automatically when you set the id of the server control to ASB_PS_plb_1.
On 12 Jun 2008 01:01, Ryan said:
I think the problem may be the ContentPlaceHolder.  This is the HTML result of using an ASP:TextBox control inside PlaceHolderMain:

<input name="ctl00$PlaceHolderMain$ASB_PS_pvtb_0" type="text" id="ctl00_PlaceHolderMain_ASB_PS_pvtb_0" />

Is the prefix messing up the name/rendering?

-Ryan
On 12 Jun 2008 01:30, Ryan said:
I'm completely at a loss...

This works:  (but no paging)
<input name="nameprefix$ASB_PS_pvtb_0"/>

this does not:
<asp:TextBox runat="server" id="ASB_PS_pvtb_0"></asp:TextBox>

The asp textbox renders to:
Inside a ContentPlaceHolder:  <input name="ctl00$PlaceHolderMain$ASB_PS_pvtb_0" type="text" id="ctl00_PlaceHolderMain_ASB_PS_pvtb_0" />
 
Outside a ContentPlaceHolder:  <input name="ASB_PS_pvtb_0" type="text" id="ASB_PS_pvtb_0" />

Neither take my critera for searching.  Does one have too many $ delimiters and the other needs one?  Ugh...frustrating.

-Ryan
On 12 Jun 2008 09:29, Tom Clarkson said:
From what I remember from looking at the code in reflector, the prefix doesn't matter - the srho looks through all the fields posted and finds the ones that include ASB_PS_pvtb in the name.

Use of ContentPlaceHolder suggests that you are putting the code on the master page rather than in a web part. Since I got the values in the original post by looking at the rendering of a web part, that could be the problem.
On 12 Jun 2008 09:29, Ryan said:
Ok, solved it.  Very interesting.

The prefix ultimately needs to match your other fields.  For example:  

<input name="ctl00$PlaceHolderMain$ASB_PS_plb_0" type="hidden" value="FileName" />
<input name="ctl00$PlaceHolderMain$ASB_PS_olb_0" type="hidden" value="Contains" />
<Input type="hidden" name="ctl00$PlaceHolderMain$ASB_PS_lolb_0" Value="And">

Needs to line up with how this will ultimately be rendered in HTML:

<asp:TextBox runat="server" id="ASB_PS_pvtb_0"></asp:TextBox>

It seems that if the prefixes don't match each other, the search will ignore or not see the input values it expects to be there.  I never would have guessed this, and just got lucky trying different name properties on the hidden inputs.

Once that worked the paging works like a charm, although I'm still confused as to how the Advanced Search Web Part works in conjunction with posting to the Results.aspx page.  Paging still works there.  I tried to copy this page/process and couldn't get it to work, but didn't spend too much time on it.

Thanks again for such a great article, and I really appreciate you replying to the comments.

-Ryan


On 17 Jun 2008 08:52, pjh said:
Just an added comment to the 67 character issue mentioned on 05/28 and responded to on 06/02: not sure if it is related, but the following is true for out-of-box functionality: when using the Advanced Search property restrictions URL <contains>, it will only find results for strings  occurring in the first 67 positions, and not anything beyond.  A case was opened with MS concerning this limitation, and the response was that it was working as designed.  Again, not sure if its related, but the coincidence lead me to post this.
On 26 Jun 2008 03:36, Manikandan said:
This is the excellent Bolg!

I am having some issues in creating custom search box. It is working fine with the single drop down (Author) and it is giving a correct result. 
But while adding one more drop down for "Title" it does not give any result.
How can I add more than two drop down boxes? I should serch with the multiple columns with "OR" condition.

Please help us to resolve his issue.

Thanks in Advance,

Regards,

R. Manikandan.
On 26 Jun 2008 03:55, Paul Noone said:
This is a good workaround and can be applied to a number of web parts but I have two points.

1. If you want to keep all the features of the original form you'll need to keep the javascript in place for your "Add Property" additions to work.
2. A more robust solution is to grab the original source code from the /bin, save a copy and modify as required. In this way you can deploy the changes as a solution and activate it as a sitewide feature.

I'm in the process of testing a fully accesible version now. When it's done I'd be happy to post it here if anyone's inteersted.
On 29 Jun 2008 07:23, Tom Clarkson said:
@Manikandan - Just duplicate olb, plb and pvtb with a different number on the end.

@Paul Noone - If you want the same structure of the original advanced search box you are better off just using what customisation is available on the standard one. This solution is more intended to produce something with the power of the advanced search but a completely different UI. 

For a more robust solution after writing this post I set up a web part that produces the same output based on an xml configuration property, which was fairly straightforward to do.
On 10 Jul 2008 07:30, Ahmed Nasser said:
Hi Tom,
  I'm trying to change the text of the advanced search property filters like (Pick a property),(Add Property),(Where the property).
  I tried the client side method but errors occured due to viewstate validation.
  Is there any work around to modify those texts? if not how can i impelment a server side solution as the advancedsearchbox class is sealed!!
On 11 Jul 2008 07:48, Steffen Estrup said:
I found a sollution to the problem: "This Page has been modified since you opened it. You must open the page again.".

Basicly what I needed to get it to work was the ResetPageHashCode function. So I inserted the following on the Prerender of my search web part:

string script = "<script>function ResetPageHashCode()\r\n                {\r\n                    var f = document.forms[0];\r\n                    if (null != f && null != f.elements['MSO_PageHashCode'])\r\n\t\t        f.elements['MSO_PageHashCode'].parentNode.removeChild(f.elements['MSO_PageHashCode']);\r\n\t\t            _spFormOnSubmitCalled = false;\r\n\t\t            \r\n                }</script>";
this.Page.ClientScript.RegisterClientScriptBlock(base.GetType(), "__ASB_SCRIPTS__", script);

ResetHashCode(); would then be needed to run on the onclick event on the search submit button.

I havent't tried it in a content editor web part but I sopose you could just put it in a script block within your editor and it would work aswell.

I had this problem with "Search Server 2008" and not MOSS But should work almost identical.

Hope this helps some of you :)
On 21 Jul 2008 07:16, Mark said:
Hello Tom,
Thanks for this blogitem :D very handy! I got i worked with a couple of pulldown menu's...and now i want to fix it with checkbox..that works but i have a problem with the AND/OR function :S
I have a pulldown menu (Status) and then two checkbox (Knowlegde) and I want the following function Status AND (Knowlegde checkbox 1 OR Knowlegde checkbox 2)..but how must I do that? I got the following code:

Status:
       <input name="nameprefix$ASB_PS_plb_1" type="hidden" value="SWKennisStatus" />
       <input name="nameprefix$ASB_PS_olb_1" type="hidden" value="Contains" />
           <SELECT name="nameprefix$ASB_PS_pvtb_1">
            <OPTION></OPTION>
             <OPTION>Draft</OPTION>
			 <OPTION>Final</OPTION>
			 <OPTION>Not Started</OPTION>
           </SELECT>
       <input name="nameprefix$ASB_PS_lolb_0" type="hidden" value="And" />
<br />
Knowlegde:
		<input name="nameprefix$ASB_PS_plb_2" type="hidden" value="Knowlegde" />
		<input name="nameprefix$ASB_PS_olb_2" type="hidden" value="Contains" />		   
		<input type="checkbox" name="nameprefix$ASB_PS_pvtb_2" value="Kennis 1">
	
       <input name="nameprefix$ASB_PS_lolb_1" type="hidden" value="Or" />	
	   
		<input name="nameprefix$ASB_PS_plb_3" type="hidden" value="Knowlegde" />
		<input name="nameprefix$ASB_PS_olb_3" type="hidden" value="Contains" />		   
		<input type="checkbox" name="nameprefix$ASB_PS_pvtb_3" value="Kennis 2">

Regards
On 21 Jul 2008 09:07, Mark said:
Hello Tom,
Thanks for this blogitem :D very handy! I got i worked with a couple of pulldown menu's...and now i want to fix it with checkbox..that works but i have a problem with the AND/OR function :S
I have a pulldown menu (Status) and then two checkbox (Knowlegde) and I want the following function Status AND (Knowlegde checkbox 1 OR Knowlegde checkbox 2)..but how must I do that? I got the following code:

Status:
       <input name="nameprefix$ASB_PS_plb_1" type="hidden" value="SWKennisStatus" />
       <input name="nameprefix$ASB_PS_olb_1" type="hidden" value="Contains" />
           <SELECT name="nameprefix$ASB_PS_pvtb_1">
            <OPTION></OPTION>
             <OPTION>Draft</OPTION>
			 <OPTION>Final</OPTION>
			 <OPTION>Not Started</OPTION>
           </SELECT>
       <input name="nameprefix$ASB_PS_lolb_0" type="hidden" value="And" />
<br />
Knowlegde:
		<input name="nameprefix$ASB_PS_plb_2" type="hidden" value="Knowlegde" />
		<input name="nameprefix$ASB_PS_olb_2" type="hidden" value="Contains" />		   
		<input type="checkbox" name="nameprefix$ASB_PS_pvtb_2" value="Kennis 1">
	
       <input name="nameprefix$ASB_PS_lolb_1" type="hidden" value="Or" />	
	   
		<input name="nameprefix$ASB_PS_plb_3" type="hidden" value="Knowlegde" />
		<input name="nameprefix$ASB_PS_olb_3" type="hidden" value="Contains" />		   
		<input type="checkbox" name="nameprefix$ASB_PS_pvtb_3" value="Kennis 2">

Regards
On 22 Jul 2008 10:08, Paromita said:
Hi Tom, 

Great work!!!
Thanks a lot for such a nice article.
But i am facing a problem , the values are not persisting in the controls after firing search.
Can you please help me out in this regard?

Regards

On 24 Jul 2008 09:27, Faruk said:
Hi, 
Really good blog. But couldn't do it. I'm struggling to re-create the Advanced search box within the Content Editor Webpart (not an expert on SP). Is it possible that someone upload a sample source code to recreate the advanced search box?
Regards
On 28 Jul 2008 03:19, Tom Clarkson said:
@Ahmed - This post is about replacing the search box completely. Whenever you have an asp.net textbox you have to modify the options server side or turn off viewstate validation. You shouldn't need to change the dropdowns you mention as they are fully configurable with xml.

@Mark - Unfortunately there is only one control for specifying the operator - you can't use both. You may be able to do something similar with javascript and passing in raw sql though.

@Paromita - see other comments regarding using asp.net controls.

@Faruk - try the posts linked from http://www.tqcblog.com/archive/2007/11/16/more-on-customising-advanced-search.aspx
On 28 Jul 2008 10:27, Paul said:
Hi Tom

I have tried this to build a custom search page for our site.  However, I have attempted to replace the QuickSearch on the masterpage with this.  I am using ASP.Net controls for the Dropdown, Textbox and button, and (obviously) HTML Hiddent fields elsewhere.  However I am getting Vewstate issues (Validation of viewstate MAC failed).  Not sure if I am missing something stupid, but your blog sppears to suggest the use of ASP.Net controls will get around hte viewstate isues.  Ay idea what I am doing wrong?
On 29 Jul 2008 09:58, Eli RIpoll said:
Hi Tom my question is are you able to list more then one dropdown and if so is there any additions or exceptions needed to add additional columns/drop down boxes. I.E change 1 to 2, etcs) posting code with an extra column refference would be great too (wishful thinkin) but thanks this article helps alot
On 30 Jul 2008 12:01, Tom Clarkson said:
@Paul - putting it on the master page will change the position in the control hierarchy and give it a different id, which may have something to do with the problem. Check for conflicts with standard controls on the results page. The viewstate problem that using asp.net controls solves is keeping search strings in the textbox. you may need to disable the validation on that control to get it working in your scenario.

@Eli - Yes, adding additional controls works. lolb and srch are the only ones that have a number but can't be duplicated. 
On 01 Aug 2008 09:38, Eli said:
Thanks that worked!
but a strange thing i have it working fine aon one site but on another with the exact same hierarchy when i click the search button it says the "This Page has been modified since you opened it. You must open the page again" click refresh. i have the page going to a different page in the same folder like the first site but something a miss, have you ever had/seen this issue?
On 01 Aug 2008 12:57, Eli said:
Thanks that worked!
but a strange thing i have it working fine aon one site but on another with the exact same hierarchy when i click the search button it says the "This Page has been modified since you opened it. You must open the page again" click refresh. i have the page going to a different page in the same folder like the first site but something a miss, have you ever had/seen this issue?
On 21 Aug 2008 11:01, Ajith said:
Hi Tom,

Let me know how the advance search webpart and search core results webparts linked. I need to create a custom search  and need to diplay the results in search core results webpart( My assumption the saerch is happening in the search core result webpart)
On 22 Aug 2008 09:27, Tom Clarkson said:
Actually it's a hidden object that does the search. To connect to that you just have to put appropriately named fields into the form.
On 25 Aug 2008 09:17, Ajith said:
Tom,

The where the hidden object resides? Can you give the deatils about how the hidden object works? whats the input and output to/from the hidden object.

On 26 Aug 2008 02:45, Ajith said:
Tom,

The where the hidden object resides? Can you give the deatils about how the hidden object works? whats the input and output to/from the hidden object.

On 27 Aug 2008 05:54, Paul said:
Tom,

Is there anyway of getting the webpart to pass the search criteria in teh querystring, like the standard advanced search does?  The search and even pagination works fine, but when i click on the modified link up the top to changed sorting, it clears the results.

I can only get this thing working when i have a core results on the same page and the submit button refers to the current page.  Is it possible to redirect to the standard results page?

Perhaps the best way forward is to build a server-side web part.  Did you jsut copy the code from somewhere int he hive and paste in your web-part as a starter point?

THanks for all you great work.
On 29 Aug 2008 02:32, Ajith said:
Tom,

The where the hidden object resides? Can you give the deatils about how the hidden object works? whats the input and output to/from the hidden object.

On 19 Sep 2008 11:41, Tom Clarkson said:
@Paul - I started by copying the html output of the advanced search box web part then made a control to reproduce that. Are you sure about the search criteria in the query string? The regular search does that using keyword query syntax, but I haven't seen sql syntax as used by advanced search in the query string.

@Ajith - to get more than is in this article you'll need to dig around in the SharePoint code using Reflector.
On 19 Sep 2008 06:27, Aaftab said:
Hi Tom,

I added the custom Advanced Search webpart on the Colaboration Portal. But the AutoPostBackwithoptions on Search button click is not working. It just refreshes the page.

Do you have any idea as to what is happening. I am using exactly the same code with same name and id.

Thanks for the article!

Best Regards,
Aaftab
On 14 Oct 2008 02:07, Madhur chadha said:
somebody asked about finding scope ids programmatically..
heres the code snippet


    Scopes allScopes = new Scopes(SearchContext.GetContext(SPListHelper.GetCurrentWeb().Site));
            Scope myScope= allScopes.GetSharedScope("myScopename");
            string scopeId = myScope.ID.ToString();

but i still m not sure where the 0 comes from in ASB_SS_scb_0_16
note :as tom said 16 here is the scope ID 
On 14 Oct 2008 02:07, Madhur chadha said:
somebody asked about finding scope ids programmatically..
heres the code snippet


    Scopes allScopes = new Scopes(SearchContext.GetContext(SPListHelper.GetCurrentWeb().Site));
            Scope myScope= allScopes.GetSharedScope("myScopename");
            string scopeId = myScope.ID.ToString();

but i still m not sure where the 0 comes from in ASB_SS_scb_0_16
note :as tom said 16 here is the scope ID 
On 14 Oct 2008 02:08, Madhur chadha said:
note here splisthelper is a custom helper class you could simply use current spsite
On 15 Oct 2008 09:03, Prabhakar said:
Nice Bolg!

I having some issues in custom search box. It is working fine with the single drop down (Author) and it is giving a correct result. 
But while adding one more drop down for "Title" it does not give any result. It's showing error message. How can I add more than two drop down boxes? I should serch with the multiple columns with "OR" condition.

Please help us to resolve his issue.

Regards,
Prabhakar.T
On 16 Oct 2008 02:22, Tom Clarkson said:
You're probably reusing an id somewhere - make sure you are incrementing the numbers appropriately.

For the operator, try ASB_PS_lolb_0 as described in the original post.
On 16 Oct 2008 03:32, Prabhakar said:
Tom & Ryan & John,

Any idea how to get the search results to work with the paging web part? It seems to render the correct number of links for the paging webpart, but clicking on any of them does work. 

Let me know the full code using asp.net controls. 
On 21 Oct 2008 09:12, Reet said:
I would like to use Result type as word documents only of Advanced search box webpart and limit the results to file extension of doc docx or dot only in search results I am totally new to sharepoint and i dont want to show the drop down to users can someone help me with this.I tried to change the properties in the xml file but it is not showing the relevant results
On 23 Oct 2008 01:14, WarrenR said:
Just found out where the language checkboxes names come from, and thought you might like to know ... if you edit the webpart "Modify Shared webpart", and expand "Properties", then edit "Properties" property, you will see that this is a blob of XML, where all the available languages (root/LangDefs/LangDef) and the selected languages (root/Languages/Language) are documented. The suffix of the control number corresponds to the LangId attribute in the XML!! Happy coding.
On 23 Oct 2008 05:13, said:
On 03 Nov 2008 05:55, Reet said:
Hi
The sharepoint searches on the basis of author of the document, modified by, modified date of the document. i dont want a search on the basis of these properties I just want to search on Name and content of the document
How do i achieve this? Please help
On 07 Nov 2008 11:27, Phil said:
Thanks Tom, scopes, result types managed properties, every thing worked fine. I was able to recreate and customise the whole advanced search web part.

Awesome post !
On 21 Nov 2008 09:01, maets said:
Hi, thanks Tom for this, really useful!

To the people with "Validation of viewstate MAC failed" and "This Page has been modified since you opened it" issues: I did a workaround for this using two webparts:

webpart #1, a simple textbox and button situated wherever I want it to be on my site. The button's onclick event redirects the user to the Enterprise Search Center page named results.aspx with querystrings of the search.

webpart #2, added within results.aspx. Using Page.ClientScript.RegisterStartupScript() and _spBodyOnLoadFunctionNames.push("myfunction") where "myfunction" simply calls document.aspnetForm.submit() instead of the onclick event fired in the above example. The <html> from the example above is still rendered as usual.

So.. this webpart registers some onload javascript which automatically posts the form and cause postback, which in turn will bring up the search results. As a final touch I simply set the webpart #2 attribute to hidden. Make sure to check if !Page.IsPostBack before registering the onload javascript. 

 
On 25 Nov 2008 08:59, SydLady said:
can any one explain how to add pick list on advance search 
step by step
Yes all are managed properties
On 25 Nov 2008 09:37, Aaftab said:
Hi Tomm,
my previous issue is resolved by adding a required field validator on the webpart :) i have another issue, I want to show only word documents in the search results from a Document Library. for this i have already created a scope and added to the coresearchresults webpart. Problem is that i have a few folders in the Document Library and sometimes they show up in the results...
I have tried adding the Result Type dropdown wirh Word Documents as the only value but it doesn't help.. 

Any suggestions on this will be appreciated..

Thanks,
Aaftab
On 26 Nov 2008 09:13, Tom Clarkson said:
Try doing something with the standard keyword search interface (ContentType:Document etc) - if you can work out the right query to use there it should tell you what you need to set up when customising the advanced search.
On 02 Dec 2008 11:31, decatec said:
is there are place like on MSDN to find all the ASB* definitions?
On 03 Dec 2008 09:10, Tom Clarkson said:
There isn't any official documentation of this that I am aware of. I believe my list is fairly complete, but if you want to go back to the original source you'll need to use reflector.
On 03 Dec 2008 09:41, Aaftab said:
Hi Tom,
I know a way to restrict the documents as i add -isDocument:0 in Basic search but i don't know where to add it in my custom advanced search webpart.

Any idea on the same?

Thanks,
Aaftab
On 04 Dec 2008 02:30, stevus_uk said:
This is a really good post but I have to say I seem to have a problem getting it to work.  I tried the HTML approach with a fairly complicated structure and then with a very simple keyword field etc and get the ViewState problem you have mentioned in the comments.  So I decided to implement the code on server side but I'm getting exactly the same problem.

Any advice or things I could look at as to why this might be happening.

I've included the hidden property fields, the keyword field and submit button.  That's it for now...
On 04 Dec 2008 04:12, stevus_uk said:
This is a really good post but I have to say I seem to have a problem getting it to work.  I tried the HTML approach with a fairly complicated structure and then with a very simple keyword field etc and get the ViewState problem you have mentioned in the comments.  So I decided to implement the code on server side but I'm getting exactly the same problem.

Any advice or things I could look at as to why this might be happening.

I've included the hidden property fields, the keyword field and submit button.  That's it for now...
On 12 Dec 2008 12:27, PAFleche said:
I juste wanna warn you about the "ASB_PS_olb_*" control :
the attribute "value" depends of the site language.
For example i have 
<input name="containNameSearch$ASB_PS_olb_0" type="hidden" value="Contains" /> 
in english Sites and 
<input name="containNameSearch$ASB_PS_olb_0" type="hidden" value="Contient" />
in french Sites.
On 12 Dec 2008 09:23, Tom Clarkson said:
That is correct, though it's worth noting that it's not as simple as just translating the words - some languages only translate some fields and use english for the rest.

Leave a comment