Explanation XML-Liu Shuang

Source: Internet
Author: User

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; // index Creation Path
Searchindexpath = confignode. selectsinglenode ("createindexpath"). innertext; // search path
Dictpath = confignode. selectsinglenode ("dictpath"). innertext;

// Database Query
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;

// Read index fields and configurations
Xmlnodelist nodelist = confignode. selectsinglenode ("indexer"). selectsinglenode ("fields"). childnodes; // obtain all the subnodes of the bookstore Node
// Dictionary <string, schemafield> indexfields = new dictionary <string, schemafield> ();
Foreach (xmlnode Xn in nodelist) // traverses all subnodes
{

String fieldname = xn. selectsinglenode ("name"). innertext; // name in the Index
String dbfieldname = xn. selectsinglenode ("dbfield"). innertext; // field name in the database
Bool bstore = xn. selectsinglenode ("storened"). innertext. Equals ("1 ")? True: false; // whether to store
Bool banalyzed = xn. selectsinglenode ("analyzed"). innertext. Equals ("1 ")? True: false; // whether to perform Word Segmentation
Bool bindex = xn. selectsinglenode ("indexed"). innertext. Equals ("1 ")? True: false; // whether to index
String type = xn. selectsinglenode ("type"). innertext; // field category
String defaultvalue = xn. selectsinglenode ("defaultvalue"). innertext; // word segmentation of fields
String analyzermode = xn. selectsinglenode ("analyzermode"). innertext;
Float fboost = (float) convert. todouble (Xn. selectsinglenode ("Boost"). innertext); // weight of the field
Schemafield FD = createschemafield (fieldname, dbfieldname, defaultvalue, bindex, bstore, banalyzed, fboost, analyzermode, type );
Indexfields. Add (fieldname, FD );
}

// Default keyword query field
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;
}

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.