Implementing ISearchProtocol

by Matt 8. November 2006 18:02

Now that we've got the protocol handler registered, and we've told WDS the default url to start searching against, we need to implement ISearchProtocol. Fortunately, that's very easy:

STDMETHODIMP Init(TIMEOUT_INFO *pTimeoutInfo, IProtocolHandlerSite *pProtocolHandlerSite,
	PROXY_INFO *pProxyInfo)
{
	ATLTRACE(myTraceProtocolHandler,0,_T("ISearchProtocol::Init\n"));

	// We don't have anything to initialise, or to cleanup from an unexpected termination
	return S_OK;
}

STDMETODIMP CreateAccessor(...)
{
	...
}

STDMETHODIMP CloseAccessor(IUrlAccessor *pAccessor)
{
	ATLTRACE(myTraceProtocolHandler,0,_T("ISearchProtocol::CloseAccessor\n"));

	// We don't want to do anything with this, just let the host close it normally
	// (it calls Release). (This method gives us the chance to pool accessors)
	return S_OK;
}

STDMETHODIMP ShutDown()
{
	ATLTRACE(myTraceProtocolHandler,0,_T("ISearchProtocol::ShutDown\n"));

	// We don't have anything to clean up
	return S_OK;
}

Currently, we have nothing to setup in the initialise phase, and similarly nothing for ShutDown to do. One important thing to note is that the ShutDown method might not get called. If the host process crashes (and there is a good chance it will - there are a lot of 3rd party plugins running around here) ShutDown won't get called, so if you create anything persistent in Init, you need to clean it up on the next Init.

On the face of things, CloseAccessor is an odd method. Surely the host would just call Release on the IUrlAccessor to close it down? And indeed it will. This method allows the host to notify you that it's about to throw away the UrlAccessor. It's an opportunity for you to e.g. pool the accessor object (by AddRef-ing it and chucking it on a list). I'm not interested in this, so I just do nothing.

The biggy is of course CreateAccessor. Here's the code I missed out above:

STDMETHODIMP CreateAccessor(LPCWSTR pcwszURL, AUTHENTICATION_INFO *pAuthenticationInfo, 
	INCREMENTAL_ACCESS_INFO *pIncrementalAccessInfo, 
	ITEM_INFO *pItemInfo, IUrlAccessor **ppAccessor)
{
	ATLTRACE(myTraceProtocolHandler,0,_T("ISearchProtocol::CreateAccessor\n"));

	CComObject<CUrlAccessor> *pUrlAccessor;
	HRESULT hr=CComObject<CUrlAccessor>::CreateInstance(&pUrlAccessor);
	if(SUCCEEDED(hr))
		hr=pUrlAccessor->QueryInterface(ppAccessor);
	return hr;
}

It's a bit naive at the moment, but it starts to show the relationship between ISearchProtocol and IUrlAccessor. In comes a url, and out goes an IUrlAccessor object. Whenever you want to get access to a url, you ask the ISearchProtocol. It's kind of analogous to the win32 CreateFile function - if you want access to a file, call CreateFile, get back a handle to the file. Abstract that away from the file system, and you've got ISearchProtocol->CreateAccessor and IUrlAccessor.

This method takes a couple of interesting parameters. It's got the url and some authentication info that is really only of use if you're doing http stuff. It also includes an ITEM_INFO structure that doesn't look too useful. The important one is the INCREMENTAL_ACCESS_INFO structure. This simply contains a size and a FILETIME of the last time the search gatherer knows it was modified. If it's never been searched, this will be zero. If the item hasn't been modified since this timestamp, CreateAccessor can return PRTH_S_NOT_MODIFIED and the item will not be re-indexed. This allows WDS to use an incremental update scheme - all urls reported by your ISearchProtocol will be accessed to see if they've been updated. It's a bit brute force - think trawling your entire hard disk to see if any files have changed, so WDS also supports change notifications, which I'll get to later in the development, once I've figured out how they work. I also need to find out if the modification time is set automatically by the indexer when the url is filtered, or if I have to do somewhere in my code.

I fully expect the method shown above to get more complex - there's no support for incremental updates, for one thing, but I'm probably also going to have to create a different number of IUrlAccessor objects - one for the root, one for folders and one for feeds. All in good time...

Next up, a bit of a closer look at IUrlAccessor - what data can you get out of it, and how do you use it for indexing?

No code today - I want to look at IUrlAccessor first.

Tags:

Windows Desktop Search

Comments (37) -

