Lucene.Net.DocumentMapper
1.0.0
See the version list below for details.
dotnet add package Lucene.Net.DocumentMapper --version 1.0.0
NuGet\Install-Package Lucene.Net.DocumentMapper -Version 1.0.0
<PackageReference Include="Lucene.Net.DocumentMapper" Version="1.0.0" />
paket add Lucene.Net.DocumentMapper --version 1.0.0
#r "nuget: Lucene.Net.DocumentMapper, 1.0.0"
// Install Lucene.Net.DocumentMapper as a Cake Addin #addin nuget:?package=Lucene.Net.DocumentMapper&version=1.0.0 // Install Lucene.Net.DocumentMapper as a Cake Tool #tool nuget:?package=Lucene.Net.DocumentMapper&version=1.0.0
Lucene.Net.DocumentMapper
Install-Package Lucene.Net.DocumentMapper
This is a simple service that helps with mapping C# Types to Lucene Documents and back. In order to wire it up with DI just call ServiceCollection.AddLuceneDocumentMapper
.
It comes with a default set of Field Mappers, but you can easily add your own and override how any property is mapped by creating a class that implements IFieldMapper
as shown here:
public class BooleanFieldMapper : AFieldMapper, IFieldMapper
{
public int Priority => 0;
public bool IsMatch(PropertyInfo propertyInfo)
{
var type = GetPropertyType(propertyInfo);
return type == typeof(bool);
}
public Field MapToField(PropertyInfo propertyInfo, object value, string name)
{
bool convertedValue = (bool)value;
return new StringField(name,
convertedValue
? Boolean.TrueString
: Boolean.FalseString, GetStore(propertyInfo));
}
public object MapFromField(Field field)
{
return Boolean.Parse(field.GetStringValue());
}
}
If you want to override a default one, you make sure that the IsMatch method returns true for a specific property and increment the priority so it takes precedence over the default mappers.
Object Mapping
Any property that is of type object
gets mapped to a JSON string in the field value, but if it has an actual type declared, that types properties will be mapped individually with dot notation.
For example if you have a BlogPost type setup like this:
public class BlogPost
{
public DateTime PublishedDate { get; set; }
public DateTimeOffset PublishedDateOffset { get; set; }
public bool IsPublished { get; set; }
public string Name { get; set; }
[Search(Tokenized = true)]
public string Body { get; set; }
public string SeoDescription { get; set; }
[Search(Store = false)]
public string SeoTitle { get; set; }
public string Excerpt { get; set; }
public string ThumbnailUrl { get; set; }
public IList<string> TagIds { get; set; }
public object Category { get; set; }
public Category Category2 { get; set; }
public IList<Tag> Tags { get; set; }
}
Category will be stored as json and Category2 will be stored as multiple fields:
- Category2.Name:{value}
- Category2.Id:{value}
- Category2.Description:{value}
Collection Mapping
For collection mapping, if the generic type is a primitive type in the instance of TagIds in the BlogPost type above, the tag ids will each be stored as an individual field all with the same name (in this case TagIds). If the collection is a complex type, then it will be similar to how complex types are stored above, instead in this case where there could be two tags, you would have these fields:
- Tags.Id:{value}
- Tags.Name:{value}
- Tags.Id:{value}
- Tags.Name:{value}
Search Attribute
The search attribute comes with two properties, Store and Tokenized. Store is set to true by default and tokenized is false by default. If you set tokenzied to true for a string field it will store the string as a text field.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Lucene.Net (>= 4.8.0-beta00012)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 3.1.8)
- Newtonsoft.Json (>= 12.0.3)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Lucene.Net.DocumentMapper:
Package | Downloads |
---|---|
Lucene.Net.IndexProvider
A simple service that helps to abstract common operations when interacting with lucene.net indexes. |
GitHub repositories
This package is not used by any popular GitHub repositories.