java - 重写我的程序,使其适合映射缩减结构

标签 java mapreduce amazon-emr inverted-index

我编写了一个 InvertedIndex java 程序,其中给定一个单词,它在某个静态字符串数组中搜索该单词,其中每个字符串都是需要搜索的 url。它最终返回找到该单词的所有 url 的列表。

这是我的相关代码:

static final String[] URL_SEARCH_LIST = {
        "http://www.cnn.com", "http://www.daniel.com", "http://www.amazon.com"
    };
private static List<String> search (String query) {
        try {
            List<String> urlList = new ArrayList<String>();
            for (String site : URL_SEARCH_LIST) {
                URL url = new URL(site);
                HttpURLConnection conn = (HttpURLConnection) url.openConnection();
                conn.setRequestMethod("GET");
                BufferedReader br = new BufferedReader(new InputStreamReader(
                        (conn.getInputStream())));
                String htmlContent;
                while ((htmlContent = br.readLine()) != null) {
                    if (htmlContent.contains(query)) {
                        urlList.add(site);
                        break;
                    }
                }
            }
            System.out.println("Search for: " + query + " Is Done!");
            return urlList;

        } catch (Exception e) {
            System.out.println(e.getMessage());
            return null;
        }
    }

现在我想在 Amazon EMR 上运行此程序,这意味着我需要将我的程序转换为执行相同操作的 Map-Reduce 程序。

鉴于此代码,有人可以帮助我开始吗?我没有完全理解map和reduce的概念...

提前致谢

最佳答案

Map-reduce 基本上只是分而治之加上大量基础设施,因此划分(映射)您的 URL_SEARCH_LIST 数组,创建每个本地 urlList,然后组合(减少)所有 urlLists 最终输出

关于java - 重写我的程序,使其适合映射缩减结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17206784/

相关文章:

hadoop - Hadoop 的分区器,用于 key 的前两个单词

java - 在程序中实现 JAVE

Hadoop/MapReduce : Reading and writing classes generated from DDL

Hadoop 基础 :Number of map tasks mappers reduce tasks reducers

hadoop - 使用 Java 代码运行简单的 Hadoop 命令

amazon-web-services - 如何在AWS EMR上安装Hadoop 3?

java - Spring webservicetemplate jar 与 Axis2 冲突问题

java - 处理大型 xml 文件

java - 在 Count 排序数组中查找中间元素

hadoop - 在 MapReduce 作业中使用之前,Amazon EMR 框架是否从 S3 复制数据