Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
RegexKeyword.cs
1using System.Collections.Generic;
2using System.Text.RegularExpressions;
3using System.Threading.Tasks;
5
7{
11 public class RegexKeyword : Keyword
12 {
17 public RegexKeyword(string Expression)
18 {
19 this.Expression = Expression;
20 this.Parsed = new Regex(Expression, RegexOptions.IgnoreCase | RegexOptions.Singleline);
21
22 if (Expression.EndsWith(".*"))
23 {
24 string s = Expression.Substring(0, Expression.Length - 2);
25
26 this.Ignore = string.IsNullOrEmpty(s) || FullTextSearchModule.IsStopWord(s);
27 }
28 else
29 this.Ignore = false;
30
31 }
32
36 public string Expression { get; }
37
41 public Regex Parsed { get; }
42
46 public override int OrderComplexity => this.Expression.Length;
47
51 public override bool Ignore { get; }
52
54 public override bool Equals(object obj)
55 {
56 return obj is RegexKeyword k && this.Expression == k.Expression;
57 }
58
60 public override string ToString()
61 {
62 return this.Expression;
63 }
64
70 public override async Task<IEnumerable<KeyValuePair<string, TokenReferences>>> GetTokenReferences(SearchProcess Process)
71 {
73 LinkedList<KeyValuePair<string, TokenReferences>> Result = new LinkedList<KeyValuePair<string, TokenReferences>>();
74
75 if (string.IsNullOrEmpty(Preamble))
76 {
77 string[] Keys = await Process.Index.GetKeysAsync();
78
79 foreach (string Key in Keys)
80 {
81 Match M = this.Parsed.Match(Key);
82 if (M.Success && M.Index == 0 && M.Length == Key.Length)
83 {
84 foreach (KeyValuePair<string, object> P in await Process.Index.GetEntriesAsync(Key, Key + "!"))
85 {
86 if (P.Value is TokenReferences References)
87 Result.AddLast(new KeyValuePair<string, TokenReferences>(P.Key, References));
88 }
89 }
90 }
91 }
92 else
93 {
94 char[] Characters = Preamble.ToCharArray();
95 Characters[Characters.Length - 1]++;
96 string ToExclusive = new string(Characters);
97
98 KeyValuePair<string, object>[] Records = await Process.Index.GetEntriesAsync(Preamble, ToExclusive);
99
100 foreach (KeyValuePair<string, object> Rec in Records)
101 {
102 Match M = this.Parsed.Match(Rec.Key);
103 if (M.Success && M.Index == 0 && M.Length == Rec.Key.Length && Rec.Value is TokenReferences References)
104 Result.AddLast(new KeyValuePair<string, TokenReferences>(Rec.Key, References));
105 }
106 }
107
108 return Result;
109 }
110 }
111}
This filter selects objects that have a named field matching a given regular expression.
static string GetRegExConstantPrefix(string RegularExpression, Regex Regex)
Gets any constant prefix from a regular expression. This prefix
Full-text search module, controlling the life-cycle of the full-text-search engine.
Abstract base class for keywords.
Definition: Keyword.cs:11
virtual async Task< bool > Process(SearchProcess Process)
Processes the keyword in a search process.
Definition: Keyword.cs:67
string Expression
String representation of regex expression.
Definition: RegexKeyword.cs:36
override int OrderComplexity
Order complexity (within category) of keyword
Definition: RegexKeyword.cs:46
RegexKeyword(string Expression)
Represents a wildcard keyword.
Definition: RegexKeyword.cs:17
override bool Ignore
If keyword should be ignored.
Definition: RegexKeyword.cs:51
override async Task< IEnumerable< KeyValuePair< string, TokenReferences > > > GetTokenReferences(SearchProcess Process)
Gets available token references.
Definition: RegexKeyword.cs:70
Contains information about a search process.
Contains a sequence of object references that include the token in its indexed text properties.