Implementing IFilter

by Matt 12. December 2006 18:54

Last time on the Windows Desktop Search show, IUrlAccessor was dishing out IFilter interfaces.

The good news is this is the last of the core interfaces a protocol handler has to implement - that's right, the theory is almost over. There'll be a test later, though.

IFilter is the work horse of desktop search - it's how WDS supports lots of different file formats. Here's the interface:

interface IFilter: IUnknown
{
    SCODE Init([in] ULONG grfFlags,
               [in] ULONG cAttributes,
               [in, size_is(cAttributes), unique] FULLPROPSPEC const * aAttributes,
               [out] ULONG *pFlags);
    SCODE GetChunk([out] STAT_CHUNK *pStat);
    SCODE GetText([in, out] ULONG *pcwcBuffer,
                  [out, size_is(*pcwcBuffer)] WCHAR *awcBuffer);
    SCODE GetValue([out] PROPVARIANT **ppPropValue);
    SCODE BindRegion([in] FILTERREGION origPos,
                     [in] REFIID riid,
                     [out] void ** ppunk);
}

BindRegion's the easiest method - it's reserved. Just return E_NOTIMPL.

Init is surprisingly complex. The flags value can modify some of the behaviour of the filter. If cAttributes is non-zero, the aAttributes array contains the list of properties to retrieve - the caller isn't interested in any others. If neither flags nor attributes are specified, the default PSGUID_STORAGE set of property attributes should be returned. These are a default set that include things such as modified time, size and contents. They're defined in stgprop.h in the Platform SDK (it looks like it's missing from the lately released Windows SDK, which replaces the Platform SDK - we might need this later). It returns a flag to say whether or not the file has OLE properties attached to it. This is only really relevant for structured storage files (like Word documents), so we will probably always return 0 here.

The remaining methods are called in a loop. GetChunk is called to continue parsing the file until it finds the next interesting "chunk", and it returns what it's found in the STAT_CHUNK parameter. This structure is rather busy, so we'll just look at the edited highlights; there's a chunk type - text or value. A text chunk is the main content, the body of the document. If it's one of those, GetText is called, and the text is returned back in a Unicode buffer. If it's a value chunk, the STAT_CHUNK will have a FULLPROPSPEC member which will contain a property set id and a property index. The property set id is a GUID which describes a set of properties, like a category. The index is just an integer value that represents a property within the property set. An example of a FULLPROPSPEC is the PSGUID_STORAGE property set and the PID_STG_SIZE index. No prizes for guessing what this represents. The value of the property is returned as a PROPVARIANT in the call to GetValue - this allows data types other than strings to be returned, such as dates and numbers. Both GetText and GetValue always work on the current chunk, which means the object has state, which means it's apartment threaded. (I have a feeling we're going to have to take a look at threading soon enough). Once the whole file is parsed, GetChunk returns FILTER_E_END_OF_CHUNKS.

There's actually quite a bit more to this interface than I've just described. Each method has a couple of different return codes, and GetText and GetValue can be called multiple times, depending on the size of the content or the number of properties (e.g. keywords). I don't intend this to be an exhaustive guide to writing an IFilter, just an overview. Pay MSDN a visit and Google is always your friend. And then you need to know what the standard property sets are. You can find these in the Windows SDK (WDS v3) and the Platform SDK (WDS v2) as defines beginning with PSGUID or FMTID - shlguid.h has loads.

And then there's a great big question that especially relates to protocol handlers - what if the item you're trying to parse isn't a document? What if it's a directory?

Tags:

Windows Desktop Search

Comments (35) -

Wedding program samples
Wedding program samples
2/11/2011 8:31:40 PM #

Part of the reason that our politics seems so tough right now and facts and science and argument does not seem to be winning the day all the time is because we're hardwired not to always think clearly when we're scared. And the country's scared.

Reply

articles francais
articles francais
2/27/2011 10:18:44 PM #

Bonjour, Existe-t-il d'autres sites proposant plus d'informations sur ce thème? Merci pour l'entraide.

Reply

best suv reviews
best suv reviews
7/20/2011 10:24:02 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

best hybrid cars 2011
best hybrid cars 2011
7/22/2011 4:24:02 AM #

Hi,what an excellent article this is,I found it on bing and I like it very much,I agree with what you have said, lots of things will be learned form your site,but I still have some questions with the last part,can you explain it for me ?I will appreciate your answer,and I will be back again!

Reply

free i pad
free i pad
7/23/2011 12:52:21 PM #

it ti permette di orientarti con semplicità nel pulviscolare niverso di Moncler.Troverai le indicazioni per lo spaccio o negozio Moncler più vicino a casa tua felpe moncler, pantaloni e abbigliamento sportivo.

Reply

iphone4 case
iphone4 case
7/28/2011 2:33:20 AM #

it ti permette di orientarti con semplicità nel pulviscolare niverso di Moncler.Troverai le indicazioni per lo spaccio o negozio Moncler più vicino a casa tua felpe moncler, pantaloni e abbigliamento sportivo.

Reply

LAURENCE  Debora
LAURENCE Debora
7/30/2011 9:27:51 AM #

Argent: faites de l’argent avec votre annuaire via allopass et encore plus...annuaires.

Reply

DEBORA Laurence
DEBORA Laurence
8/9/2011 7:15:54 PM #

Recevoir la newsletter et les informations des partenaires de annuaires-gratuit.com

Reply

DEBORA Laurence
DEBORA Laurence
8/9/2011 7:24:03 PM #

Recevoir la newsletter et les informations des partenaires de annuaires-gratuit.com

Reply

DEBORA Laurence
DEBORA Laurence
8/9/2011 7:25:00 PM #

Recevoir la newsletter et les informations des partenaires de annuaires-gratuit.com

Reply

DEBORA Laurence
DEBORA Laurence
8/9/2011 7:33:19 PM #

Recevoir la newsletter et les informations des partenaires de annuaires-gratuit.com

Reply

DEBORA Laurence
DEBORA Laurence
8/9/2011 9:18:17 PM #

Recevoir la newsletter et les informations des partenaires de annuaires-gratuit.com

Reply

DEBORA Laurence
DEBORA Laurence
8/13/2011 8:53:20 AM #

Le système d'Enchère automatique sibeys.com, vendez aux enchères vos objets neuf.

Reply

DEBORA Laurence
DEBORA Laurence
8/13/2011 9:00:40 AM #

Le système d'Enchère automatique sibeys.com, vendez aux enchères vos objets neuf.

Reply

DEBORA Laurence
DEBORA Laurence
8/13/2011 9:01:33 AM #

Le système d'Enchère automatique sibeys.com, vendez aux enchères vos objets neuf.

Reply

DEBORA Laurence
DEBORA Laurence
8/13/2011 9:07:50 AM #

Le système d'Enchère automatique sibeys.com, vendez aux enchères vos objets neuf.

Reply

DEBORA Laurence
DEBORA Laurence
8/13/2011 10:59:35 AM #

Le système d'Enchère automatique sibeys.com, vendez aux enchères vos objets neuf.

Reply

Anthony Passero
Anthony Passero
10/7/2011 5:50:00 AM #

I am really enjoying the theme/design of your website. Do you ever run into any browser compatibility issues? A small number of my blog audience have complained about my site not operating correctly in Explorer but looks great in Chrome. Do you have any recommendations to help fix this problem?

Reply

monster dr dre
monster dr dre
10/30/2011 4:39:54 PM #

It’s not easy to change friendship into love. But it's even harder to turn love into friendship.

Reply

Best apps
Best apps
11/26/2011 8:36:51 AM #

Good job  , amazing Post !!!

Reply

Philix
Philix United States
11/18/2015 2:48:57 PM #

Great Website

Reply

philix
philix United States
11/20/2015 5:47:47 PM #

wonderful site.

Reply

philix
philix United States
11/27/2015 7:50:02 PM #

Superb Website

Reply

Christin Boxwell
Christin Boxwell United States
1/15/2016 7:19:30 AM #

getting laid AWSOME

Reply

Rico Petronis
Rico Petronis United States
1/15/2016 8:31:06 AM #

I can't wait to read this masterpiece. Ordering off the menu at fast food restaurants and old dangerous playground equipment have to be in the book!

Reply

Importante empresa de alimentos requiere aprendices del SENA de instituciones avaladas de especialidades como asistencia administrativa, contabilidad y finanzas, recursos humanos, mesa y bar, procesamiento de alimentos, cocina afines. Se solicita URGENTE aprendiz SENA (técnico tecnólogo) en nomina, con experiencia en el manejo de temas de seguridad social y otros, relacionados con el área. Se realiza contrato por prestación de servicios con pagos acordes a la entrega de los productos y compromisos contractuales.

Reply

Pedro Wiman
Pedro Wiman United States
7/16/2016 5:18:46 PM #

Great post. Quite refreshing provided all the duplicate written content out there. Cheers for doing something original.

Reply

Scott Weldeen
Scott Weldeen United States
7/20/2016 7:43:04 AM #

Take my word for it, it's not as easy as you think

Reply

eczema treatment
eczema treatment United States
8/11/2016 9:13:19 AM #

How can I copyright all original content current and future on my website?

Reply

nutra forskolin
nutra forskolin United States
9/7/2016 3:38:57 PM #

My friend put together my small business website in dreamweaver for me.  However, I now want to maintain it myself---my friend recommended putting it into wordpress.  However, I am not a web designer and have no idea what I'm doing---is there an easy way to convert my current website from dreamweaver to wordpress (for someone who can't read code, etc). . Thanks!.

Reply

how to potty train
how to potty train United States
9/9/2016 5:59:17 PM #

What is a blogging site where people give a lot of quick feedback?

Reply

Dominica Caraveo
Dominica Caraveo United States
9/29/2016 2:55:15 AM #

It's a lot a lot better than other weather apps and works on just about any operating system. Everyday new features are being introduced to facilitate more and more people. Next, you have to write the programming code and UI code for you Android app.

Reply

Carroll B. Merriman
Carroll B. Merriman United States
10/3/2016 5:22:22 AM #

I'll gear this review to 2 types of people: current Zune owners who are considering an upgrade, and people trying to decide between a Zune and an iPod. (There are other players worth considering out there, like the Sony Walkman X, but I hope this gives you enough info to make an informed decision of the Zune vs players other than the iPod line as well.)

Reply

Nguyet Geldrich
Nguyet Geldrich United States
7/15/2018 8:17:40 AM #

good stuff. I will make sure to bookmark your blog.

Reply

Milan Willenbrock
Milan Willenbrock United States
7/21/2018 11:45:16 AM #

I got what you mean,saved to fav, very decent site.

Reply

Add comment

biuquote
  • Comment
  • Preview
Loading

Rel=Me

Month List

RecentComments

Comment RSS