国内首款完全由国人自主研发的可编程云平台 BDC 4.0 新增了云索引、云检索、云中文分词

国内首款完全由国人自主研发的可编程云平台 BDC 4.0 -- 新增了云索引、云检索、云中文分词

BDC 4.0下载地址: http://pan.baidu.com/share/link?shareid=579097387&uk=1614272889

BDC 4.0 云平台分布是云索引、云检索 云中文分词配置说明

一、索引检索配置 

   首先配置一些基本参数和路径

在配置节:<WebSystem.Framework.Key>

下配置以下配置项:

  1、<KeyInfo Key="PhysicaPath" Value="E:\sousuo\"/>

     表示中文分词所在的目录,将压缩文件中的App_Data 文件夹拷贝到 所配置的目录中

     ★注;没这个次库索引、检索都无法正常执行

  2、<KeyInfo Key="SEARCHIDX" Value="E:\sousuo\index\"/>

     表示全文索引存储的目录

   

  3、<KeyInfo Key="SNAPSHOT" Value="E:\sousuo\snapshot\"/> 

     表示快照文件存储的目录

 

  4、<KeyInfo Key="BuildIndexRate" Value="5"/>

     表示索引频率(分钟整数),建议范围 3 - 10,Value越大索引周期越长,但是IO效率将越高,

    (2G以下内存建议使用 5分钟以下,太大高并发将导致内存溢出) 

 

  5、<KeyInfo Key="StartDocId" Value="0"/>

     表示索引文档编号起始值(整数), 在索引的时候会自动增长,每次服务停止会自动记录下最后的编号, 

    考虑到分布式索引和检索,建议每个节点的间隔编号以4000000 为间隔,比如:

    此节点起始编号是 0,那么下一个节点是 4000000,再下一个节点是 8000000

    也就是说,每个节点建议最多索引 400万网页,当然要是你机器足够好,也可以适当调整。

    ★注;单个节点机最多索引 10000000(1千万)网页

 

二、集群配置 

    BDC云平台在具体架设硬件集群的时候最好是将硬件划分逻辑层

    如下图:

         

                       1号节点机               2号节点机               3号节点机 

                           |                       |                       |

                   ----------------         ----------------        ----------------

                   4       5      6         7      8       9        10     11      12

               -------

               13 14  15  ...     ...      ...    ...     ...      ...    ...      ...

 

以此类推,这么做的好处就在于每个节点上下及不多,有效的减少了节点间的网络通信、有效的减少了上下层节点之间的Map - Reduce的计算时间和数据传输

  

在配置节:<WebSystem.Framework.Distributed 中进行配置
具体配置及参数说明请参见:
国内首款完全由国人自主研发的开源云平台 BDC 3.0 详解
http://blog.csdn.net/tengyunjiawu_com/article/details/8565766

★注;BDC 3.0在集群配置上与 BDC 4.0没有做改动


基于 BDC 4.0的分布式集群的云寻觅索引、检索范例代码 下载地址
http://pan.baidu.com/share/link?shareid=580846343&uk=1614272889

 

范例代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WebSystem.Framework;
using System.Net;
using WebSystem.Framework.Distributed;
using System.Windows.Forms;
using System.IO;
using System.Reflection;
//using BoInterFace;
using Bo;
using System.Runtime.Remoting;
using System.Diagnostics;
using WebSystem.FrameWork.SearchEngine.Search;
using System.Threading;
using System.Collections;
using WebSystem.FrameWork.SearchEngine.Index;
using Business.Processing.Business.BO.Core;
using WebSystem.FrameWork.FenCi;
using System.Runtime.Serialization.Formatters.Binary;
using WebSystem.FrameWork.AlgorithmDataStructure.Sort;
using testbo;

