eebcc3ac4843f1fde321c293306e39aff5d12057
[mono.git] / mcs / tools / monkeydoc / MonkeyDoc / SearchableDocument.cs
1 //
2 //
3 // SearchableDocument.cs: Abstracts our model of document from the Lucene Document 
4 //
5 // Author: Mario Sopena
6 //
7 using Lucene.Net.Documents;
8
9 namespace MonkeyDoc
10 {
11         struct SearchableDocument
12         {
13                 public string Title {
14                         get; set;
15                 }
16
17                 public string Url {
18                         get; set;
19                 }
20
21                 public string FullTitle {
22                         get; set;
23                 }
24
25                 public string HotText {
26                         get; set;
27                 }
28
29                 public string Text {
30                         get; set;
31                 }
32
33                 public string Examples {
34                         get; set;
35                 }
36
37                 public SearchableDocument Reset ()
38                 {
39                         Title = Url = FullTitle = HotText = Text = Examples = null;
40                         return this;
41                 }
42
43                 public Document LuceneDoc {
44                         get {
45                                 Document doc = new Document ();
46                                 doc.Add (UnIndexed ("title", Title));
47                                 doc.Add (UnIndexed ("url", Url));
48                                 doc.Add (UnIndexed ("fulltitle", FullTitle ?? string.Empty));
49                                 doc.Add (UnStored ("hottext", HotText));
50                                 doc.Add (UnStored ("text", Text));
51                                 doc.Add (UnStored ("examples", Examples));
52                                 return doc;
53                         }
54                 }
55
56                 static Field UnIndexed(System.String name, System.String value_Renamed)
57                 {
58                         return new Field(name, value_Renamed, Field.Store.YES, Field.Index.NO);
59                 }
60
61                 static Field UnStored(System.String name, System.String value_Renamed)
62                 {
63                         return new Field(name, value_Renamed, Field.Store.NO, Field.Index.ANALYZED);
64                 }
65         }
66 }