Lucene.net search engine

牧云@^-^@ 提交于 2019-12-07 13:17:31

问题


I have a folder with 20 text files in it. and I wish to index this folder and search for any keyword among these files.

How can I do this in C#?


回答1:


This is a nice introduction to lucene.Net:

  • Introducing Lucene.Net (CodeProject)

It covers the basics of how to create an index, add documents to the index and finally how to search your index.




回答2:


1) Use this code to load all your file contents into a List():

var files = new List<string>();
foreach (var filePath in System.IO.Directory.EnumerateFiles("path_to_your_files")) {
    files.Add(System.IO.File.ReadAllText(filePath));
}

2) Read my article on how to setup basic Lucene.Net search:
Lucene.Net ultra fast search for MVC or WebForms site => made easy!

3) Instead of the static data in that article, use the data from your text files you got in step #1.

I hope that'll help!



来源:https://stackoverflow.com/questions/5074586/lucene-net-search-engine

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!