Lucene2.3.1搜索单个字母的时候出不来结果
如题,请高手帮忙,谢谢代码如下:
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 System.IO;
using System.Collections.Generic;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
IndexInfo();
Analyzer analyzer = new WhitespaceAnalyzer();
IndexSearcher searcher = new IndexSearcher(Server.MapPath("IndexDirectory"));
MultiFieldQueryParser parser = new MultiFieldQueryParser(new string[] { "title", "content" }, analyzer);
Query query = parser.Parse("s");
Hits hits = searcher.Search(query);
for (int i = 0; i < hits.Length(); i++)
{
Document doc = hits.Doc(i);
Response.Write(string.Format("title:{0} content:{1}", doc.Get("title"), doc.Get("content")));
}
searcher.Close();
}
}
protected void IndexInfo()
{
Analyzer analyzer = new StandardAnalyzer();
IndexWriter writer = new IndexWriter(Server.MapPath("IndexDirectory"), analyzer, true);
AddDocument(writer, "SQL Server 2008 的发布", "SQL Server2008 的新特性");
AddDocument(writer, "ASP.NetSQL MVC框架配置与分析2008", "而今,微软推出了新的MVC开发框架,也就是MicrosoftSQL ASP.NET2008 3.5 Extensions");
writer.Optimize();
writer.Close();
}
protected void AddDocument(IndexWriter writer, string title, string content)
{
Document document = new Document();
document.Add(new Field("title", title, Field.Store.YES, Field.Index.TOKENIZED));
document.Add(new Field("content", content, Field.Store.YES, Field.Index.TOKENIZED));
writer.AddDocument(document);
}
} --------------------编程问答-------------------- http://qq497525725.download.csdn.net/
这里有一个中文分词的例子。 --------------------编程问答-------------------- 无语。。
补充:.NET技术 , C#