Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
RequiredKeyword.cs
1using System.Collections.Generic;
2using System.Threading.Tasks;
4
6{
10 public class RequiredKeyword : Keyword
11 {
17 : base()
18 {
19 this.Keyword = Keyword;
20 }
21
25 public Keyword Keyword { get; }
26
30 public override bool Optional => false;
31
35 public override bool Required => true;
36
40 public override int OrderCategory => 1;
41
45 public override int OrderComplexity => this.Keyword.OrderComplexity;
46
50 public override bool Ignore => this.Keyword.Ignore;
51
53 public override bool Equals(object obj)
54 {
55 return obj is RequiredKeyword k && this.Keyword.Equals(k.Keyword);
56 }
57
59 public override string ToString()
60 {
61 return "+" + this.Keyword.ToString();
62 }
63
69 public override Task<IEnumerable<KeyValuePair<string, TokenReferences>>> GetTokenReferences(SearchProcess Process)
70 {
72 }
73
79 public override async Task<bool> Process(SearchProcess Process)
80 {
81 IEnumerable<KeyValuePair<string, TokenReferences>> Records = await this.GetTokenReferences(Process);
82
83 foreach (KeyValuePair<string, TokenReferences> Rec in Records)
84 {
85 string Token = Rec.Key;
86 TokenReferences References = Rec.Value;
87
88 int j, d = References.ObjectReferences.Length;
89
90 for (j = 0; j < d; j++)
91 {
92 ulong ObjectReference = References.ObjectReferences[j];
93
94 if (Process.IsRestricted)
95 Process.Found[ObjectReference] = true;
96
97 if (!Process.ReferencesByObject.TryGetValue(ObjectReference, out MatchInformation ByObjectReference))
98 {
99 if (Process.IsRestricted)
100 continue;
101
102 ByObjectReference = new MatchInformation();
103 Process.ReferencesByObject[ObjectReference] = ByObjectReference;
104 }
105
106 ByObjectReference.AddTokenReference(new TokenReference()
107 {
108 Count = References.Counts[j],
109 LastBlock = References.LastBlock,
111 Timestamp = References.Timestamps[j],
112 Token = Token
113 });
114 }
115 }
116
117 if (Process.IsRestricted)
118 {
119 LinkedList<ulong> ToRemove = null;
120
121 foreach (ulong ObjectReference in Process.ReferencesByObject.Keys)
122 {
123 if (!Process.Found.ContainsKey(ObjectReference))
124 {
125 if (ToRemove is null)
126 ToRemove = new LinkedList<ulong>();
127
128 ToRemove.AddLast(ObjectReference);
129 }
130 }
131
132 if (!(ToRemove is null))
133 {
134 foreach (ulong ObjectReference in ToRemove)
135 Process.ReferencesByObject.Remove(ObjectReference);
136 }
137 }
138
139 if (Process.ReferencesByObject.Count == 0)
140 return false;
141
142 Process.IncRestricted();
143
144 return true;
145 }
146
147 }
148}
Abstract base class for keywords.
Definition: Keyword.cs:11
virtual bool Ignore
If keyword should be ignored.
Definition: Keyword.cs:47
virtual int OrderComplexity
Order complexity (within category) of keyword
Definition: Keyword.cs:42
abstract Task< IEnumerable< KeyValuePair< string, TokenReferences > > > GetTokenReferences(SearchProcess Process)
Gets available token references.
override async Task< bool > Process(SearchProcess Process)
Processes the keyword in a search process.
override bool Ignore
If keyword should be ignored.
override Task< IEnumerable< KeyValuePair< string, TokenReferences > > > GetTokenReferences(SearchProcess Process)
Gets available token references.
override int OrderComplexity
Order complexity (within category) of keyword
RequiredKeyword(Keyword Keyword)
Represents a required keyword.
override int OrderCategory
Order category of keyword
Contains information about a search process.
Contains a reference to an indexed object.
Contains matching information about a document in a search.
Contains a sequence of object references that include the token in its indexed text properties.
DateTime[] Timestamps
Timestamps when corresponding object refernces were indexed.
uint[] Counts
Token counts for respective object reference.
ulong[] ObjectReferences
References to objects containing the token.
uint LastBlock
Index to last block in index representing the same token.