是否有可能使用Erlang,Mnesia和Yaws开发功能强大的网络搜索引擎?
我想开发一个使用Erlang,Mnesia & Yaws的网络搜索引擎。是否有可能使用这些软件制作功能强大且速度最快的网络搜索引擎?它需要做什么来完成这个任务,以及我如何开始?是否有可能使用Erlang,Mnesia和Yaws开发功能强大的网络搜索引擎?
二郎可以使最强大的网络爬虫今天。让我带你穿过我的简单爬行器。
步骤1.我创建一个简单的并行模块,我称之为映射精简
-module(mapreduce). -export([compute/2]). %%===================================================================== %% usage example %% Module = string %% Function = tokens %% List_of_arg_lists = [["file\r\nfile","\r\n"],["muzaaya_joshua","_"]] %% Ans = [["file","file"],["muzaaya","joshua"]] %% Job being done by two processes %% i.e no. of processes spawned = length(List_of_arg_lists) compute({Module,Function},List_of_arg_lists)-> S = self(), Ref = erlang:make_ref(), PJob = fun(Arg_list) -> erlang:apply(Module,Function,Arg_list) end, Spawn_job = fun(Arg_list) -> spawn(fun() -> execute(S,Ref,PJob,Arg_list) end) end, lists:foreach(Spawn_job,List_of_arg_lists), gather(length(List_of_arg_lists),Ref,[]).
gather(0, _, L) -> L; gather(N, Ref, L) -> receive {Ref,{'EXIT',_}} -> gather(N-1,Ref,L); {Ref, Result} -> gather(N-1, Ref, [Result|L]) end.
execute(Parent,Ref,Fun,Arg)-> Parent ! {Ref,(catch Fun(Arg))}.
步骤2. HTTP客户端
一个通常会使用任一inets httpc module
内置二郎或ibrowse
。但是,对于内存管理和速度(让内存足迹尽可能低),一个好的erlang程序员会选择使用curl
。通过应用采用该curl命令行的os:cmd/1
,可以将输出直接导入erlang调用函数。然而,更好的做法是让curl将它的输出结果输入到文件中,然后我们的应用程序有另一个线程(进程)来读取和解析这些文件
Command: curl "http://www.erlang.org" -o "/downloaded_sites/erlang/file1.html"因此,您可以产生许多进程。在执行该命令时,记得要跳过URL以及输出文件路径。另一方面有一个过程,其工作是观看下载页面的目录。它读取并分析他们这些网页,它可能然后解析后删除或保存在不同的位置,甚至更好,使用
In Erlang
os:cmd("curl \"http://www.erlang.org\" -o \"/downloaded_sites/erlang/file1.html\"").
zip module
folder_check()-> spawn(fun() -> check_and_report() end), ok. -define(CHECK_INTERVAL,5). check_and_report()-> %% avoid using %% filelib:list_dir/1 %% if files are many, memory !!! case os:cmd("ls | wc -l") of "0\n" -> ok; "0" -> ok; _ -> ?MODULE:new_files_found() end, sleep(timer:seconds(?CHECK_INTERVAL)), %% keep checking check_and_report(). new_files_found()-> %% inform our parser to pick files %% once it parses a file, it has to %% delete it or save it some %% where else gen_server:cast(?MODULE,files_detected).
第3步:HTML解析器归档。
更好地使用这个mochiweb's html parser and XPATH
。这将帮助您解析并获取所有您最喜爱的HTML标记,提取内容然后再行。下面的例子,我把重点放在只有Keywords
,description
和title
在标记
模块测试壳...真棒!结果
2> spider_bot:parse_url("http://erlang.org"). [[[],[], {"keywords", "erlang, functional, programming, fault-tolerant, distributed, multi-platform, portable, software, multi-core, smp, concurrency "}, {"description","open-source erlang official website"}], {title,"erlang programming language, official website"}]
3> spider_bot:parse_url("http://facebook.com"). [[{"description", " facebook is a social utility that connects people with friends and others who work, study and live around them. people use facebook to keep up with friends, upload an unlimited number of photos, post links and videos, and learn more about the people they meet."}, {"robots","noodp,noydir"}, [],[],[],[]], {title,"incompatible browser | facebook"}]
4> spider_bot:parse_url("http://python.org"). [[{"description", " home page for python, an interpreted, interactive, object-oriented, extensible\n programming language. it provides an extraordinary combination of clarity and\n versatility, and is free and comprehensively ported."}, {"keywords", "python programming language object oriented web free source"}, []], {title,"python programming language – official website"}]
5> spider_bot:parse_url("http://www.house.gov/"). [[[],[],[], {"description", "home page of the united states house of representatives"}, {"description", "home page of the united states house of representatives"}, [],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[], [],[],[]|...], {title,"united states house of representatives, 111th congress, 2nd session"}]
现在可以意识到这一点,我们可以索引对他们的关键字的网页,加页revisists的一个很好的计划。另一个挑战是如何制作抓取工具(这将围绕整个网络,从一个域到另一个域),但这很容易。它可能通过解析Html标签的Html文件。使HTML解析器提取所有的href标记,然后你可能需要一些正则表达式在这里和那里得到正确的链接在给定的域下。
运行履带
7> spider_connect:conn2("http://erlang.org"). Links: ["http://www.erlang.org/index.html", "http://www.erlang.org/rss.xml", "http://erlang.org/index.html","http://erlang.org/about.html", "http://erlang.org/download.html", "http://erlang.org/links.html","http://erlang.org/faq.html", "http://erlang.org/eep.html", "http://erlang.org/starting.html", "http://erlang.org/doc.html", "http://erlang.org/examples.html", "http://erlang.org/user.html", "http://erlang.org/mirrors.html", "http://www.pragprog.com/titles/jaerlang/programming-erlang", "http://oreilly.com/catalog/9780596518189", "http://erlang.org/download.html", "http://www.erlang-factory.com/conference/ErlangUserConference2010/speakers", "http://erlang.org/download/otp_src_R14B.readme", "http://erlang.org/download.html", "https://www.erlang-factory.com/conference/ErlangUserConference2010/register", "http://www.erlang-factory.com/conference/ErlangUserConference2010/submit_talk", "http://www.erlang.org/workshop/2010/", "http://erlangcamp.com","http://manning.com/logan", "http://erlangcamp.com","http://twitter.com/erlangcamp", "http://www.erlang-factory.com/conference/London2010/speakers/joearmstrong/", "http://www.erlang-factory.com/conference/London2010/speakers/RobertVirding/", "http://www.erlang-factory.com/conference/London2010/speakers/MartinOdersky/", "http://www.erlang-factory.com/", "http://erlang.org/download/otp_src_R14A.readme", "http://erlang.org/download.html", "http://www.erlang-factory.com/conference/London2010", "http://github.com/erlang/otp", "http://erlang.org/download.html", "http://erlang.org/doc/man/erl_nif.html", "http://github.com/erlang/otp", "http://erlang.org/download.html", "http://www.erlang-factory.com/conference/ErlangUserConference2009", "http://erlang.org/doc/efficiency_guide/drivers.html", "http://erlang.org/download.html", "http://erlang.org/workshop/2009/index.html", "http://groups.google.com/group/erlang-programming", "http://www.erlang.org/eeps/eep-0010.html", "http://erlang.org/download/otp_src_R13B.readme", "http://erlang.org/download.html", "http://oreilly.com/catalog/9780596518189", "http://www.erlang-factory.com", "http://www.manning.com/logan", "http://www.erlang.se/euc/08/index.html", "http://erlang.org/download/otp_src_R12B-5.readme", "http://erlang.org/download.html", "http://erlang.org/workshop/2008/index.html", "http://www.erlang-exchange.com", "http://erlang.org/doc/highlights.html", "http://www.erlang.se/euc/07/", "http://www.erlang.se/workshop/2007/", "http://erlang.org/eep.html", "http://erlang.org/download/otp_src_R11B-5.readme", "http://pragmaticprogrammer.com/titles/jaerlang/index.html", "http://erlang.org/project/test_server", "http://erlang.org/download-stats/", "http://erlang.org/user.html#smtp_client-1.0", "http://erlang.org/user.html#xmlrpc-1.13", "http://erlang.org/EPLICENSE", "http://erlang.org/project/megaco/", "http://www.erlang-consulting.com/training_fs.html", "http://erlang.org/old_news.html"] ok存储:是一个搜索引擎最重要的概念之一。将搜索引擎数据存储在像MySQL,Oracle,MS SQL e.t.c这样的RDBMS中是一个很大的错误。这样的系统是完全复杂的,与它们接口的应用程序采用启发式算法。这给我们带来了 Key-Value Stores,其中我最好的两个是
Couch Base Server
和
Riak
。这些都是很棒的云文件系统。另一个重要参数是缓存。缓存是通过使用say
Memcached
来实现的,其中上面提到的其他两个存储系统都支持它。搜索引擎的存储系统应该是
schemaless DBMS
,重点是
Availability rather than Consistency
。从这里了解更多关于搜索引擎的信息:
http://en.wikipedia.org/wiki/Web_search_engine
在'rdbms' contrib中,有一个Porter Stemming算法的实现。它从未集成到'rdbms'中,所以它基本上只是坐在那里。我们在内部使用它,并且它工作得很好,至少对于数据集不是很大(我没有在庞大的数据量上进行测试)。
相关模块是:
rdbms_wsearch.erl
rdbms_wsearch_idx.erl
rdbms_wsearch_porter.erl
然后是,当然,在Disco Map-Reduce framework。
不管你能不能做出最快的引擎,我都说不出来。 搜索引擎是否有一个市场快速?我从来没有遇到过例如谷歌。但是,增加我寻找我的问题的良好答案的机会的搜索工具会让我感兴趣。
我会推荐CouchDB而不是Mnesia。
- 的Mnesia不具备的map-reduce,CouchDB的呢(修正 - 见注释)
- Mnesia的是静态类型,CouchDB的是一个数据库文件(和网页文件,即一个更适合的信息模型在我看来)
- Mnesia is primarily intended to be a memory-resident database
YAWS是相当不错的。你还应该考虑MochiWeb。
你不会出错,二郎
您是否问过这个问题,认为某人已经完成了它并且有经验告诉您? :) – 2008-10-17 19:54:09
Robert P!它没有像那样;)。其实,我正在使用这些langs。用于开发我公司的产品。基本上,这个框架工作(erlang,mnesia&yaws)在印度并不为人所知。但是我想用这些lang开发上面的搜索引擎,但不知道它会如何反应? – iankits 2008-10-20 10:13:03