Lucene.Net  3.0.3
Lucene.Net is a .NET port of the Java Lucene Indexing Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties
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 {
42  public class DistributedSearcher
43  {
44  private int _id;
45  private SearchMethod _eSearchMethod;
46  private string _strLocation;
47 
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 
104  public int Id
105  {
106  get { return this._id; }
107  }
108 
113  {
114  get {return this._eSearchMethod;}
115  }
121  public string Location
122  {
123  get {return this._strLocation;}
124  }
125  }
126 }