@@ -51,7 +51,7 @@ public Lite<TypeEntity>? EntityType
51
51
public MList<PanelPartEmbedded> Parts { get; set; } = new MList<PanelPartEmbedded>();
52
52
53
53
[Ignore, QueryableProperty]
54
-
public MList<TokenEquivalenceGroupEntity> TokenEquivalences { get; set; } = new MList<TokenEquivalenceGroupEntity>();
54
+
public MList<TokenEquivalenceGroupEntity> TokenEquivalencesGroups { get; set; } = new MList<TokenEquivalenceGroupEntity>();
55
55
56
56
[UniqueIndex]
57
57
public Guid Guid { get; set; } = Guid.NewGuid();
@@ -105,6 +105,19 @@ protected override void ChildCollectionChanged(object? sender, NotifyCollectionC
105
105
}
106
106
107
107
108
+
internal void ParseData(Func<QueryEntity, QueryDescription?> getDescription)
109
+
{
110
+
foreach (var f in TokenEquivalencesGroups)
111
+
{
112
+
foreach (var t in f.TokenEquivalences)
113
+
{
114
+
var description = getDescription(t.Query);
115
+
if (description != null)
116
+
t.Token.ParseData(this, description, SubTokensOptions.CanElement);
117
+
}
118
+
}
119
+
}
120
+
108
121
[Ignore]
109
122
bool invalidating = false;
110
123
protected override void ChildPropertyChanged(object sender, PropertyChangedEventArgs e)
@@ -151,7 +164,9 @@ public XElement ToXml(IToXmlContext ctx)
151
164
EmbeddedInEntity == null ? null! : new XAttribute("EmbeddedInEntity", EmbeddedInEntity.Value.ToString()),
152
165
new XAttribute("CombineSimilarRows", CombineSimilarRows),
153
166
CacheQueryConfiguration?.ToXml(ctx),
154
-
new XElement("Parts", Parts.Select(p => p.ToXml(ctx))));
167
+
new XElement("Parts", Parts.Select(p => p.ToXml(ctx))),
168
+
new XElement(nameof(TokenEquivalencesGroups), TokenEquivalencesGroups.Select(teg => teg.ToXml(ctx)))
169
+
);
155
170
}
156
171
157
172
@@ -165,6 +180,8 @@ public void FromXml(XElement element, IFromXmlContext ctx)
165
180
CombineSimilarRows = element.Attribute("CombineSimilarRows")?.Let(a => bool.Parse(a.Value)) ?? false;
166
181
CacheQueryConfiguration = CacheQueryConfiguration.CreateOrAssignEmbedded(element.Element(nameof(CacheQueryConfiguration)), (cqc, elem) => cqc.FromXml(elem));
167
182
Parts.Synchronize(element.Element("Parts")!.Elements().ToList(), (pp, x) => pp.FromXml(x, ctx));
183
+
TokenEquivalencesGroups.Synchronize(element.Element(nameof(TokenEquivalencesGroups))?.Elements().ToList() ?? new List<XElement>(), (teg, x) => teg.FromXml(x, ctx));
184
+
ParseData(q => ctx.GetQueryDescription(q));
168
185
}
169
186
170
187
protected override string? PropertyValidation(PropertyInfo pi)
@@ -183,6 +200,16 @@ public void FromXml(XElement element, IFromXmlContext ctx)
183
200
return ValidationMessage._0ShouldBeNullWhen1IsSet.NiceToString(pi.NiceName(), NicePropertyName(() => EntityType));
184
201
}
185
202
203
+
if(pi.Name == nameof(TokenEquivalencesGroups))
204
+
{
205
+
var dups = TokenEquivalencesGroups
206
+
.SelectMany(a => a.TokenEquivalences).Select(a => a.Token.Token).NotNull()
207
+
.GroupCount(a => a).Where(gr => gr.Value > 1).ToString(a => a.Value + " x " + a.Key.FullKey(), "\n");
208
+
209
+
if (dups.HasText())
210
+
return "Duplicated tokens: " + dups;
211
+
}
212
+
186
213
return base.PropertyValidation(pi);
187
214
}
188
215
}
@@ -270,18 +297,57 @@ public enum DashboardEmbedededInEntity
270
297
[EntityKind(EntityKind.Part, EntityData.Master)]
271
298
public class TokenEquivalenceGroupEntity : Entity
272
299
{
273
-
[NotNullValidator(DisabledInModelBinder = true)]
300
+
[NotNullValidator(Disabled = true)]
274
301
public Lite<DashboardEntity> Dashboard { get; set; }
275
302
276
303
public InteractionGroup? InteractionGroup { get; set; }
277
304
278
305
[PreserveOrder, NoRepeatValidator, CountIsValidator(ComparisonType.GreaterThan, 1)]
279
306
public MList<TokenEquivalenceEmbedded> TokenEquivalences { get; set; } = new MList<TokenEquivalenceEmbedded>();
307
+
308
+
internal void FromXml(XElement x, IFromXmlContext ctx)
309
+
{
310
+
InteractionGroup = x.Attribute("InteractionGroup")?.Value.ToEnum<InteractionGroup>();
311
+
TokenEquivalences.Synchronize(x.Elements("TokenEquivalence").ToList(), (teg, x) => teg.FromXml(x, ctx));
312
+
}
313
+
314
+
internal XElement ToXml(IToXmlContext ctx)
315
+
{
316
+
return new XElement("TokenEquivalenceGroup",
317
+
InteractionGroup == null ? null : new XAttribute(nameof(InteractionGroup), InteractionGroup.Value.ToString()),
318
+
TokenEquivalences.Select(te => te.ToXml(ctx)));
319
+
}
320
+
321
+
protected override string? PropertyValidation(PropertyInfo pi)
322
+
{
323
+
if(pi.Name == nameof(TokenEquivalences))
324
+
{
325
+
var list = TokenEquivalences.Select(a => a.Token.Token.Type.UnNullify().CleanType()).Distinct().ToList();
326
+
if(list.Count > 1)
327
+
{
328
+
if (!list.Any(t => list.All(t2 => t.IsAssignableFrom(t2))))
329
+
return "Types " + list.CommaAnd(t => t.TypeName()) + " are not compatible";
330
+
}
331
+
}
332
+
333
+
return base.PropertyValidation(pi);
334
+
}
280
335
}
281
336
282
337
public class TokenEquivalenceEmbedded : EmbeddedEntity
283
338
{
284
339
public QueryEntity Query { get; set; }
285
340
286
-
public QueryTokenEmbedded QueryToken { get; set; }
341
+
public QueryTokenEmbedded Token { get; set; }
342
+
343
+
internal void FromXml(XElement element, IFromXmlContext ctx)
344
+
{
345
+
Query = ctx.GetQuery(element.Attribute("Query")!.Value);
346
+
Token = new QueryTokenEmbedded(element.Attribute("Token")!.Value);
347
+
}
348
+
349
+
internal XElement ToXml(IToXmlContext ctx) => new XElement("TokenEquivalence",
350
+
new XAttribute("Query", Query.Key),
351
+
new XAttribute("Token", Token.Token.FullKey())
352
+
);
287
353
}
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4