-
Notifications
You must be signed in to change notification settings - Fork 9
/
ExampleMethods.cs
149 lines (107 loc) · 5.84 KB
/
ExampleMethods.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Lucene.Net.Documents;
namespace LukeMapper
{
public class ExampleMethods
{
public static Document MapperFunction(Poco obj)
{
var doc = new Document();
//doc.Add(new Field("PropInt", obj.PropInt.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
//doc.Add(new Field("PropNullInt", obj.PropNullInt.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
//doc.Add(new Field("PropString", obj.PropString, Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
//doc.Add(new Field("PropDt", LukeMapper.ToDateString(obj.PropDt), Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
//doc.Add(new Field("Int", obj.Int.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
//doc.Add(new Field("NullInt", obj.NullInt.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
//doc.Add(new Field("String", obj.String, Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
//doc.Add(new Field("Dt", LukeMapper.ToDateString(obj.Dt), Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
//doc.Add(new Field("NullDt", obj.NullDt.HasValue ? LukeMapper.ToDateString(obj.NullDt.Value) : "", Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
//doc.Add(new Field("PropNullDt", obj.PropNullDt.HasValue ? LukeMapper.ToDateString(obj.PropNullDt.Value) : "", Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
//doc.Add(new Field("Char", obj.Char.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
//doc.Add(new Field("PropChar", obj.PropChar.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
//doc.Add(new Field("NullChar", obj.NullChar.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
//doc.Add(new Field("PropNullChar", obj.PropNullChar.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
doc.Add(new Field("Bl", obj.Bl.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
doc.Add(new Field("PropBl", obj.PropBl.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
doc.Add(new Field("NullBl", obj.NullBl.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
doc.Add(new Field("PropNullBl", obj.PropNullBl.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
return doc;
}
public static Document CustomMapperFunction(TestCustomSerializerClass obj)
{
var doc = new Document();
doc.Add(new Field("CustomList", TestCustomSerializerClass.CustomListToString(obj.PropStringList), Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
return doc;
}
public static TestCustomSerializerClass CustomDeserializeFunction(Document doc)
{
var obj = new TestCustomSerializerClass();
obj.PropStringList = TestCustomSerializerClass.StringToCustomList(doc.Get("CustomList"));
return obj;
}
public static TestCustomSerializerClass CustomMapperFunction2(Document doc)
{
var obj = new TestCustomSerializerClass();
obj.PropStringList = doc.Get("PropStringList").Split(new[] { "," }, StringSplitOptions.None).ToList();
obj.StringList = doc.Get("StringList").Split(new[] { "," }, StringSplitOptions.None).ToList();
obj.IntList = doc.Get("IntList").Split(new[] {","}, StringSplitOptions.None)
.Select(int.Parse)
.ToList();
obj.PropIntList = doc.Get("PropIntList").Split(new[] { "," }, StringSplitOptions.None)
.Select(int.Parse)
.ToList();
return obj;
}
public static Document CustomMapperFunction3(TestCustomSerializerClass obj)
{
var doc = new Document();
doc.Add(new Field("PropStringList", string.Join(",", obj.PropStringList), Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
doc.Add(new Field("StringList", string.Join(",", obj.StringList), Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
doc.Add(new Field("IntList", string.Join(",", obj.IntList), Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
doc.Add(new Field("PropIntList", string.Join(",", obj.PropIntList), Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
return doc;
}
}
public class TestCustomSerializerClass
{
public int Id { get; set; }
public List<string> StringList;
public List<string> PropStringList { get; set; }
public List<int> IntList;
public List<int> PropIntList { get; set; }
[LukeSerializer("CustomList")]
public static string CustomListToString(List<string> list)
{
return "";
}
[LukeDeserializer("CustomList")]
public static List<string> StringToCustomList(string serialized)
{
return new List<string>();
}
}
public class Poco
{
public int Int;
public int PropInt { get; set; }
public int? NullInt;
public int? PropNullInt { get; set; }
public string String;
public string PropString { get; set; }
public DateTime Dt;
public DateTime PropDt { get; set; }
public DateTime? NullDt;
public DateTime? PropNullDt { get; set; }
public char Char;
public char PropChar { get; set; }
public char? NullChar;
public char? PropNullChar { get; set; }
public bool Bl;
public bool PropBl { get; set; }
public bool? NullBl;
public bool? PropNullBl { get; set; }
}
}