我试图在200,000个文本文件中执行搜索,其大小可能从50kb到5mb不等,总共为1.7GB。我打算开发一个搜索引擎(只是一个样本)。 过程是:在一个性能良好的文件中搜索
1) Extract words from each file and store them in a separate file(40,000,000 words)
2) Search each word in each file (40,000,000(words) X 200,000(Files) = 8 X 10^12 searches)
3) Generate boolean Index(650Mb).
所以,大部分这里所涉及的操作都将在文件(S)或文件(县)搜索。 (4+小时)
这是我编写的用于在JAVA中搜索单词的程序。
count = 0;
BufferedReader reader = new BufferedReader(new FileReader('fileName.txt'));
while ((text = reader.readLine()) != null) {
if(text.indexOf(searchString) != -1)
{
if(text.equals(searchString))
{
System.out.print('Word Found in line number '+count);
break;
}
}
count++;
}
计划在Python:
count = 0
file = open(filePath)
with file as f :
for line in f:
count += 1
if(line.index(searchWord))
print("Word found in line number"+count)
输出是完美的,但它需要大量的时间。语言对我来说并不是一个考虑的标准。我正在寻找更好的表现。有没有什么办法可以解决这个问题。由于它大部分是搜索过程,是否有任何完美的方式,因为它正在搜索大块小块。
(我的电脑配置:8GB内存,i7处理器第四代)
所以你试图在Java中实现'grep'? – devnull
你为什么在Java和Python中工作?您想要哪种语言的解决方案? – wnnmaw
你需要编写一个程序吗?或者你只需要寻找一个工具来做到这一点? – Derek