Skip to content

Commit

Permalink
wenli.search
Browse files Browse the repository at this point in the history
  • Loading branch information
yswenli committed Jul 12, 2017
1 parent 34f42bf commit 5da4b1b
Show file tree
Hide file tree
Showing 29 changed files with 370 additions and 0 deletions.
121 changes: 121 additions & 0 deletions Wenli.Search.Demo/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Wenli.Search.Interface;
using Wenli.Search.Model;

namespace Wenli.Search.Demo
{
class Program
{
static void Main(string[] args)
{

Console.Title = "Wenli.Search test";

Console.WriteLine("Wenli.Search test" + Environment.NewLine);


while (true)
{
#region 分词测试
Console.WriteLine("回车开始分词测试");
Console.ReadLine();

string str = "当一个资源从与该资源本身所在的服务器的域或端口不同的域或不同的端口请求一个资源时,浏览器会发起一个跨域 HTTP 请求。出于安全考虑,浏览器会限制从脚本内发起的跨域HTTP请求或者拦截了服务器返回内容。例如,XMLHttpRequest 和 Fetch 遵循同源策略。因此,使用 XMLHttpRequest或 Fetch 的Web应用程序只能将HTTP请求发送到其自己的域;这种安全机制是为避免出现类似CSRF 跨站攻击等问题。";

Console.WriteLine(str);

Console.WriteLine("分词结果如下:");
Console.WriteLine("============================================");


var segs = SeachHelper.Segment(str);

foreach (var item in segs)
{
Console.WriteLine(item);
}

Console.WriteLine("============================================");
#endregion

#region 索引测试
Console.WriteLine("分词测试完成,按回车进入索引测试");
Console.ReadLine();
Console.WriteLine("============================================");
SeachHelper.CleanIndex();

var list = new List<ISearchData>();

list.Add(new SearchData(Guid.NewGuid().ToString("N"), "javascript之ProtoBuf在websocket中的使用", "摘要: 因为ProtoBuf的序列化效率和大小都非常好,所以它在网络通信上面应用越来越多;而webosocket也随着web3.0应用越来越广泛,而将这两个结合在一起的也会慢慢形成一种趋势;本人是为了测试自已写的一个C# websocket,所以在web上面结合pb也写了一个js实例: 1.首先下载prot阅读全文", "protobuf, pb, websocket, javascript protobuf, js protobuf", "http://www.cnblogs.com/yswenli/p/7099809.html", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")));

list.Add(new SearchData(Guid.NewGuid().ToString("N"), "跨域CORS", "摘要: 一、跨域CORS是什么 当一个资源从与该资源本身所在的服务器的域或端口不同的域或不同的端口请求一个资源时,浏览器会发起一个跨域 HTTP 请求。出于安全考虑,浏览器会限制从脚本内发起的跨域HTTP请求或者拦截了服务器返回内容。例如,XMLHttpRequest 和 Fetch 遵循同源策略。因此,使阅读全文", "WCF跨域, 跨域, ajax跨域, CORS, js跨域", "http://www.cnblogs.com/yswenli/p/7053964.html", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")));

list.Add(new SearchData(Guid.NewGuid().ToString("N"), "C# 输入法", "摘要: C# 输入法 虽说输入法不是什么新事物,各种语言版本都有,不过在C#不常见;这就会给人一种误会:C#不能做!其实C#能不能做呢,答案是肯定的——三种方式都行:IMM、TSF以及外挂式。IMM这种就是调windows的一些底层api,不过在新版本的windows中基本上已经不能用了,属于一种过时的操作阅读全文", "C# 输入法, 外挂输入法, 五笔输入法, 拼音输入法", "http://www.cnblogs.com/yswenli/p/6528447.html", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")));

list.Add(new SearchData(Guid.NewGuid().ToString("N"), "C#如何使用ES", "摘要: Elasticsearch简介 Elasticsearch (ES)是一个基于Apache Lucene(TM)的开源搜索引擎,无论在开源还是专有领域,Lucene可以被认为是迄今为止最先进、性能最好的、功能最全的搜索引擎库。 但是,Lucene只是一个库。想要发挥其强大的作用,你需使用C#将其集成阅读全文", "C#, Elasticsearch, Full-text Search, 全文搜索, 搜索引擎, Distributed", "http://www.cnblogs.com/yswenli/p/6266569.html", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")));

list.Add(new SearchData(Guid.NewGuid().ToString("N"), "redis成长之路", "摘要: 为什么使用redis Redis适合所有数据in-momory的场景,虽然Redis也提供持久化功能,但实际更多的是一个disk-backed的功能,跟传统意义上的持久化有比较大的差别,那么可能大家就会有疑问,似乎Redis更像一个加强版的Memcached. 上面描述说的过于泛了,很多初次接触的码阅读全文", "C#, Redis, StackExchange.Redis, Wenli.Drive.Redis", "http://www.cnblogs.com/yswenli/p/6235765.html", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")));

SeachHelper.CreateIndex(list);

Console.WriteLine("============================================");
#endregion



#region 查询测试
Console.WriteLine("索引测试完成,按回车进入查询测试");
Console.ReadLine();
Console.WriteLine("============================================");

var result = SeachHelper.Search("摘要");

result.Data.ForEach((item) =>
{
Console.WriteLine("id:{0} title:{1}", item.id, item.title);
});
Console.WriteLine("============================================");
Console.WriteLine("搜索【摘要】完成,查询结果:{0} 条,按回车进入下次查询测试", result.Count);
Console.ReadLine();
Console.WriteLine("============================================");

result = SeachHelper.Search("ES");

result.Data.ForEach((item) =>
{
Console.WriteLine("id:{0} title:{1}", item.id, item.title);
});
Console.WriteLine("============================================");
#endregion

#region 多次查询测试
Console.WriteLine("搜索【ES】完成,查询结果:{0} 条,按回车进入多次查询测试", result.Count);
Console.ReadLine();
Console.WriteLine("============================================");
Console.WriteLine("正在进行多项查询测试,请稍候...");

Stopwatch sw = new Stopwatch();
sw.Start();

Parallel.For(0, 10000, (i) =>
{
SeachHelper.Search("");
});
Console.WriteLine("============================================");
Console.WriteLine("10000次【的】查询测试已完成,用时:{0}", sw.Elapsed.ToString());
sw.Stop();
#endregion
Console.WriteLine("wenli.Search 测试完成");

}

}
}
}
36 changes: 36 additions & 0 deletions Wenli.Search.Demo/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("Wenli.Search.Demo")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Wenli.Search.Demo")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]

// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("df6778c6-14fc-47f2-a32a-d9daccc75c04")]

// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
// 方法是按如下所示使用“*”: :
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
76 changes: 76 additions & 0 deletions Wenli.Search.Demo/Wenli.Search.Demo.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{DF6778C6-14FC-47F2-A32A-D9DACCC75C04}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>Wenli.Search.Demo</RootNamespace>
<AssemblyName>Wenli.Search.Demo</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup>
<StartupObject>Wenli.Search.Demo.Program</StartupObject>
</PropertyGroup>
<ItemGroup>
<Reference Include="Lucene.Net, Version=3.0.3.0, Culture=neutral, PublicKeyToken=85089178b9ac3181, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>bin\Debug\Lucene.Net.dll</HintPath>
</Reference>
<Reference Include="PanGu, Version=2.4.1.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>bin\Debug\PanGu.dll</HintPath>
</Reference>
<Reference Include="PanGu.HighLight, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>bin\Debug\PanGu.HighLight.dll</HintPath>
</Reference>
<Reference Include="PanGu.Lucene.Analyzer, Version=2.4.1.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>bin\Debug\PanGu.Lucene.Analyzer.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="Wenli.Search, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>bin\Debug\Wenli.Search.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
6 changes: 6 additions & 0 deletions Wenli.Search.Demo/Wenli.Search.Demo.csproj.user
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectView>ShowAllFiles</ProjectView>
</PropertyGroup>
</Project>
10 changes: 10 additions & 0 deletions Wenli.Search.Demo/app.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="searchConfig" type="Wenli.Search.SearchConfig,Wenli.Search" />
</configSections>
<searchConfig FSDirectory="E:\Wenli.Search\Wenli.Search.Demo\bin\Debug\SearchIndex" PanGuXmlFilePath="PanGu.xml" />
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
</startup>
</configuration>
Binary file added Wenli.Search.Demo/bin/Debug/Lucene.Net.dll
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added Wenli.Search.Demo/bin/Debug/PanGu.dll
Binary file not shown.
Binary file added Wenli.Search.Demo/bin/Debug/SearchIndex/_h.cfs
Binary file not shown.
Binary file added Wenli.Search.Demo/bin/Debug/SearchIndex/_h.cfx
Binary file not shown.
Binary file not shown.
Binary file added Wenli.Search.Demo/bin/Debug/SearchIndex/segments_11
Binary file not shown.
Binary file added Wenli.Search.Demo/bin/Debug/Wenli.Search.Demo.exe
Binary file not shown.
10 changes: 10 additions & 0 deletions Wenli.Search.Demo/bin/Debug/Wenli.Search.Demo.exe.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="searchConfig" type="Wenli.Search.SearchConfig,Wenli.Search" />
</configSections>
<searchConfig FSDirectory="E:\Wenli.Search\Wenli.Search.Demo\bin\Debug\SearchIndex" PanGuXmlFilePath="PanGu.xml" />
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
</startup>
</configuration>
Binary file added Wenli.Search.Demo/bin/Debug/Wenli.Search.Demo.pdb
Binary file not shown.
Binary file not shown.
58 changes: 58 additions & 0 deletions Wenli.Search.Demo/bin/Debug/Wenli.Search.Demo.vshost.exe.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
<section name="searchConfig" type="Wenli.Search.SearchConfig,Wenli.Search" />
</configSections>
<log4net>
<logger name="logerror">
<level value="ERROR" />
<appender-ref ref="ErrorAppender" />
</logger>
<logger name="loginfo">
<level value="INFO" />
<appender-ref ref="InfoAppender" />
</logger>
<logger name="logdebug">
<level value="DEBUG" />
<appender-ref ref="DebugAppender" />
</logger>
<appender name="ErrorAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="ErrorLog.log" />
<param name="AppendToFile" value="true" />
<param name="MaxSizeRollBackups" value="100" />
<param name="MaximumFileSize" value="1MB" />
<param name="RollingStyle" value="Size" />
<param name="StaticLogFileName" value="true" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%-5p %d [%c] %m%n" />
</layout>
</appender>
<appender name="InfoAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="InfoLog.log" />
<param name="AppendToFile" value="true" />
<param name="MaxSizeRollBackups" value="100" />
<param name="MaximumFileSize" value="1MB" />
<param name="RollingStyle" value="Size" />
<param name="StaticLogFileName" value="true" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%-5p %d [%c] %m%n" />
</layout>
</appender>
<appender name="DebugAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="DebugLog.log" />
<param name="AppendToFile" value="true" />
<param name="MaxSizeRollBackups" value="100" />
<param name="MaximumFileSize" value="1MB" />
<param name="RollingStyle" value="Size" />
<param name="StaticLogFileName" value="true" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%-5p %d [%c] %m%n" />
</layout>
</appender>
</log4net>
<searchConfig FSDirectory="E:\百度云\Develop\案例\全文搜索\Wenli.Search\Wenli.Search.Demo\bin\Debug\SearchIndex" PanGuXmlFilePath="PanGu.xml" />
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
</startup>
</configuration>
11 changes: 11 additions & 0 deletions Wenli.Search.Demo/bin/Debug/Wenli.Search.Demo.vshost.exe.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<requestedExecutionLevel level="asInvoker" uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
</assembly>
Binary file added Wenli.Search.Demo/bin/Debug/Wenli.Search.dll
Binary file not shown.
1 change: 1 addition & 0 deletions Wenli.Search.Demo/obj/Debug/CoreCompileInputs.cache
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0eb8465fd2e53228b68096a227cdeb0670db9d7f
Binary file not shown.
Empty file.
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
E:\百度云\Develop\案例\全文搜索\Wenli.Search\Wenli.Search.Demo\bin\Debug\Wenli.Search.Demo.exe.config
E:\百度云\Develop\案例\全文搜索\Wenli.Search\Wenli.Search.Demo\bin\Debug\Wenli.Search.Demo.exe
E:\百度云\Develop\案例\全文搜索\Wenli.Search\Wenli.Search.Demo\bin\Debug\Wenli.Search.Demo.pdb
E:\百度云\Develop\案例\全文搜索\Wenli.Search\Wenli.Search.Demo\bin\Debug\Wenli.Search.dll
E:\百度云\Develop\案例\全文搜索\Wenli.Search\Wenli.Search.Demo\bin\Debug\Lucene.Net.dll
E:\百度云\Develop\案例\全文搜索\Wenli.Search\Wenli.Search.Demo\bin\Debug\PanGu.HighLight.dll
E:\百度云\Develop\案例\全文搜索\Wenli.Search\Wenli.Search.Demo\bin\Debug\PanGu.Lucene.Analyzer.dll
E:\百度云\Develop\案例\全文搜索\Wenli.Search\Wenli.Search.Demo\bin\Debug\PanGu.dll
E:\百度云\Develop\案例\全文搜索\Wenli.Search\Wenli.Search.Demo\bin\Debug\Wenli.Search.pdb
E:\百度云\Develop\案例\全文搜索\Wenli.Search\Wenli.Search.Demo\bin\Debug\Lucene.Net.xml
E:\百度云\Develop\案例\全文搜索\Wenli.Search\Wenli.Search.Demo\bin\Debug\PanGu.xml
E:\百度云\Develop\案例\全文搜索\Wenli.Search\Wenli.Search.Demo\obj\Debug\Wenli.Search.Demo.csprojResolveAssemblyReference.cache
E:\百度云\Develop\案例\全文搜索\Wenli.Search\Wenli.Search.Demo\obj\Debug\Wenli.Search.Demo.exe
E:\百度云\Develop\案例\全文搜索\Wenli.Search\Wenli.Search.Demo\obj\Debug\Wenli.Search.Demo.pdb
C:\Users\Administrator\Documents\GitHub\Wenli.Search\Wenli.Search.Demo\bin\Debug\Wenli.Search.Demo.exe.config
C:\Users\Administrator\Documents\GitHub\Wenli.Search\Wenli.Search.Demo\obj\Debug\Wenli.Search.Demo.exe
C:\Users\Administrator\Documents\GitHub\Wenli.Search\Wenli.Search.Demo\obj\Debug\Wenli.Search.Demo.pdb
C:\Users\Administrator\Documents\GitHub\Wenli.Search\Wenli.Search.Demo\bin\Debug\Wenli.Search.Demo.exe
C:\Users\Administrator\Documents\GitHub\Wenli.Search\Wenli.Search.Demo\bin\Debug\Wenli.Search.Demo.pdb
Binary file added Wenli.Search.Demo/obj/Debug/Wenli.Search.Demo.exe
Binary file not shown.
Binary file added Wenli.Search.Demo/obj/Debug/Wenli.Search.Demo.pdb
Binary file not shown.
22 changes: 22 additions & 0 deletions Wenli.Search.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wenli.Search.Demo", "Wenli.Search.Demo\Wenli.Search.Demo.csproj", "{DF6778C6-14FC-47F2-A32A-D9DACCC75C04}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{DF6778C6-14FC-47F2-A32A-D9DACCC75C04}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DF6778C6-14FC-47F2-A32A-D9DACCC75C04}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DF6778C6-14FC-47F2-A32A-D9DACCC75C04}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DF6778C6-14FC-47F2-A32A-D9DACCC75C04}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

0 comments on commit 5da4b1b

Please sign in to comment.