Skip to main content

Indexes: Additional Assemblies

Syntax

Additional assemblies are defined using the AdditionalAssembly object.

public class AdditionalAssembly
{
public static AdditionalAssembly FromRuntime(string assemblyName,
HashSet<string> usings = null);

public static AdditionalAssembly FromPath(string assemblyPath,
HashSet<string> usings = null);

public static AdditionalAssembly FromNuGet(string packageName,
string packageVersion,
string packageSourceUrl = null,
HashSet<string> usings = null);
}
ParameterTypeDescription
assemblyNamestringThe name of an assembly to import from runtime
assemblyPathstringLocal path to an assembly
packageNamestringName of a NuGet package to import
packageVersionstringThe version number of the NuGet package - optional
packageSourceUrlstringThe URL of the package's original source - optional
usingsHashSet<string>A set of namespaces to attach to the compiled index with using - optional
The AdditionalAssemblys are collected in AdditionalAssemblies, a property of
IndexDefinition:
public HashSet<AdditionalAssembly> AdditionalAssemblies;

Examples

Basic Example

This index is able to use the method GetFileName() from the class Path because the namespace System.IO has been imported as an additional assembly. It takes a string file path and retrieves just the file name and extension.

var runtimeindex = new IndexDefinition
{
Name = "Dog_Pictures",
Maps = { @"
from user in docs.Users
let fileName = Path.GetFileName(user.ImagePath)
where fileName = ""My_Dogs.jpeg""
select new {
user.Name,
fileName
}"
},
AdditionalAssemblies = {
AdditionalAssembly.FromRuntime("System.IO")
}
};

Complex Example

This index uses a machine learning algorithm imported from NuGet that can recognize the contents of images and classify them with an appropriate tag. These tags are then stored in the index just like any other term.

store.Maintenance.Send(new PutIndexesOperation(new IndexDefinition
{
Name = "Photographs/Tags",
Maps =
{
@"
from p in docs.Photographs
let photo = LoadAttachment(p, ""photo.png"")
where photo != null
let classified = ImageClassifier.Classify(photo.GetContentAsStream())
select new {
e.Name,
Tag = classified.Where(x => x.Value > 0.75f).Select(x => x.Key),
_ = classified.Select(x => CreateField(x.Key, x.Value))
}"
},
AdditionalSources = new System.Collections.Generic.Dictionary<string, string>
{
{
"ImageClassifier",
@"
public static class ImageClassifier
{
public static IDictionary<string, float> Classify(Stream s)
{
// returns a list of descriptors with a
// value between 0 and 1 of how well the
// image matches that descriptor.
}
}"
}

},
AdditionalAssemblies =
{
AdditionalAssembly.FromRuntime("System.Memory"),
AdditionalAssembly.FromNuGet("System.Drawing.Common", "4.7.0"),
AdditionalAssembly.FromNuGet("Microsoft.ML", "1.5.2")
}
}));

Pre-Release Packages

Additional assemblies are allowed to include pre-release packages.

AdditionalAssemblies = {
AdditionalAssembly.FromNuGet("FlexiMvvm.Common.PreRelease", "0.10.8-prerelease")
}