Lucene.Net.DocumentMapper 1.0.0

There is a newer version of this package available.
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                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Lucene.Net.DocumentMapper" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Lucene.Net.DocumentMapper --version 1.0.0                
#r "nuget: Lucene.Net.DocumentMapper, 1.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// 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

CI

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:

  1. Category2.Name:{value}
  2. Category2.Id:{value}
  3. 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:

  1. Tags.Id:{value}
  2. Tags.Name:{value}
  3. Tags.Id:{value}
  4. 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.

Version Downloads Last updated
1.0.15 455 10/9/2023
1.0.14 171 8/31/2023
1.0.13 390 5/31/2023
1.0.12 590 3/21/2022
1.0.11 1,062 3/23/2021
1.0.6 467 3/20/2021
1.0.5 651 11/29/2020
1.0.4 766 11/28/2020
1.0.3 1,475 9/27/2020
1.0.2 643 9/27/2020
1.0.1 670 9/27/2020
1.0.0 659 9/26/2020