namespace Bwsyq.Distributed.Cluster.Demo
{
    class Program : ContextBoundObject
    {
        static void Main(string[] args)
        {
            GInvertedIndex ii = new GInvertedIndex();
            var sw = Stopwatch.StartNew();

            int exectype = 0;
            RemoteFactory rf = new RemoteFactory();

      Thebegin:
            Console.WriteLine("请输入需执行的项:\n");
            Console.WriteLine("1:分发业务逻辑程序 \n");
            Console.WriteLine("2:由指定IP开始的节点及所有子节点中性能最优节点执行的BO对象的方法,\n如果IP是根IP那么就由整个集群中性能最优的节点执行BO对象的方法 \n");
            Console.WriteLine("3:获取某个目录下的指定扩展名的文件列表 \n");
            Console.WriteLine("4:获取CPU性能指标和内存可用指标 \n");
            Console.WriteLine("5:创建远程非透明代理对象,并调用其方法 \n");
            Console.WriteLine("6:分发普通文件 \n");
            Console.WriteLine("7:建立远程全文索引 \n");
            Console.WriteLine("8:执行远程全文检索 \n");
            Console.WriteLine("9:建立远程全文索引(无快照) \n");
            Console.WriteLine("10:执行远程全文检索(无快照) \n");

            Console.WriteLine("11:建立远程网页全文索引 \n");
            Console.WriteLine("12:执行远程网页全文检索 \n");
            Console.WriteLine("13:建立远程网页全文索引(无快照) \n");
            Console.WriteLine("14:执行远程网页全文检索(无快照) \n");

            Console.WriteLine("15:执行远程集群网页全文检索(无快照) \n");

            Console.WriteLine("16:执行远程指定IP节点的中文分词 \n");
            Console.WriteLine("17:执行指定IP开始的节点及所有子节点中性能最优节点的中文分词,\n如果IP是根IP那么就由整个集群中性能最优的节点执行中文分词方法 \n");
            Console.WriteLine("18:获取全局自增长流水号(整数) \n");
            Console.WriteLine("Other Key:退出 \n");

            try
            {
                exectype = Console.ReadLine().ToInt();
            }
            catch (Exception e) { return; }

            switch (exectype)
            {
                case 1:
                    rf = new RemoteFactory();
                    //将业务逻辑程序 TestBo.dll 分发到 192.168.1.4 及其所有下层节点机中,并加载等待调用
                    //注:分发之后可以随时更新覆盖
                    rf.DistributionBoFile(@"D:\clienttest\TestBo.dll", "192.168.1.4");
                    goto Thebegin;
                case 2:
                    foreach (IPAddress ip in Api.LocalIps())
                    {
                        Console.Write(ip.ToString() + "\n");
                    }
                    Console.Write(Api.IsLocalIpAddress("192.168.1.4") + "\n");
                    goto Thebegin;
                case 3:
                    string[] fs = Api.GetDirectoryFiles(Application.StartupPath + Path.DirectorySeparatorChar, "dll");
                    string s = "";
                    if (fs != null)
                    {
                        foreach (string f in fs)
                        {

                            Assembly asm = Assembly.LoadFrom(f);
                            string assemblyName = asm.FullName;
                            foreach (Type t in asm.GetTypes())
                            {
                                if (t.IsClass)
                                {
                                    if (Api.IsInherit(t, typeof(ContextBoundObject)))
                                    {
                                        string typeName = t.FullName;
                                        s = s + typeName + "|" + assemblyName + "|" + typeName + "Service" + "\n";
                                    }
                                }
                            }
                            Console.Write(f + "\n");
                        }
                    }
                    goto Thebegin;
                case 4:
                    Console.Write(Api.GetCPUIndex() + "|" + Api.GetMemoryIndex());
                    goto Thebegin;
                case 5:
                    TestBo TestBo = (TestBo)rf.CreateTheBestRemoteObject(typeof(TestBo), "192.168.1.103");
                    Console.WriteLine(TestBo.GetHttpContext(null, "", ""));
                    goto Thebegin;
                case 6:
                    rf = new RemoteFactory();
                    rf.DistributionFile(@"D:\clienttest\Business.Processing.xml", "127.0.0.2");
                    goto Thebegin;
                case 7:
                    //如果你的内容存储在数据库中,那么全文索引可以采用这种方案
                    //这个索引的同时还会存储快照
                    rf = new RemoteFactory();
                    bool r = false;
                    for (int i = 0; i < 100000; i++)  //索引十万笔数据小试一下,大约10分钟
                    {
                        //参数说明:
                        // 数据库名(必填)、表名(必填)、Key字段名(必填)、Key字段值(必填)、正文(必填)、希望真正执行索引的节点IP
                        r = rf.DistributionDataBaseFullTextIndex("DB001", "T0001", "F0001", Api.uuid(false), "我是一个兵,来自老百姓", "127.0.0.2");
                    }
                    if (r)
                        Console.WriteLine("远程索引成功!");
                    else
                        Console.WriteLine("远程索引失败!");
                    goto Thebegin;
                case 8:
                    //如果你存储在数据库中的内容已经做了全文索引
                    //这个检索出来的结果回包括:查询语句所在的库、表、Key字段名、Key字段值、索引内容、索引内容的动态摘要
                    rf = new RemoteFactory();
                    string queryString = Console.ReadLine();
                    //参数说明:搜索语句、页号、每页条数、希望真正执行检索的节点IP
                    DataBaseSearchResults dbsrs = rf.DistributionDataBaseFullTextSearch(queryString, 1, 10, "127.0.0.2");
                    if (dbsrs.DataBaseSearchResultEntityList.Count > 0)
                    {
                        Console.WriteLine("查询串:" + dbsrs.QueryString);
                        Console.WriteLine("查询串分词结果:" + dbsrs.SearchWords.ToValue());
                        Console.WriteLine("页号:" + dbsrs.PageNumber);
                        Console.WriteLine("每页条数:" + dbsrs.PageSize);
                        Console.WriteLine("总页数:" + dbsrs.PageCount);
                        Console.WriteLine("总条数:" + dbsrs.SearchCount);
                        Console.WriteLine("搜索总用时(豪秒):" + dbsrs.ElapsedMilliseconds);
                        Console.WriteLine("搜索IO用时(豪秒):" + dbsrs.ioMilliseconds);
                        Console.WriteLine("搜索排序用时(豪秒):" + dbsrs.SortMilliseconds);
                        foreach (DataBaseSearchResultEntity dbsre in dbsrs.DataBaseSearchResultEntityList)
                        {
                            Console.WriteLine("DataBaseName:" + dbsre.DataBaseName);
                            Console.WriteLine("TableName:" + dbsre.TableName);
                            Console.WriteLine("KeyFieldName:" + dbsre.KeyFieldName);
                            Console.WriteLine("KeyFieldValue:" + dbsre.KeyFieldValue);
                            Console.WriteLine("Context:" + dbsre.Context);
                            Console.WriteLine("ContextDynamicSummary(动态摘要):" + dbsre.ContextDynamicSummary);
                        }
                    }
                    goto Thebegin;
                case 9:
                    //如果你的内容存储在数据库中,那么全文索引可以采用这种方案
                    //这个索引的同时不会存储快照
                    //索引后返回一个唯一的ID
                    rf = new RemoteFactory();
                    long recordDocId = 0;
                    for (int i = 0; i < 100000; i++)  //索引十万笔数据小试一下,大约10分钟
                    {
                        //参数说明:
                        // 数据库名(必填)、表名(必填)、Key字段名(必填)、Key字段值(必填)、正文(必填)、希望真正执行索引的节点IP
                        recordDocId = rf.DistributionDataBaseFullTextIndexNoSnapShot("DB001", "T0001", "F0001", Api.uuid(false), "我是一个兵,来自老百姓", "127.0.0.2");
                        if (recordDocId == 0)
                            Console.WriteLine("远程索引(无快照)失败!");
                        else
                            Console.WriteLine("远程索引(无快照)成功,全文索引编号:" + recordDocId);
                    }

                    goto Thebegin;
                case 10:
                    //如果你存储在数据库中的内容已经做了全文索引
                    //这个检索出来的结果包括索引的时候生成的 ID列表
                    rf = new RemoteFactory();
                    queryString = Console.ReadLine();
                    //参数说明:搜索语句、页号、每页条数、希望真正执行检索的节点IP
                    DataBaseSearchResultsNoSnapShot dbsrsnss = rf.DistributionDataBaseFullTextSearchNoSnapShot(queryString, 10000, 10, "127.0.0.2");
                    if (dbsrsnss.RecordDocIds.Count > 0)
                    {
                        Console.WriteLine("查询串:" + dbsrsnss.QueryString);
                        Console.WriteLine("查询串分词结果:" + dbsrsnss.SearchWords.ToValue());
                        Console.WriteLine("页号:" + dbsrsnss.PageNumber);
                        Console.WriteLine("每页条数:" + dbsrsnss.PageSize);
                        Console.WriteLine("总页数:" + dbsrsnss.PageCount);
                        Console.WriteLine("总条数:" + dbsrsnss.SearchCount);
                        Console.WriteLine("搜索总用时(豪秒):" + dbsrsnss.ElapsedMilliseconds);
                        Console.WriteLine("搜索IO用时(豪秒):" + dbsrsnss.ioMilliseconds);
                        Console.WriteLine("搜索排序用时(豪秒):" + dbsrsnss.SortMilliseconds);
                        foreach (long RecordDocId in dbsrsnss.RecordDocIds)
                        {
                            Console.WriteLine("全文索引编号:" + RecordDocId);
                        }
                    }
                    goto Thebegin;

                case 11:
                    //如果你的内容是抓取后的网页或文本,那么全文索引可以采用这种方案
                    //这个索引的同时会存储快照
                    rf = new RemoteFactory();
                    r = false;
                    for (int i = 0; i < 1000000; i++)  //索引100万笔数据小试一下,大约2小时
                    {
                        //参数说明:
                        // 链接(必填)、网页Html内容、网站的IP地址、网站web服务器类型、标题(必填)、正文(必填)、
                        // 时间(必填)、网页的权重(0-100)、希望真正执行索引的节点IP
                        // ★网页的权重 一旦指定所对应的网页所有的关键词都会增加相应的权重
                        r = rf.DistributionWebFullTextIndex("http://www.yunxunmi.com/" + i + ".html", 
                            "<body>云寻觅搜索引擎</body>", "127.0.0.1", "IIS", "云寻觅搜索引擎官网", 
                            "云寻觅搜索引擎", DateTime.Now, 100, "127.0.0.2");
                    }
                    if (r)
                        Console.WriteLine("远程索引网页成功!");
                    else
                        Console.WriteLine("远程索引网页失败!");
                    goto Thebegin;

                case 12:
                    //如果你的网页或文本已经做了全文索引
                    //这个检索出来的结果回包括:链接、网页Html内容、标题、正文、网站的IP地址、
                    //网站web服务器类型、网页权重、标题动态摘要、正文动态摘要
                    rf = new RemoteFactory();
                    queryString = Console.ReadLine();
                    //参数说明:搜索语句、页号、每页条数、希望真正执行检索的节点IP
                    WebSearchResults wsrs = rf.DistributionWebFullTextSearch(queryString, 1, 10, "127.0.0.2");
                    if (wsrs.WebSearchResultEntityList.Count > 0)
                    {
                        Console.WriteLine("查询串:" + wsrs.QueryString);
                        Console.WriteLine("查询串分词结果:" + wsrs.SearchWords.ToValue());
                        Console.WriteLine("页号:" + wsrs.PageNumber);
                        Console.WriteLine("每页条数:" + wsrs.PageSize);
                        Console.WriteLine("总页数:" + wsrs.PageCount);
                        Console.WriteLine("总条数:" + wsrs.SearchCount);
                        Console.WriteLine("搜索总用时(豪秒):" + wsrs.ElapsedMilliseconds);
                        Console.WriteLine("搜索IO用时(豪秒):" + wsrs.ioMilliseconds);
                        Console.WriteLine("搜索排序用时(豪秒):" + wsrs.SortMilliseconds);
                        foreach (WebSearchResultEntity wsre in wsrs.WebSearchResultEntityList)
                        {
                            Console.WriteLine("Url:" + wsre.Url);
                            Console.WriteLine("Html:" + wsre.Html);
                            Console.WriteLine("Title:" + wsre.Title);
                            Console.WriteLine("Context:" + wsre.Context);
                            Console.WriteLine("WebSiteIpAddress:" + wsre.WebSiteIpAddress);
                            Console.WriteLine("WebServer:" + wsre.WebServer);
                            Console.WriteLine("WebPageWeights(网页权重):" + wsre.WebPageWeights);
                            Console.WriteLine("TitleDynamicSummary(标题动态摘要):" + wsre.TitleDynamicSummary);
                            Console.WriteLine("ContextDynamicSummary(正文动态摘要):" + wsre.ContextDynamicSummary);
                        }
                    }
                    goto Thebegin;

                case 13:
                    //如果你的内容是抓取后的网页或文本,那么全文索引可以采用这种方案
                    //这个索引的同时不会存储快照
                    //索引后返回一个唯一的文档ID
                    rf = new RemoteFactory();
                    long WebDocId = 0;
                    for (int i = 0; i < 2000000; i++)  //索引200万笔数据小试一下,大约4小时
                    {
                        //参数说明:
                        // 链接(必填)、标题(必填)、正文(必填)、网页的权重(0-100)、希望真正执行索引的节点IP
                        // ★网页的权重 一旦指定所对应的网页所有的关键词都会增加相应的权重
                        WebDocId = rf.DistributionWebFullTextIndexNoSnapShot("http://www.yunxunmi.com/" + i + ".html",
                            "云寻觅搜索引擎官网", "云寻觅搜索引擎", 10, "127.0.0.2");
                        if (WebDocId == 0)
                            Console.WriteLine("远程索引网页(无快照)失败!");
                        else
                            Console.WriteLine("远程索引网页(无快照)成功,全文索引编号:" + WebDocId);
                    }

                    goto Thebegin;

                case 14:
                    //如果你的网页或文本已经做了全文索引
                    //无快照
                    //这个检索出来的结果包括索引的时候生成的文挡ID列表
                    queryString = Console.ReadLine();
                    queryString = string.IsNullOrEmpty(queryString) ? "云寻觅搜索引擎" : queryString;
                    for (int j = 0; j < 100; j++)
                    {
                        rf = new RemoteFactory();
                        //参数说明:搜索语句、页号、每页条数、希望真正执行检索的节点IP
                        WebSearchResultsNoSnapShot wsrsnss = rf.DistributionWebFullTextSearchNoSnapShot(queryString, 10, 10, "192.168.1.6");
                        Console.WriteLine("查询串:" + wsrsnss.QueryString);
                        Console.WriteLine("查询串分词结果:" + wsrsnss.SearchWords.ToValue());
                        Console.WriteLine("页号:" + wsrsnss.PageNumber);
                        Console.WriteLine("每页条数:" + wsrsnss.PageSize);
                        Console.WriteLine("总页数:" + wsrsnss.PageCount);
                        Console.WriteLine("总条数:" + wsrsnss.SearchCount);
                        Console.WriteLine("搜索总用时(豪秒):" + wsrsnss.ElapsedMilliseconds);
                        Console.WriteLine("搜索IO用时(豪秒):" + wsrsnss.ioMilliseconds);
                        Console.WriteLine("搜索排序用时(豪秒):" + wsrsnss.SortMilliseconds);
                        foreach (long webDocId in wsrsnss.WebDocIds)
                        {
                            Console.WriteLine("网页全文索引编号:" + webDocId);
                        }
                    }
                    goto Thebegin;

                case 15:
                    //★★★★★★★★★★★★★★★★★
                    //         这里是集群搜索
                    //搜索指定IP以及其下层所有节点(并行)
                    //★★★★★★★★★★★★★★★★★
                    //如果你的网页或文本已经做了全文索引
                    //这个检索出来的结果包括索引的时候生成的文挡ID列表 
                    //★注;无论搜索结果有多少,只返回最多1000条数据 
                    queryString = Console.ReadLine();
                    queryString = string.IsNullOrEmpty(queryString) ? "云寻觅搜索引擎" : queryString;
                    for (int j = 0; j < 100; j++)  //执行100次搜索检测一下看内存是否溢出
                    {
                        rf = new RemoteFactory();
                        //参数说明:搜索语句、页号、每页条数、希望真正执行检索的节点IP
                        WebSearchResultsNoSnapShot cwsrsnss = rf.DistributionClustersWebFullTextSearchNoSnapShot(queryString, 2, 10, "192.168.1.4");
                        if (cwsrsnss.WebDocIds.Count > 0)
                        {
                            Console.WriteLine("查询串:" + cwsrsnss.QueryString);
                            Console.WriteLine("查询串分词结果:" + cwsrsnss.SearchWords.ToValue());
                            Console.WriteLine("页号:" + cwsrsnss.PageNumber);
                            Console.WriteLine("每页条数:" + cwsrsnss.PageSize);
                            Console.WriteLine("总页数:" + cwsrsnss.PageCount);
                            Console.WriteLine("总条数:" + cwsrsnss.SearchCount);
                            Console.WriteLine("搜索总用时(豪秒):" + cwsrsnss.ElapsedMilliseconds);
                            Console.WriteLine("搜索平均IO用时(豪秒):" + cwsrsnss.ioMilliseconds);
                            Console.WriteLine("搜索平均排序用时(豪秒):" + cwsrsnss.SortMilliseconds);
                            foreach (long webDocId in cwsrsnss.WebDocIds)
                            {
                                Console.WriteLine("集群网页全文索引编号:" + webDocId);
                            }
                        }
                    }
                    goto Thebegin;

                case 16:
                    //由指定IP的节点来执行中文分词
                    string mContext = Console.ReadLine();
                    rf = new RemoteFactory();
                    try
                    {
                        if (String.IsNullOrEmpty(mContext))
                            goto Thebegin;
                        List<string> ls = new List<string>();
                        //参数说明:
                        // 要分词的正文内容、分词类型(CutType.Max:最大分词、CutType.Min最小分词、CutType.MinAndMax最小+最大分词、CutType.MinAndMaxAndMiddle最小+中间+最大分词)、
                        // 正文是否 html内容如果 true 程序会自动对 html进行解析提取正文后在分词、
                        // 希望真正执行中文分词的节点IP
                        foreach (DictionaryEntry de in rf.SpecifyIpRemoteFenCi(mContext, CutType.Max, false, "127.0.0.2"))
                        {
                            ls.Add(de.Key.ToString());
                            Console.WriteLine("分词结果->词汇:" + de.Key.ToString() + " 权重:" + de.Value.ToString());
                        }
                        Console.WriteLine("分词结果:" + ls.ToValue());
                    }
                    catch { goto Thebegin; }
                    goto Thebegin;
                case 17:
                    //由指定IP的节点及其下层所有节点中性能最优的节点机来执行中文分词
                    mContext = Console.ReadLine();
                    rf = new RemoteFactory();
                    try
                    {
                        if (String.IsNullOrEmpty(mContext))
                            goto Thebegin;
                        List<string> ls = new List<string>();
                        //参数说明:
                        // 要分词的正文内容、分词类型(CutType.Max:最大分词、CutType.Min最小分词、CutType.MinAndMax最小+最大分词、CutType.MinAndMaxAndMiddle最小+中间+最大分词)、
                        // 正文是否 html内容如果 true 程序会自动对 html进行解析提取正文后在分词、
                        // 希望真正执行中文分词的节点IP
                        foreach (DictionaryEntry de in rf.TheBestRemoteFenCi(mContext, CutType.Max, false, "127.0.0.2"))
                        {
                            ls.Add(de.Key.ToString());
                            Console.Write("分词结果->词汇:" + de.Key.ToString() + " 权重:" + de.Value.ToString() + "\n");
                        }
                        Console.Write("分词结果:" + ls.ToValue() + "\n");
                    }
                    catch { goto Thebegin; }
                    goto Thebegin;

                case 18:
                    //全局自增长流水号(整数), 每次调用就会返回指定IP节点的下一个流水号,这个完全是系统额外提供的函数,系统本身并不使用。
                    //这个是线程安全的,支持大规模并发。服务停止后系统会保存最后的流水号,作为下次的起始值。
                    rf = new RemoteFactory();
                    int iSerialNumber = 0;
                    try
                    {
                        iSerialNumber = rf.OverallSituationSinceTheGrowthSerialNumber("127.0.0.2");
                    }
                    catch
                    {
                        Console.WriteLine("远程调用全局自增长流水号失败!");
                    }

                    goto Thebegin;
                default:
                    break;
            }
        }
    }
}

参考范例网站: http://sousuo.yunxunmi.com/当然目前的版本即便是单机性能也比测试网站性能强至少 10倍!

在30台PC上做了一周时间的测试,每台机器索引了200万的数据,共6000万模拟网页数据。

任意检索不超过 1秒, 发现目前在云检索的性能、相关性等方面上还有很多值得进一步优化的,因此希望大家多提宝贵意见,谢谢!

有任何疑问或建议请联系QQ群: 204725117

原文地址:https://www.cnblogs.com/bdccloudy/p/3132414.html