using System.Collections.Generic;
using System.Text;
using Lucene.Net;
using Lucene.Net.Analysis;
using Lucene.Net " /> 亚洲男女网站,先锋成人av,三上亚洲一区二区

色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

Lucene.Net操作上的一些技巧

以下例子采用 Lucene.NET 1.9 版本,可取去 Lucene.NET 下載。

1. 基本應(yīng)用

using System;
using System.Collections.Generic;
using System.Text;
using Lucene.NET;
using Lucene.NET.Analysis;
using Lucene.NET.Analysis.Standard;
using Lucene.NET.Documents;
using Lucene.NET.Index;
using Lucene.NET.QueryParsers;
using Lucene.NET.Search;
using Lucene.NET.Store;
using Lucene.NET.Util;

namespace ConsoleApplication1.Lucene
{
public class LuceNETest
{
private const string FieldName = "name";
private const string FieldValue = "value";

private Directory directory = new RAMDirectory();
private Analyzer analyzer = new StandardAnalyzer();

public LuceNETest()
{
}

private void Index()
{
IndexWriter writer
= new IndexWriter(directory, analyzer, true);
writer.maxFieldLength
= 1000;

for (int i = 1; i <= 100; i++)
{
Document document
= new Document();

document.Add(
new Field(FieldName, "name" + i, Field.Store.YES, Field.Index.UN_TOKENIZED));
document.Add(
new Field(FieldValue, "Hello, World!", Field.Store.YES, Field.Index.TOKENIZED));

writer.AddDocument(document);
}

writer.Optimize();
writer.Close();
}

private void Search()
{
Query query
= QueryParser.Parse("name*", FieldName, analyzer);

IndexSearcher searcher
= new IndexSearcher(directory);

Hits hits
= searcher.Search(query);

Console.WriteLine(
"符合條件記錄:{0}; 索引庫(kù)記錄總數(shù):{1}", hits.Length(), searcher.Reader.NumDocs());
for (int i = 0; i < hits.Length(); i++)
{
int docId = hits.Id(i);
string name = hits.Doc(i).Get(FieldName);
string value = hits.Doc(i).Get(FieldValue);
float score = hits.Score(i);

Console.WriteLine(
"{0}: DocId:{1}; Name:{2}; Value:{3}; Score:{4}",
i
+ 1, docId, name, value, score);
}

searcher.Close();
}
}
}

NET技術(shù)Lucene.Net操作上的一些技巧,轉(zhuǎn)載需保留來(lái)源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 东丽区| 英超| 合山市| 宁都县| 萝北县| 桂东县| 榆中县| 长治市| 呈贡县| 永寿县| 侯马市| 肃宁县| 卓尼县| 盐池县| 壶关县| 个旧市| 玉树县| 小金县| 黎川县| 大埔区| 济宁市| 大埔县| 丽水市| 织金县| 土默特左旗| 自治县| 正蓝旗| 庆元县| 林甸县| 张家港市| 河源市| 剑阁县| 三台县| 安阳市| 福清市| 承德县| 石阡县| 四子王旗| 清新县| 兴隆县| 申扎县|