Thursday, 15 November 2007

SharePoint 2007: Creating a custom advanced search webpart - Part 2

In the first part of this series of posts, we explained how to create a custom advanced search box by default which limits searches to a particular search scope.

In this part we will explain how to create a advanced search customization which uses a dropdown to limit results to a particular set of meta data / categories only.

Typical search requirements would be that users can limit their search results to a particular category of results only. An example of this would be the following: You have created a number a document library(ies) each having a DocType column which identifies whether the uploaded document is a Purchase Order, Invoice, Contract, Tender etc. You then want to create a search customisation such that your users can choose to search within Purchase Orders only.

This can be done using a number of sharepoint features and the advanced search custom webpart we will build.

Defining a searchable property

The first thing that we need to do is ensure that the DocType column we have created to categorize our documents is a searchable. To do this we need to go to the Shared Services > Search Settings > Metadata Property Mappings in Central Administration. As the description in this page says, "Users can perform queries over managed properties". Therefore we need to create our own mapped data property, and map this property to the DocType column we have created.

Click on the New Managed Property, give the property a name (DocType), and specify that this will be a text property. In the Mappings to crawled properties you need select the property to map to by clicking on Add Mapping and selecting the DocType column. This is done by searching for the DocType crawled property name. (If you don't find it here, you need to perform a full crawl, so that your column is discovered, and then re-do the steps here).

Once this is done you need to perform a full crawl again to make sure that the Number of items found with this property has a number which is greaten than zero. This means that items which use the DocType have been discovered.

Creating a custom advanced search dropdown which searches this property

Once again, we need to create a webpart page with a Content Editor Web Part and a Search Core Results web part. Using the source editor we define the following code:

The ASB_TextDT_Props defines the properties which will be used to define the text properties which will be used to build the query.

Quoting Tom Clarkson:
"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. "

Thus in our case:
<input type="hidden" name="ASB_TextDT_Props" id="Hidden4" value="DocType" />

We then define the search such that only items that contain certain values are displayed in the search using the following:

<input name="nameprefix$ASB_PS_plb_1" type="hidden" value="DocType" /> <input name="nameprefix$ASB_PS_olb_1" type="hidden" value="Contains" />

ASB_PS_plb_1 is the internal name of the property to search (in our case DocType)

whilst ASB_PS_olb_1 is the operator which will be used (contains)

The next thing is to actual build the drop down list:
<SELECT name="nameprefix$ASB_PS_pvtb_1"> <OPTION></OPTION>
<OPTION>Purchase Order</OPTION>
<OPTION>Invoice</OPTION>
<OPTION>Contract</OPTION>
<OPTION>Tender</OPTION>
</SELECT>

Once this is done, the only thing which is left is to create the text box to enter the queries to search for:
<input name="nameprefix$ASB_TQS_AndQ_tb" type="text" />

This used the ASB_TQS_AndQ_tb to define the All words in query operator.

The last thing which is required is the Submit button which posts to the CustomSearch.aspx page (which is the page which contains our Search Core Results Page):

<input type="hidden" name="nameprefix$ASB_SS_scb_1_4" value="nameprefix$ASB_SS_scb_1_4"/></table> <INPUT id="Submit1" onclick='WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("nameprefix$ASB_BS_SRCH_1", "", false, "", "/Pages/Pages/CustomSearch.aspx", false, false))' type="submit" name="nameprefix$ASB_BS_SRCH_1" value="Search" />

All Code:

<input type="hidden" name="ASB_TextDT_Props" id="Hidden4" value="DocType" />

<input name="nameprefix$ASB_PS_plb_1" type="hidden" value="DocType" /> <input name="nameprefix$ASB_PS_olb_1" type="hidden" value="Contains" />

<SELECT name="nameprefix$ASB_PS_pvtb_1"> <OPTION></OPTION>
<OPTION>Purchase Order</OPTION>
<OPTION>Invoice</OPTION>
<OPTION>Contract</OPTION>
<OPTION>Tender</OPTION>
</SELECT>

<input name="nameprefix$ASB_TQS_AndQ_tb" type="text" />

<input type="hidden" name="nameprefix$ASB_SS_scb_1_4" value="nameprefix$ASB_SS_scb_1_4"/></table> <INPUT id="Submit1" onclick='WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("nameprefix$ASB_BS_SRCH_1", "", false, "", "/Pages/Pages/CustomSearch.aspx", false, false))' type="submit" name="nameprefix$ASB_BS_SRCH_1" value="Search" />

This creates a dropdown custom advanced search which limits the search results to the particular category you have chosen. For more details on how this was done and what each operator does, what they stand for and more operations which you can use in your custom queries visit Tom Clarkson's post.

35 comments:

Vee said...

Hi,
I'm trying to build a custom search web part. However I'll not be able to use the way it was specified in Tom's post..Since I've many dropdowns and also other action that i have in this custom search web part. But i would like to use the SearchCoreResults web part to show my results..Do you think i should be able to pass my XML results to this CoreResults web part. Appreciate your help.
Thanks..

dattard said...

Vee, I'm working on something like this too at the moment. If I have some information I'll post again.

twoz said...

How can one find the internal name of a property?

dattard said...

Are you referring to the metadata property mapping?

You can find this in Shared Services adminisistration in Central Administration. You need to click on Shared Services Administration (SharedServices1) > Search Settings > Metadata property mappings.

Here you will find a list of all searchable properties. You can define your own or modify the existing ones. You can also use these in your queries.

John said...

When I use paging, if a user is on page 2 and then runs a new search, the new search shows results from page 2. If there is no page 2 it shows nothing.

Any idea how to get around this?

-John

Amila said...

Hi,

I want to have an advanced search facility for one of our forums, but my problem is I don't want to have this in several other forums hosted in the same SharePoint installation. Can I apply this customization to achieve my goal?
Appreciate any help.
Thanks,

xuemei said...

Now do you worried about that in the game do not had enough aion kina to play the game, now you can not worried, my friend told me a website, in here you can buy a lot aion online kina and only spend a little money, do not hesitate, it was really, in here we had much aion gold, we can sure that you will get the cheap aion kina, quick to come here to buy aion kina.

Now do you worried about that in the game do not had enough Anarchy credits to play the game, now you can not worried, my friend told me a website, in here you can buy a lot Anarchy Online credits and only spend a little money, do not hesitate, it was really, in here we had much Anarchy gold, we can sure that you will get the Anarchy online gold, quick to come here to buy AO credits.

. said...

酒店 ,酒店經紀 ,酒店公關 ,酒店兼職,酒店小姐, 酒店上班,酒店喝酒,酒店工作,酒店兼差,酒店打工

lanzi said...

I can get LOTRO Gold cheaply.
Yesterday i bought Lord Of The Rings Gold for my brother.
i hope him like it. i like the cheap Lord Of The Rings Gold very much.
I usuallybuy LOTRO Gold and keep it in my store.
I can get ro zeny cheaply,
Yesterday i want to buy ragnarok zenyfor my brother.
i hope him like it. i will buy iro zeny for him
as birthday present. i like the ragnarok online zeny very much.
I usually buy cheap zeny and keep it in my store.

春香 said...

Making aoc gold is the old question : Honestly there is no fast way to make lots of conan gold. Sadly enough a lot of the people that all of a sudden come to with millions of age of conan gold almost overnight probably duped . Although there are a lot of ways to make lots of cheap aoc gold here I will tell you all of the ways that I know and what I do to buyaoc money.

春香 said...

As a new player , you may need some game guides or information to enhance yourself.
World of Kung fu Gold is one of the hardest theme for every class at the beginning . You must have a good way to manage your WoKf gold.If yor are a lucky guy ,you can earn so many buy World of Kung fu Gold by yourself . But if you are a not , I just find a nice way to cheap World of Kung fu Gold. If you need , you can buy World of Kung fu money at our website . Go to the related page and check the detailed information . Once you have any question , you can connect our customer service at any time .

xw said...

latale online gold in the game. We know, the latale gold can exchange the real money of the reality. The world you are enjoying in latale money can entertainment. This economic structure lead buy latale online gold has one kinds of real value. You can use cheap latale gold to purchase various items of course.
The 12sky2 Gold should be a timely evolution of the world. Please step up efforts to investigate all types of twelve sky2 Gold can be set up in the game. twelvesky2 Gold to add more rudimentary fashion. The buy 12sky2 Gold can help you combat equipment of the production. Use the cheap twelve sky2 Gold may change the door to door battle.

naliliuya said...

rohan crone has many ways for us to use. When you start the Rohan Online game, your character will be level 1. I remembered that when I started playing this Rohan game with some little cheap rohan money. My friends all told me that the best way to spend rohan online gold is a good way. But I could not like spending my own rohan online crone. If you do not like upgrading level step by step, you can cost rohan gold to help your character to reach level high.
rf gold which in RF Online Game is very popular for many players. Play this online game the premise that we have more enough rf online gold first. They are able to combine creative tools and weapons with some rf money and the Light form of universal magic. Under such sustained attacks they fell from power, yet they have bided their rf cp and time. Due to make cheap rf gold the intense gravity on their home planet, the Bellato are the smallest people.

yanhui said...

Once I played flyff, I did not know how to get strong, someone told me that you must have flyff penya. He gave me some flyff money, he said that I could buy flyff penya, but I did not have money, then I played it all my spare time. From then on, I got some flyff gold, if I did not continue to play it, I can sell cheap penya to anyone who want.


Once I played flyff, I did not know how to get strong, someone told me that you must have flyff penya. He gave me some flyff money, he said that I could buy flyff penya, but I did not have money, then I played it all my spare time. From then on, I got some flyff gold, if I did not continue to play it, I can sell cheap penya to anyone who want.

rhtehe said...

Do you know the eve isk, in the game you need the eve online isk. It can help you increase your level. My friends always asked me how to
buy eve online isk, and I do not know he spend how much money to
buy isk, when I see him in order to play the game and search which the place can buy the
cheap eve isk. I am happy with him.
Do you know the dofus kama, in the game you need the kamas. It can help you increase your level. My friends always asked me how to buy dofus kamas, and I do not know he spend how much money to buy the
dofus gold, when I see him in order to play the game and search which the place can buy the
cheap kamas. I am happy with him.

li said...

What do you know requiem gold. And do you want to know? You can get requiem lant here. And welcome to our website, here you can play games, and you will get requiem money to play game. I know cheap requiem lant, and it is very interesting. Do you want a try, come and view our website, and you will learn much about requiem online gold.

li said...

Do you know that the knight gold, and do you want to know? In the game many players need the knight noah to up their levels. so they often search where can buy the knight online gold, I think our website is your choice. Many friends told me that in here can knight online noah, and you will also practice your online games skills. So i hope more and more players come here to buy the cheap knight gold.

li said...

Do you want to know the magic of online games, and here you can get more angels gold. Do you want to have a try? Come on and angels online gold can make you happy. You can change a lot buy angels gold for play games. And you can use the cheap angels online gold do what you want to do in the online game.

陈凯燕 said...

Do you know cabal online alz? I like it. My brother often goes to the internet bar to buy cabal alz and play it. After school, He likes playing games using these cabal gold with his friend. One day, he give me many cabal money and play the game with me. I came to the bar following him and found buy cabal alz was so cheap.

陈凯燕 said...

Do you know cabal online alz? I like it. My brother often go to the internet bar to buy cabal alz and play it. After school, He likes playing games using these cabal gold with his friend. One day, he give me many cabal money and play the game with me. I came to the bar following him and found buy cabal alz was so cheap.

陈凯燕 said...

Do you know Asda Story gold? I like it. My brother often goes to the internet bar to buy Asda Story money and play it. After school, He likes playing games using these buy Asda Story Gold with his friend. I do not like to play it. Because I think that it not only costs much money but also spend much time. One day, he give me manycheap Asda Story gold and play the game with me.

筱娅 said...

Have you heared about a game which you need use Anarchy credits to play, and you can also borrow Anarchy Online credits from other players? But you can buy AO credits, or you will lose the choice if you do not have Anarchy online gold. If you get Anarchy gold, you can continue this game.

筱娅 said...

Have you heared about a game which you need use kal geons to play, and you can also borrow kal gold from other players? But you can buy kal online geons, or you will lose the choice if you do not have kal online gold. If you get kalonline Geons, you can continue this game.

筱娅 said...

Have you heared about a game which you need use shadow of legend Gold to play, and you can also borrow sol gold from other players? But you can buy shadow of legend Gold, or you will lose the choice if you do not have cheap shadow of legend Gold. If you get shadow of legend Gold money, you can continue this game.

youxi said...

At one time or another, I do not have the rf gold ; at the first time, I am not willing to buy rf online gold . But I do not wonder I buy the rf money , my friend thinks that I am ill. But when I have it, it carries the magic from such a group, such a link in the world, rf cp , it is the key bring you to this world. But buy cheap rf gold is the best desire that I make.

youxi said...

After separate for one year, I can not leave you, leave Scions Of Fate gold . Now I buy SOF gold again, I do not want to leave you, but at that time, I have no idea. Buy Scions Of Fate money is the thing I want to do for long time. I know that cheap SOF gold is your life. So I will try my best and do not let you pass away. In my mind, I think I buy sof gold is the fate.

youxi said...

rohan crone has many ways for us to use. When you start the Rohan Online game, your character will be level 1. I remembered that when I started playing this Rohan game with some little cheap rohan money. My friends all told me that the best way to spend rohan online gold is a good way. But I could not like spending my own rohan online crone. If you do not like upgrading level step by step, you can cost rohan gold to help your character to reach level high.

dong said...

I always believe the angel is being and 12sky2 Gold . In fact, we all like listening to the songs of milk tea twelve sky2 Gold .
Generally speaking, I think is her voice very comfortable and mood of the story twelvesky2 Gold , We feel life bit by bit, looking forward the love belonging of the life feelings buy 12sky2 Gold , you will love milk tea like me, let us love her together and play cheap twelve sky2 Gold .

dong said...

they are like me and tell me anything about them wakfu kamas, I know wakfu gold. one of my friend likes to go to play buy wakfu kamas, I can not stand praising the land and the nature wakfu money , It makes us to be wakfu kama.

dong said...

Do you know latale online gold? I like it. My brother often go to the internet bar to buy latale gold and play it. After school, He likes playing games using these latale money with his friends. I do not like to play it. Because I think that it not only costs much money but also spend much time. One day, he give me many buy latale online gold and play the game with me. I came to the bar following him and found cheap latale gold was so cheap. After that, I also go to play game with him.

GAME GOLD said...

I am so happy to get some ro zeny and the ragnarok zeny is given by my close friend who tells me that the iro zeny is the basis to enter into the game. Therefore, I should cheap zeny with the spare money and I gain some ragnarok online zeny from other players.

GAME GOLD said...

I always heard something from my neighbor that he sometimes goes to the internet bar to play the game which will use him some Solstice Kron, he usually can win a lot of Solstice Online Kron, then he let his friends all have some Solstice Gold, his friends thank him very much for introducing them the Solstice Online Gold, they usually buy Solstice Kron together. And then share their cheap Solstice Kron to each other. At last they all get some Solstice Online money than before.

GAME GOLD said...

I always heard something from my neighbor that he sometimes goes to the internet bar to play the game which will use him some mabinogi gold,he usually can win a lot of cheap mabinogi,then he let his friends all have some mabinogi money,his friends thank him very much for introducing them the buy mabinogi gold,they usually mabinogi online gold together.

J&amp;D said...

A片下載|成人影片下載|免費A片下載|日本A片|情色A片|免費A片|成人影城|成人電影|線上A片|A片免費看

米蘭情趣用品|情趣用品|情趣|飛機杯|自慰套|充氣娃娃|AV女優.按摩棒|跳蛋|潤滑液|角色扮演|情趣內衣|自慰器|穿戴蝴蝶|變頻跳蛋|無線跳蛋|電動按摩棒|情趣按摩棒|

Kevin said...

牙醫,植牙,矯正,紋身,刺青,創業,批發,皮膚科,痘痘,中醫,飛梭雷射,毛孔粗大,醫學美容,seo,關鍵字行銷,關鍵字自然排序,網路行銷,關鍵字自然排序,關鍵字行銷seo,關鍵字廣告,部落格行銷,網路行銷,seo,關鍵字行銷,關鍵字廣告,關鍵字,自然排序,部落格行銷,網路行銷,網路爆紅,牛舌餅婚紗台中婚紗,腳臭,腳臭,腳臭,腳臭,腳臭,腳臭,腳臭,中古車,二手車,中古車,二手車,高雄婚紗,搬家,搬家公司,服飾批發,團體服,街舞,融資,借貸,借錢