Lucene.Net  3.0.3
Lucene.Net is a port of the Lucene search engine library, written in C# and targeted at .NET runtime users.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Pages
DistributedSearcher.cs
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 using System;
19 using System.Collections;
20 using System.Configuration;
21 using System.IO;
22 using System.Xml;
23 using Lucene.Net.Distributed;
24 
25 namespace Lucene.Net.Distributed.Configuration
26 {
27  /// <summary>
28  /// Definition of a configurable set of search indexes made accessible by the
29  /// LuceneServer windows service for a consuming application. These search indexes
30  /// are defined in the configuration file of an application. The locations defined
31  /// in a DistributedSearcher match the exposed object URIs as defined in the LuceneServer service.
32  ///
33  /// An example configuration would look like the following:
34  /// <code>
35  /// <DistributedSearchers>
36  /// <DistributedSearcher id="1" SearchMethod="0" location="c:\localindexes\LocalIndex1" />
37  /// <DistributedSearcher id="2" SearchMethod="1" location="tcp://192.168.1.100:1089/RemoteIndex1" />
38  /// <DistributedSearcher id="3" SearchMethod="1" location="tcp://192.168.1.101:1089/RemoteIndex2" />
39  /// </DistributedSearchers>
40  /// </code>
41  /// </summary>
42  public class DistributedSearcher
43  {
44  private int _id;
45  private SearchMethod _eSearchMethod;
46  private string _strLocation;
47 
48  /// <summary>
49  /// Public constructor for DistributedSearcher. A DistributedSearcher is defined
50  /// in XML configuration and is loaded via a custom configuration handler.
51  /// </summary>
52  /// <param name="xSection">The Xml definition in the configuration file</param>
53  public DistributedSearcher(XmlNode xSection)
54  {
55 
56  XmlAttributeCollection attributeCollection = xSection.Attributes;
57  if (attributeCollection == null)
58  throw new ConfigurationErrorsException("xSection.Attributes invalid: " + Environment.NewLine + xSection.OuterXml);
59 
60  try
61  {
62  this._id = Convert.ToInt32(attributeCollection["id"].Value);
63  }
64  catch (Exception e)
65  {
66  throw new ConfigurationErrorsException("DistributedSearcher.id invalid: " + Environment.NewLine + xSection.OuterXml + Environment.NewLine + e.Message);
67  }
68 
69  try
70  {
71  this._eSearchMethod = (SearchMethod)Enum.Parse(typeof(SearchMethod), attributeCollection["SearchMethod"].Value);
72  }
73  catch (Exception)
74  {
75  throw new ConfigurationErrorsException("DistributedSearcher.SearchMethod invalid: " + Environment.NewLine + xSection.OuterXml);
76  }
77 
78  try
79  {
80  this._strLocation = attributeCollection["Location"].Value;
81  }
82  catch (Exception)
83  {
84  throw new ConfigurationErrorsException("DistributedSearcher.Location invalid: " + Environment.NewLine + xSection.OuterXml);
85  }
86 
87  if (this.SearchMethod == SearchMethod.Local)
88  {
89  //check for file-system existence
90  if (!Lucene.Net.Index.IndexReader.IndexExists(this.Location))
91  throw new ConfigurationErrorsException("DistributedSearcher.Location not an index: " + Environment.NewLine + this.Location);
92  }
93  else if (this.SearchMethod == SearchMethod.Distributed)
94  {
95  //exec ping check if needed
96  }
97 
98  }
99 
100  /// <summary>
101  /// Unique Id value assigned to this DistributedSearcher. Not required for any processing,
102  /// simply for identification in reference.
103  /// </summary>
104  public int Id
105  {
106  get { return this._id; }
107  }
108 
109  /// <summary>
110  /// Enumeration value specifying the locality of the index -- local or remote
111  /// </summary>
113  {
114  get {return this._eSearchMethod;}
115  }
116  /// <summary>
117  /// Reference path to the DistributedSearcher. If SearchMethod is Local, this is a local
118  /// file-system path, i.e. "c:\local\index". If SearchMethod is Distributed, this is the
119  /// URI of the server-activated service type, i.e. "tcp://192.168.1.100:1089/RemoteIndex".
120  /// </summary>
121  public string Location
122  {
123  get {return this._strLocation;}
124  }
125  }
126 }