-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJsonAnalyzer.cs
54 lines (45 loc) · 1.69 KB
/
JsonAnalyzer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using System.IO;
using Lucene.Net.Analysis;
using Lucene.Net.Analysis.Core;
using Lucene.Net.Analysis.Standard;
using Lucene.Net.Analysis.Util;
using Lucene.Net.Util;
namespace DotJEM.Json.Index2.Analysis;
/// <summary>
///
/// </summary>
// TODO: This is a copy of https://github.com/apache/lucenenet/blob/b1476aee4fe21131899c1f43b2e06e25971b3ebe/src/Lucene.Net.Analysis.Common/Analysis/Standard/ClassicAnalyzer.cs
// followed by a trimming of unneeded features. But we should do more to make it especially useful for JSON.
public class JsonAnalyzer : Analyzer
{
public LuceneVersion Version { get; }
public int MaxTokenLength { get; set; } = 4096;
public JsonAnalyzer(LuceneVersion version)
{
Version = version;
}
protected override TokenStreamComponents CreateComponents(string fieldName, TextReader reader)
{
ClassicTokenizer src = new (Version, reader);
src.MaxTokenLength = MaxTokenLength;
TokenStream tok = new ClassicFilter(src);
tok = new LowerCaseFilter(Version, tok);
return new TokenStreamComponentsAnonymousClass(this, src, tok);
}
private sealed class TokenStreamComponentsAnonymousClass : TokenStreamComponents
{
private readonly JsonAnalyzer analyzer;
private readonly ClassicTokenizer src;
public TokenStreamComponentsAnonymousClass(JsonAnalyzer analyzer, ClassicTokenizer src, TokenStream tok)
: base(src, tok)
{
this.analyzer = analyzer;
this.src = src;
}
protected override void SetReader(TextReader reader)
{
src.MaxTokenLength = analyzer.MaxTokenLength;
base.SetReader(reader);
}
}
}