This project is read-only.

Custom Search Indexing

Nov 25, 2010 at 11:32 PM

Hello, I'm trying to figure out how to store my model as a content type and I was wondering if there's a way that we can control how search indexing works.

I have a blob of text (multi-lines) and I'm thinking of separating them out with each line being it's own record. I'm concerned that if a sentence is spanning across two lines and the user is trying to search for that sentences, they won't get a match because they're get index seperately.

Can someone advice me to if this is possible or not? (or if I should approach storing my data differently)

Nov 25, 2010 at 11:40 PM


You need to create a content handler implementation like this one:

public class BodyPartHandler : ContentHandler {       
    public BodyPartHandler(IRepository<BodyPartRecord> bodyRepository) {

        OnIndexing<BodyPart>((context, bodyPart) => 
              .Add("body", bodyPart.Record.Text).RemoveTags().Analyze()
                 .Add("format", bodyPart.Record.Format).Store()

In this example, the index record (Document in Lucene) will contain two properties, "body" and "format", and you got different options to define how the index stores them. This event is called when the index service process a content item whose content type is marked as Indexable.

Concerning your blob of lines, index it in one property like the "body" field above. This content will be tokenized, wether there are lines or not..