AyongToolsLibrary/IndexQuery.cs
(开头部分) 4KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Data;
//全文索引所需引入的命名空间
using Lucene.Net.Index;
using Lucene.Net.Documents;
using Lucene.Net.Analysis.Standard;
using Lucene.Net.Search;
using Lucene.Net.QueryParsers;
using Lucene.Net.Analysis;
using Lucene.Net.Analysis.PanGu;
namespace ATL.Search
{
public class IndexQuery
{
//索引存放路径
private string _path;
public string Path
{
get { return _path; }
set { _path = value; }
}
//分词
string GetKerWords(string kw,PanGuTokenizer token)
{
StringBuilder result = new StringBuilder();
ICollection<PanGu.WordInfo> words = token.SegmentToWordInfos(kw);
foreach (PanGu.WordInfo word in words)
{
if (word == null)
{
continue;
}
result.AppendFormat("{0}^{1}.0 ", word.Word, (int)Math.Pow(3, word.Rank));
}
return result.ToString().Trim();
}
//搜索并返回DataTable
public int Search(string kw)
{
string keywords = kw;
IndexSearcher search = new IndexSearcher(Path);
//分词
kw = GetKerWords(kw, new PanGuTokenizer());
//Query构造器
QueryParser titleQueryParser = new QueryParser("title",new PanGuAnalyzer(true));
后面还有 79 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