Alek
Alek
11/18/2006 2:11:15 PM #

alek@zvuk.net

Can you use ISearchProtocol to implement on the fly searches? What I'm trying to do is get the results a Google search in my start menu. Also, do I have to use C++ or will C# do?

Reply

Allen Cruz
Allen Cruz
5/12/2011 2:35:19 PM #

It is a particularly useful content.  It's very beneficial and you simply have evidently performed your groundwork previous to composing that post.  I will likely need to visit and follow your upcoming articles.

Reply

billiard videos
billiard videos
5/24/2011 6:52:16 AM #

I would like to thank you for the efforts you have put in writing this web site. I am hoping the same high-grade web site post from you in the upcoming as well. In fact your creative writing abilities has encouraged me to get my own site now. Really the blogging is spreading its wings fast. Your write up is a good example of it.

Reply

best suv 2011
best suv 2011
7/20/2011 10:24:11 PM #

I wonder if he cheated on her? I remember he cheated on his previous wife with JLO so it wouldn’t be surprising.

Reply

iphone os 4
iphone os 4
7/23/2011 8:38:29 PM #

hi!,I like your writing so so much! proportion we communicate extra about your post on AOL? I require a specialist in this area to unravel my problem. May be that's you! Taking a look forward to see you.

Reply

LAURENCE  Debora
LAURENCE Debora
7/30/2011 6:37:26 PM #

ThumbShots est aussi inclus, il vous permet d'avoir un aperçu du site sur vos annuaires.

Reply

Rueben Derosa
Rueben Derosa United States
1/15/2016 3:43:50 AM #

I love the dolphin saving you one.

Reply

Wilton Megeath
Wilton Megeath United States
1/15/2016 3:47:59 AM #

Congratulations on your success! You deserve it for brightening all of my work days with something to be excited about.

Reply

Selma Houzah
Selma Houzah United States
1/15/2016 4:04:08 AM #

Well good for you! I have a lot but one I just thought of was when you lick a crease of paper so that it'll rip in a straight line and it actually tears in a frayed straight line rather than rips awkwardly. I love that bleachy taste and that bleachy satisfaction.

Reply

Rich Bowdry
Rich Bowdry United States
1/15/2016 4:15:35 AM #

Hey, congratulations Neil. This site really is something special and it's been a pleasure to share it with my readership too. Looking forward to future awesome things, and I'll send any suggestions that are sufficiently awesome.

Reply

Marylynn Okoro
Marylynn Okoro United States
1/15/2016 4:51:30 AM #

Congrats! This is such a great website, I know it will translate well into book form. Which is AWESOME!

Reply

Isreal Payor
Isreal Payor United States
1/15/2016 4:56:57 AM #

The dolphin saving you one is the best one!

Reply

Jamison Gerraro
Jamison Gerraro United States
1/15/2016 4:58:51 AM #

the style of keeping you connected with so many things of different types is awesome and you find it interesting everytime.

Reply

Janine Norwood
Janine Norwood United States
1/15/2016 5:44:17 AM #

Printing out an essay or paper, reading the first line and realizing there aren't any mistakes.<br />AWESOME!

Reply

Athena Deodato
Athena Deodato United States
1/15/2016 6:24:04 AM #

the style of keeping you connected with so many things of different types is awesome and you find it interesting everytime.

Reply

Francisco Brixner
Francisco Brixner United States
1/15/2016 6:44:17 AM #

Congrats! This is such a great website, I know it will translate well into book form. Which is AWESOME!

Reply

Kylee Marett
Kylee Marett United States
1/15/2016 7:19:37 AM #

the style of keeping you connected with so many things of different types is awesome and you find it interesting everytime.

Reply

Loida Shaneyfelt
Loida Shaneyfelt United States
1/15/2016 7:44:48 AM #

Congratulations on your success! You deserve it for brightening all of my work days with something to be excited about.

Reply

Rico Petronis
Rico Petronis United States
1/15/2016 8:29:47 AM #

getting laid AWSOME

Reply

Janine Norwood
Janine Norwood United States
1/15/2016 8:59:32 AM #

Congrats! So glad to see this site getting the recognition it deserves, the world can always use a little more awesome.

Reply

strony www Warszawa
strony www Warszawa United States
3/27/2016 2:32:35 AM #

I just could not depart your site before suggesting that I extremely loved the usual info an individual supply to your visitors? Is gonna be back frequently in order to investigate cross-check new posts

Reply

