搜索引擎查找关键字的文档 [英] search engine for documents finding keywords

查看:239
本文介绍了搜索引擎查找关键字的文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我手上有一项任务。



基本上我要做的就是创建一个简单的搜索引擎,通过一组文本文档和记录对于文档集合中的每个单词,包含特定单词的所有文档。



简单搜索引擎必须接受搜索查询(包含一组关键字)并识别每个单词包含所有或部分关键字的文档。



然后它应按照找到的关键字的降序打印文档名称,这意味着包含所有关键字的文档应显示在顶部列表



我正在努力使用伪代码而不管它的程序。

I have a task on my hands.

Basically what I have to do is to create a simple search engine that goes through a group of text documents and record for each word in the document collection all documents that contain a particular word.

The simple search engine must accept a search query (containing a set of keywords) and identify each document that contain all or some keywords.

It should then print documents names in descending order of keywords found, this means the document that contains all keywords should appear at the top of the list

I'm struggling with the pseudocode let alone the program for it.

推荐答案

例如,伪代码可能是:



>使用变量int count和string filename定义一个类Result

>制作一个ArrayList或其他集合,将结果添加到

>获取目录中的文件名列表

>获取用户的关键字列表

>对于文件名中的每个文件,请执行以下操作:

>>对于每个关键字,请执行以下操作:

>>>搜索关键字

>>>>如果找到:count ++

>>>结束

>>如果count> 0:将结果添加到列表中

>>结束



> sortByCount

> print List
For example, the pseudocode might be:

> define a class Result with variables int count and string filename
> make an ArrayList or other collection to add Results to
> get List of file names from directory
> get list of keywords from user
> for each file in file names do:
>> for each keyword do:
>>> search for keyword
>>>> if found: count++
>>> end
>>if count>0: add Result to list
>>end

>sortByCount
>print List


我不懂Java,但在C#中我用 System.IO.File.ReadAllText(String)然后使用RegularExpression。

我肯定会使用 IndexOf - 这将导致误报。



例如:



I don't know Java, but in C# I'd read the whole file with System.IO.File.ReadAllText(String) then use a RegularExpression.
I definitely would not use IndexOf -- that will lead to false-positives.

For example:

System.Text.RegularExpressions.Regex reg = 
  new System.Text.RegularExpressions.Regex
  ( @"(?i)\b(a)|(the)|(this)\b" ) ; // Create the expresion from the provided terms

System.Text.RegularExpressions.MatchCollection mat = reg.Matches ( args [ 0 ] ) ;
          
System.Console.WriteLine ( mat.Count ) ;


这篇关于搜索引擎查找关键字的文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