public bool LoadConfig(String fileName)
{
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
try
{
doc.Load(fileName);
XmlNode configNode = doc.SelectSingleNode("LuceneConfig");
createIndexPath = configNode.SelectSingleNode("CreateIndexPath").InnerText; // 建索引的路径
searchIndexPath = configNode.SelectSingleNode("CreateIndexPath").InnerText; // 搜索时的路径
dictPath = configNode.SelectSingleNode("DictPath").InnerText;
// 数据库查询相关
XmlNode datasource = configNode.SelectSingleNode("DataSource");
string server = datasource.SelectSingleNode("sql_host").InnerText;
string user = datasource.SelectSingleNode("sql_user").InnerText;
string pwd = datasource.SelectSingleNode("sql_pwd").InnerText;
string db = datasource.SelectSingleNode("sql_db").InnerText;
strSql = datasource.SelectSingleNode("sql_query").InnerText;
strConn = "server=" + server + ";uid=" + user + ";pwd=" + pwd + ";database=" + db;
// 读取索引字段及配置
XmlNodeList nodeList = configNode.SelectSingleNode("Indexer").SelectSingleNode("Fields").ChildNodes;//获取bookstore节点的所有子节点
//Dictionary<string, SchemaField> IndexFields = new Dictionary<string, SchemaField>();
foreach (XmlNode xn in nodeList)//遍历所有子节点
{
string fieldName = xn.SelectSingleNode("Name").InnerText; // 索引中的名称
string dbFieldName = xn.SelectSingleNode("DBField").InnerText; // 对应数据库中的字段名
bool bStore = xn.SelectSingleNode("Storened").InnerText.Equals("1") ? true : false; //是否存储
bool bAnalyzed = xn.SelectSingleNode("Analyzed").InnerText.Equals("1") ? true : false; // 是否分词
bool bIndex = xn.SelectSingleNode("Indexed").InnerText.Equals("1") ? true : false; // 是否索引
string type = xn.SelectSingleNode("Type").InnerText; // 字段的类别
string defaultValue = xn.SelectSingleNode("DefaultValue").InnerText; // 字段的分词方式
string AnalyzerMode = xn.SelectSingleNode("AnalyzerMode").InnerText;
float fBoost = (float)Convert.ToDouble(xn.SelectSingleNode("Boost").InnerText); // 字段的权重
SchemaField fd = CreateSchemaField(fieldName, dbFieldName, defaultValue, bIndex, bStore, bAnalyzed, fBoost, AnalyzerMode, type);
indexFields.Add(fieldName, fd);
}
// 默认的关键字 查询字段
defaultSearchFields = configNode.SelectSingleNode("Indexer").SelectSingleNode("DefaultSearchFields").InnerText.Split(",".ToCharArray());
ramBufferSizeMB = int.Parse(configNode.SelectSingleNode("Indexer").SelectSingleNode("Men_limit").InnerText);
return true;
}
catch (Exception e)
{
return false;
}
}