Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
RegexKeyword.cs
2using System.Text.RegularExpressions;
3using System.Threading.Tasks;
6
8{
12 public class RegexKeyword : Keyword
13 {
18 public RegexKeyword(string Expression)
19 {
20 this.Expression = Expression;
21 this.Parsed = new Regex(Expression, RegexOptions.IgnoreCase | RegexOptions.Singleline);
22
23 if (Expression.EndsWith(".*"))
24 {
25 string s = Expression.Substring(0, Expression.Length - 2);
26
27 this.Ignore = string.IsNullOrEmpty(s) || FullTextSearchModule.IsStopWord(s);
28 }
29 else
30 this.Ignore = false;
31
32 }
33
37 public string Expression { get; }
38
42 public Regex Parsed { get; }
43
47 public override int OrderComplexity => this.Expression.Length;
48
52 public override bool Ignore { get; }
53
55 public override bool Equals(object obj)
56 {
57 return obj is RegexKeyword k && this.Expression == k.Expression;
58 }
59
61 public override string ToString()
62 {
63 return this.Expression;
64 }
65
71 public override async Task<IEnumerable<KeyValuePair<string, TokenReferences>>> GetTokenReferences(SearchProcess Process)
72 {
75
76 if (string.IsNullOrEmpty(Preamble))
77 {
78 string[] Keys = await Process.Index.GetKeysAsync();
79
80 foreach (string Key in Keys)
81 {
82 Match M = this.Parsed.Match(Key);
83 if (M.Success && M.Index == 0 && M.Length == Key.Length)
84 {
85 foreach (KeyValuePair<string, object> P in await Process.Index.GetEntriesAsync(Key, Key + "!"))
86 {
87 if (P.Value is TokenReferences References)
88 Result.Add(new KeyValuePair<string, TokenReferences>(P.Key, References));
89 }
90 }
91 }
92 }
93 else
94 {
95 char[] Characters = Preamble.ToCharArray();
96 Characters[Characters.Length - 1]++;
97 string ToExclusive = new string(Characters);
98
99 KeyValuePair<string, object>[] Records = await Process.Index.GetEntriesAsync(Preamble, ToExclusive);
100
101 foreach (KeyValuePair<string, object> Rec in Records)
102 {
103 Match M = this.Parsed.Match(Rec.Key);
104 if (M.Success && M.Index == 0 && M.Length == Rec.Key.Length && Rec.Value is TokenReferences References)
105 Result.Add(new KeyValuePair<string, TokenReferences>(Rec.Key, References));
106 }
107 }
108
109 return Result;
110 }
111 }
112}
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:37
override int OrderComplexity
Order complexity (within category) of keyword
Definition: RegexKeyword.cs:47
RegexKeyword(string Expression)
Represents a wildcard keyword.
Definition: RegexKeyword.cs:18
override bool Ignore
If keyword should be ignored.
Definition: RegexKeyword.cs:52
override async Task< IEnumerable< KeyValuePair< string, TokenReferences > > > GetTokenReferences(SearchProcess Process)
Gets available token references.
Definition: RegexKeyword.cs:71
Contains information about a search process.
Contains a sequence of object references that include the token in its indexed text properties.
A chunked list is a linked list of chunks of objects of type T .
Definition: ChunkedList.cs:54
void Add(T Item)
Adds an item to the collection.
Definition: ChunkedList.cs:272