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:**- you’ll find the sample project in the Samples solution folder:


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:

 2public IEnumerable<string> SplitWords(string text)
 4    var builder = new StringBuilder();
 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        }
14        builder.Append(character);
15    }
17    if (builder.Length > 0)
18    {
19        yield return builder.ToString();
20    }

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:

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:


And also a combination of capital letters and partial words:


That’s all for now - any questions?