Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
AddFtsProperties.cs
1using System.Threading.Tasks;
9
11{
16 {
25 public AddFtsProperties(ScriptNode Collection, ScriptNode Properties,
27 : base(new ScriptNode[] { Collection, Properties },
28 new ArgumentType[] { ArgumentType.Scalar, ArgumentType.Vector },
30 {
31 }
32
36 public override string FunctionName => nameof(AddFtsProperties);
37
41 public override string[] DefaultArgumentNames => new string[]
42 {
43 "Collection", "Properties"
44 };
45
50 public override bool IsAsynchronous => true;
51
59 {
60 return this.EvaluateAsync(Arguments, Variables).Result;
61 }
62
69 public override async Task<IElement> EvaluateAsync(IElement[] Arguments, Variables Variables)
70 {
71 string Collection = Arguments[0].AssociatedObjectValue?.ToString() ?? string.Empty;
73
74 bool Result = await Waher.Persistence.FullTextSearch.Search.AddFullTextSearch(Collection, Properties);
75
76 return Result ? BooleanValue.True : BooleanValue.False;
77 }
78
86 {
87 object Obj = Argument.AssociatedObjectValue;
88
89 if (Obj is PropertyDefinition[] Result)
90 return Result;
91
92 if (Obj is string[] Labels)
93 return PropertyDefinition.ToArray(Labels);
94
95 if (Obj is PropertyDefinition Def)
96 return new PropertyDefinition[] { Def };
97
98 if (Obj is string s)
99 return new PropertyDefinition[] { new PropertyDefinition(s) };
100
101 if (Obj is Expression Exp)
102 return new PropertyDefinition[] { new PropertyDefinition(typeof(ExpressionEvaluator).FullName, Exp.Script) };
103
104 if (Obj is LambdaDefinition Lambda0 && Lambda0.NrArguments == 1)
105 return new PropertyDefinition[] { new PropertyDefinition(typeof(LambdaEvaluator).FullName, Lambda0.SubExpression) };
106
107 if (!(Argument is IVector V))
108 throw new ScriptRuntimeException("Expected a vector of property definitions.", Node);
109
110 int i, c = V.Dimension;
111
112 Result = new PropertyDefinition[c];
113
114 for (i = 0; i < c; i++)
115 {
116 Argument = V.GetElement(i);
117 Obj = Argument.AssociatedObjectValue;
118
119 if (Obj is PropertyDefinition Def2)
120 Result[i] = Def2;
121 else if (Obj is string s2)
122 Result[i] = new PropertyDefinition(s2);
123 else if (Obj is Expression Expression)
124 Result[i] = new PropertyDefinition(typeof(ExpressionEvaluator).FullName, Expression.Script);
125 else if (Obj is LambdaDefinition Lambda && Lambda.NrArguments == 1)
126 Result[i] = new PropertyDefinition(typeof(LambdaEvaluator).FullName, Lambda.SubExpression);
127 else
128 throw new ScriptRuntimeException("Unrecognized property definition: " + Obj.GetType().FullName, Node);
129 }
130
131 return Result;
132 }
133
134 }
135}
static PropertyDefinition[] ToArray(string[] PropertyNames)
Creates an array of property definitions from an array of property names.
Evaluates property values where properties are defined as script expressions.
Evaluates property values where properties are defined as script expressions.
Static class for access to Full-Text-Search
Definition: Search.cs:68
static Task< bool > AddFullTextSearch(string CollectionName, params PropertyDefinition[] Properties)
Adds properties for full-text-search indexation.
Definition: Search.cs:253
Class managing a script expression.
Definition: Expression.cs:39
string Script
Original script string.
Definition: Expression.cs:181
Adds collection properties to the corresponding index for full-text-searching.
static PropertyDefinition[] GetPropertyDefinitions(IElement Argument, ScriptNode Node)
Gets property definitions.
override bool IsAsynchronous
If the node (or its decendants) include asynchronous evaluation. Asynchronous nodes should be evaluat...
override IElement Evaluate(IElement[] Arguments, Variables Variables)
Evaluates the function.
override string FunctionName
Name of the function
override string[] DefaultArgumentNames
Default Argument names
AddFtsProperties(ScriptNode Collection, ScriptNode Properties, int Start, int Length, Expression Expression)
Adds collection properties to the corresponding index for full-text-searching.
override async Task< IElement > EvaluateAsync(IElement[] Arguments, Variables Variables)
Evaluates the function.
Base class for multivariate funcions.
ScriptNode[] Arguments
Function arguments.
Base class for all nodes in a parsed script tree.
Definition: ScriptNode.cs:69
int Length
Length of expression covered by node.
Definition: ScriptNode.cs:101
override string ToString()
Definition: ScriptNode.cs:359
Expression Expression
Expression of which the node is a part.
Definition: ScriptNode.cs:177
int Start
Start position in script expression.
Definition: ScriptNode.cs:92
Boolean-valued number.
Definition: BooleanValue.cs:12
static readonly BooleanValue False
Constant false value.
Collection of variables.
Definition: Variables.cs:25
Basic interface for all types of elements.
Definition: IElement.cs:20
object AssociatedObjectValue
Associated object value.
Definition: IElement.cs:33
Basic interface for vectors.
Definition: IVector.cs:9
ArgumentType
Type of parameter used in a function definition or a lambda definition.
Definition: IFunction.cs:9
Definition: App.xaml.cs:4