Matilde Hoesly
Matilde Hoesly United States
3/27/2016 9:46:09 AM #

I’ll right away grasp your rss feed as I can't find your email subscription hyperlink or e-newsletter service. Do you've any? Kindly let me understand so that I could subscribe. Thanks.

Reply

fast food,pomysł na biznes
fast food,pomysł na biznes United States
4/2/2016 11:18:54 PM #

Have you ever considered writing an ebook or guest authoring on other websites? I have a blog centered on the same ideas you discuss and would love to have you share some stories/information. I know my subscribers would value your work. If you are even remotely interested, feel free to shoot me an e mail.

Reply

Hermelinda Read
Hermelinda Read United States
7/17/2016 10:29:55 AM #

for everyone! Love this post.It is helpful.

Reply

the next bitcoin
the next bitcoin United States
7/20/2016 7:14:45 PM #

I love your blogging theme, where did you get a hold of it from? anyways have you heard about this unique tech like bitcoin? I searched for TrumpCoin and this site came up TrumCoin.infoI think it would be a interesting point of discussion for your readersthanks from England! Here's a few great resources <a href="htttp://www.trumpcoin.info">trumpcoin</a>; & <a href="htttp://www.trumpcoin.com">trumpcoin llc</a>

Reply

trumpcoin
trumpcoin United States
7/21/2016 2:47:16 PM #

I love your blog web template, where did you down load it from? anyways have you heard about this interesting coin similar bitcoin? I searched for TrumpCoin and this site came up TrumCoin.infoI believe it would be a thought provoking point of discussion for your readersCheers from England! Here's a few great resources <a href="htttp://www.trumpcoin.info">trumpcoin</a>; & <a href="htttp://www.trumpcoin.com">trumpcoin llc</a>

Reply

bitcoin alternative
bitcoin alternative United States
7/21/2016 2:50:41 PM #

I adore your wordpress? template, exactly where would you down load it from? eitherway have you heard about this unique currency like bitcoin? I searched for TrumpCoin and this netpage came up TrumCoin.infoI think it would be a thought provoking point of discussion for your readersCheers from England! Here's a few great resources <a href="htttp://www.trumpcoin.info">trumpcoin</a>; & <a href="htttp://www.trumpcoin.com">trumpcoin llc</a>

Reply

Troy Aprill
Troy Aprill United States
7/29/2016 6:29:13 AM #

I have the game and when I tried it on my computer, it was all broken up and crappy.  I'm thinking of buying a new computer anyway.  Does anyone know of a computer where the game works well?.

Reply

Kathie Digian
Kathie Digian United States
8/25/2016 4:16:00 AM #

Hi! This is my first visit to your post! We are a group of volunteers and starting a new initiative in a community in the same niche. Your blog provided us educational information to work on. You have done a nice job!

Reply

como quitar puntos negros
como quitar puntos negros United States
10/5/2017 2:23:41 PM #

Hello, i think that i saw you visited my weblog so i came to “return the favor”.I'm attempting to find things to enhance my website!I suppose its ok to use some of your ideas!!

Reply

Tyson F. Gautreaux
Tyson F. Gautreaux United States
12/6/2017 5:31:26 AM #

Reply

baexkitty
baexkitty United States
5/22/2018 10:08:28 PM #

She may take her panties off at any time!

Reply

natynaty
natynaty United States
7/12/2018 5:48:49 AM #

You’ve been working hard lately. All that stress has got to be eating at you. Why not take a break and enjoy some cam girls? There’s plenty of them to enjoy at http://www.camgirl.pw It’s wall to wall babes at this site. You’ll know that right away after your first visit.

Reply

Samara Mezzenga
Samara Mezzenga United States
7/15/2018 11:43:04 AM #

It?s hard to come by knowledgeable people on this subject, however, you

Reply

Kathlene Shankin
Kathlene Shankin United States
7/18/2018 8:13:31 PM #

Black on black in the Charger I'm creepin' Rub me the right way, you might get a genie B.o.B, black Houdini

Reply

Myrtle Cella
Myrtle Cella United States
7/20/2018 9:34:50 AM #

I like the helpful info you provide in your articles. I will bookmark your weblog and check again here regularly.

Reply

Jacque Tuccillo
Jacque Tuccillo United States
7/21/2018 10:40:10 AM #

Don’t wear seat belts lest you drown in your own urine?

Reply

Add comment

biuquote
  • Comment
  • Preview
Loading

Rel=Me

Month List

RecentComments

Comment RSS