Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduced per field analyzer for purpose of better Title field token…
…ization. Motive - trying to get all my new tests to pass.
- Loading branch information
Tim Lovell-Smith
committed
Dec 12, 2012
1 parent
84129e8
commit ae9ad9e
Showing
4 changed files
with
147 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using Lucene.Net.Analysis; | ||
using Lucene.Net.Analysis.Standard; | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Linq; | ||
|
||
namespace NuGetGallery | ||
{ | ||
public class PerFieldAnalyzer : PerFieldAnalyzerWrapper | ||
{ | ||
public PerFieldAnalyzer() | ||
: base(new StandardAnalyzer(LuceneCommon.LuceneVersion), CreateFieldAnalyzers()) | ||
{ | ||
} | ||
|
||
private static IDictionary CreateFieldAnalyzers() | ||
{ | ||
return new Dictionary<string, Analyzer> | ||
{ | ||
{ "Title", new TitleAnalyzer() } | ||
}; | ||
} | ||
|
||
class TitleAnalyzer : Analyzer | ||
{ | ||
private Analyzer innerAnalyzer = new StandardAnalyzer(LuceneCommon.LuceneVersion); | ||
|
||
public override TokenStream TokenStream(string fieldName, TextReader reader) | ||
{ | ||
// Split the title based on IdSeparators, then run it through the standardAnalyzer | ||
Debug.Assert(fieldName == "Title"); | ||
string title = reader.ReadToEnd(); | ||
string partiallyTokenized = string.Join(" ", title.Split(LuceneIndexingService.IdSeparators, StringSplitOptions.RemoveEmptyEntries)); | ||
return innerAnalyzer.TokenStream(fieldName, new StringReader(partiallyTokenized)); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters