LIFTI: Searching Pascal-cased words

Share on:

This post will show how LIFTI can be adapted to index and search upon Pascal-cased words, similar to Visual Studio 2010’s Navigate To window. (Or Resharper’s Go to symbol command, if you’re so inclined)

The code for this sample can be found in the Lifti solution:* http://lifti.codeplex.com/SourceControl/list/changesets*- you’ll find the sample project in the Samples solution folder:

image_thumb9_thumb

The way the default word splitter works is by breaking a phrase into separate words wherever whitespace characters appear - by changing this behaviour to break on changes in capitalisation, we’re pretty much all the way there:

 1
 2public IEnumerable<string> SplitWords(string text)
 3{
 4    var builder = new StringBuilder();
 5
 6    foreach (var character in text)
 7    {
 8        if (Char.IsUpper(character) && builder.Length > 0)
 9        {
10            yield return builder.ToString();
11            builder.Length = 0;
12        }
13
14        builder.Append(character);
15    }
16
17    if (builder.Length > 0)
18    {
19        yield return builder.ToString();
20    }
21}

The sample project VS2010MethodIndexer indexes all the methods in all the assemblies currently loaded into a FullTextIndexer instance configured to use the new Pascal case word splitter:

1
2this.index = new FullTextIndexer<MethodInfo>(m => m.Name);
3this.index.WordSplitter = new PascalCaseWordSplitter();

Using the UI you’re able to search on just the capital letters of a method name:

image_thumb7_thumb

And also a combination of capital letters and partial words:

image_thumb6_thumb

That’s all for now - any questions?