首页 文章 精选 留言 我的

精选列表

搜索[javascript框架],共10000篇文章
优秀的个人博客,低调大师

ionic入门之开始使用ionic框架

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/inforstack/article/details/71120744 安装ionic npm install -g cordova ionic 首先,安装 Node.js。然后,在你的终端安装最新的Cordova 和 Ionic的命令行工具。按照 Android和 iOS平台指南,安装所需的开发工具。 创建应用程序 ionic start myApp tabs 创建一个Ionic的应用程序使用一个我们现成的应用程序模板,或一张空白的重新开始。查阅更多设计 市场。 模板命令 ionic start myApp blank ionic start myApp tabs ionic start myApp sidemenu 运行应用程序 cd myApp ionic serve 很多应用程序可以建立在与浏览器中的权利。建议启动workflow。 ionic serve

优秀的个人博客,低调大师

全文检索:Apache Lucene框架入门实例

一 简介 Lucene属于Apache开源项目的一部分,是一个开源的全文检索引擎工具包,但它不是一个完整的全文检索引擎,而是一个全文检索引擎的架构,提供了完整的查询引擎和索引引擎,部分文本分析引擎(英文与德文两种西方语言) Lucene的目的是为软件开发人员提供一个简单易用的工具包,以方便在目标系统中实现全文检索的功能,或者是以此为基础建立起完整的全文检索引擎。在Java开发环境里Lucene是一个成熟的免费开源工具。就其本身而言,Lucene是当前以及最近几年最受欢迎的免费Java信息检索程序库。人们经常提到信息检索程序库,虽然与搜索引擎有关,但不应该将信息检索程序库与搜索引擎相混淆 注:以上介绍参考至百度百科 在使用Lucene建立索引时,可以选择将索引文件存储在内存中或者磁盘里。下面我将分别介绍基于这两种存储方式的全文索引的创建与检索 二 基于内存的索引创建与检索 首先需要做的是下载相关的jar包,下载地址是:http://lucene.apache.org/core/downloads.html 其次,在正式介绍下面的内容之前,至少需要导入以下三个jar包: lucene-analyzers-common-6.2.1.jar lucene-core-6.2.1.jar lucene-queryparser-6.2.1.jar 基于内存的全文索引示例代码如下: packagecn.zifangsky.lucene; importjava.io.IOException; importjava.util.HashMap; importjava.util.Map; importjava.util.Map.Entry; importorg.apache.lucene.analysis.Analyzer; importorg.apache.lucene.analysis.standard.StandardAnalyzer; importorg.apache.lucene.document.Document; importorg.apache.lucene.document.Field; importorg.apache.lucene.document.StringField; importorg.apache.lucene.document.TextField; importorg.apache.lucene.index.DirectoryReader; importorg.apache.lucene.index.IndexReader; importorg.apache.lucene.index.IndexWriter; importorg.apache.lucene.index.IndexWriterConfig; importorg.apache.lucene.queryparser.classic.ParseException; importorg.apache.lucene.queryparser.classic.QueryParser; importorg.apache.lucene.search.IndexSearcher; importorg.apache.lucene.search.Query; importorg.apache.lucene.search.ScoreDoc; importorg.apache.lucene.store.Directory; importorg.apache.lucene.store.RAMDirectory; publicclassDemo1{ /** *创建索引 * *@paramsourceMap *待索引的内容 *@return */ publicstaticDirectorycreateIndex(Map<String,String>sourceMap){ //1创建一个默认的词法分析器 Analyzeranalyzer=newStandardAnalyzer(); //2设置索引文件存储位置,可以存储到磁盘和内存中,这里设置为存储到内存 Directorydirectory=newRAMDirectory();//存储到内存 //3索引的写入 IndexWriterConfigconfig=newIndexWriterConfig(analyzer); try{ IndexWriterindexWriter=newIndexWriter(directory,config); //将内容添加到索引中,每本书表示一个“文档”,并将每个文档进行存储 if(!sourceMap.isEmpty()){ for(Entry<String,String>source:sourceMap.entrySet()){ Documentdocument=newDocument(); //标题需要分词,使用TextField document.add(newTextField("title",source.getKey(),Field.Store.YES)); //作者不需要分词,使用StringField document.add(newStringField("author",source.getValue(),Field.Store.YES)); indexWriter.addDocument(document); } } indexWriter.close(); }catch(IOExceptione){ e.printStackTrace(); } returndirectory; } /** *搜索 * *@paramdirectory *@paramsearchWord *搜索关键词 */ publicstaticvoidreadIndex(Directorydirectory,StringsearchWord){ intpreHits=10;//获取前面多少个结果 try{ //1打开一个文档 IndexReaderindexReader=DirectoryReader.open(directory); IndexSearcherindexSearcher=newIndexSearcher(indexReader); Analyzeranalyzer=newStandardAnalyzer(); //2设置使用关键字检索,这里是检索标题 QueryParserparser=newQueryParser("title",analyzer); Queryquery=parser.parse(searchWord); //3获取检索到的结果 System.out.println("总共有"+indexSearcher.count(query)+"个结果"); ScoreDoc[]hits=indexSearcher.search(query,preHits).scoreDocs; System.out.println("当前有"+hits.length+"个结果,内容分别如下:"); //遍历检索到的“文档” for(inti=0;i<hits.length;i++){ intdocId=hits[i].doc; DocumenthitDoc=indexSearcher.doc(docId); System.out.println("《"+hitDoc.get("title")+"》作者:"+hitDoc.get("author")); } indexReader.close(); }catch(IOException|ParseExceptione){ e.printStackTrace(); } } publicstaticvoidmain(String[]args){ Map<String,String>books=newHashMap<>(); books.put("Java编程思想","BruceEckel"); books.put("Java8实战","Raoul-GabrielUrma"); books.put("Spring入门经典","MertCaliskan"); books.put("Spring实战","CraigWalls"); books.put("SpringBoot实战","汪云飞"); books.put("Redis实战","JosiahL.Carlson"); Directorydirectory=Demo1.createIndex(books); Demo1.readIndex(directory,"Spring"); // Demo1.readIndex(directory,"实战"); } } 上面代码并不复杂,而且还有详细的注释,因此一些细节流程我就不多做介绍了。只是需要强调的一点是: 在创建索引时使用了这样的代码: document.add(newTextField("title",source.getKey(),Field.Store.YES)); 其中,上面的Field.Store.YES表示在创建索引的同时将内容的原文(也就是:source.getKey())也存储到内存中。如果我们选择了Field.Store.NO,在创建索引和检索的时候都是没问题的,但是在最后是没法提取检索关键字所在的原文内容的 最后的输出结果如下: 总共有3个结果 当前有3个结果,内容分别如下: 《SpringBoot实战》作者:汪云飞 《Spring实战》作者:CraigWalls 《Spring入门经典》作者:MertCaliskan 三基于磁盘的索引创建与检索 示例代码如下: packagecn.zifangsky.lucene; importjava.io.BufferedReader; importjava.io.File; importjava.io.FileReader; importjava.io.FilenameFilter; importjava.io.IOException; importjava.util.ArrayList; importjava.util.List; importorg.apache.lucene.analysis.Analyzer; importorg.apache.lucene.analysis.standard.StandardAnalyzer; importorg.apache.lucene.document.Document; importorg.apache.lucene.document.Field.Store; importorg.apache.lucene.document.StringField; importorg.apache.lucene.document.TextField; importorg.apache.lucene.index.DirectoryReader; importorg.apache.lucene.index.IndexWriter; importorg.apache.lucene.index.IndexWriterConfig; importorg.apache.lucene.queryparser.classic.QueryParser; importorg.apache.lucene.search.IndexSearcher; importorg.apache.lucene.search.Query; importorg.apache.lucene.search.ScoreDoc; importorg.apache.lucene.store.Directory; importorg.apache.lucene.store.FSDirectory; publicclassDemo2{ publicstaticvoidmain(String[]args){ Demo2.createIndex("D:/test/source","D:/test/index"); Demo2.searchIndex("D:/test/index","apache"); } /** *给一个目录下的所有文本文件创建索引 * *@paramsourceDir *待索引的文件目录 *@paramindexDir *索引文件存储目录 *@return */ publicstaticvoidcreateIndex(StringsourceDir,StringindexDir){ List<File>fileList=getFileList(sourceDir); if(fileList.size()>0){ //遍历文件并分别创建索引 for(Filefile:fileList){ StringBufferstringBuffer=newStringBuffer(); stringBuffer.append(getFileContent(file)); // System.out.println("fileName:"+file.getName()+"filePath:"+file.getPath()); Analyzeranalyzer=newStandardAnalyzer(); try{ FileindexFile=newFile(indexDir); if(!indexFile.exists()){ indexFile.mkdirs(); } //存储到文件中 Directorydirectory=FSDirectory.open(newFile(indexDir).toPath()); IndexWriterConfigconfig=newIndexWriterConfig(analyzer); IndexWriterindexWriter=newIndexWriter(directory,config); Documentdocument=newDocument(); document.add(newTextField("fileName",file.getName(),Store.YES)); document.add(newTextField("content",stringBuffer.toString(),Store.YES)); document.add(newStringField("path",file.getPath(),Store.YES)); indexWriter.addDocument(document); indexWriter.commit(); indexWriter.close(); }catch(IOExceptione){ e.printStackTrace(); } } } } /** *在索引目录下检索关键字 * *@paramindexDir *索引文件存储目录 *@paramsearchWord *搜索的关键字 */ publicstaticvoidsearchIndex(StringindexDir,StringsearchWord){ Analyzeranalyzer=newStandardAnalyzer(); try{ //从一个磁盘目录中检索 Directorydirectory=FSDirectory.open(newFile(indexDir).toPath()); DirectoryReaderdirectoryReader=DirectoryReader.open(directory); IndexSearcherindexSearcher=newIndexSearcher(directoryReader); //检索正文 QueryParserqueryParser=newQueryParser("content",analyzer); Queryquery=queryParser.parse(searchWord); //检索前1000个结果 System.out.println("总共有"+indexSearcher.count(query)+"个结果"); ScoreDoc[]hits=indexSearcher.search(query,1000).scoreDocs; System.out.println("当前有"+hits.length+"个结果,分别如下:"); for(inti=0;i<hits.length;i++){ intdocId=hits[i].doc; DocumenthitDoc=indexSearcher.doc(docId); System.out.println("文件名:"+hitDoc.get("fileName")+"路径:"+hitDoc.get("path")); //System.out.println(hitDoc.get("content")); } directoryReader.close(); directory.close(); }catch(Exceptione){ e.printStackTrace(); } } /*** *获取一个目录下的所有文件 * *@paramsourceDir *文件目录 *@return所有文件的集合 */ privatestaticList<File>getFileList(StringsourceDir){ Filedir=newFile(sourceDir); if(dir.isDirectory()){ //返回指定格式的文本文件 File[]files=dir.listFiles(newFilenameFilter(){ publicbooleanaccept(Filedir,Stringname){ returnname.endsWith(".txt")||name.endsWith(".log")||name.endsWith(".xml"); } }); List<File>fileList=newArrayList<File>(); if(files.length>0){ for(FiletmpFile:files){ fileList.add(tmpFile); } } returnfileList; } returnnull; } /** *获取一个文本文件的所有内容 * *@paramfile *@return */ privatestaticStringBuffergetFileContent(Filefile){ try{ // BufferedReaderreader=newBufferedReader(newInputStreamReader(newFileInputStream(file),"UTF-8")); BufferedReaderreader=newBufferedReader(newFileReader(file)); Stringline=null; StringBufferstringBuffer=newStringBuffer(); while((line=reader.readLine())!=null){ stringBuffer.append(line+"\n"); } reader.close(); returnstringBuffer; }catch(Exceptione){ e.printStackTrace(); } returnnull; } } 从上面的代码可以看出,索引存储到内存或者磁盘上,其基本步骤是差不多的,只是使用的类稍有区别。同时多了一些基本的IO操作代码,包括文件的读写等操作 运行上面的索引创建方法之后,打开磁盘上的“D:/test/index”,可以发现多了很多这样的文件: 最后,检索关键字“apache”,检索到的结果如下: 总共有3个结果 当前有3个结果,分别如下: 文件名:Lucene简介.txt路径:D:\test\source\Lucene简介.txt 文件名:H5_ws.log路径:D:\test\source\H5_ws.log 文件名:Shiro简介.txt路径:D:\test\source\Shiro简介.txt 可以发现,有三个文件包含“apache”这个关键字 至此,Lucene的入门介绍到此结束 参考文章: http://www.importnew.com/12715.html http://www.cnblogs.com/xing901022/p/3933675.html PS:上面图片中的水印是我个人博客的域名,因此还请管理员手下留情不要给我标为“转载文章”,谢谢!!!

优秀的个人博客,低调大师

MapReduce框架Mapper和Reducer类源码分析

一:Mapper类 在Hadoop的mapper类中,有4个主要的函数,分别是:setup,cleanup,map,run。代码如下: protected void setup(Context context) throws IOException, InterruptedException { // NOTHING } protected void map(KEYIN key, VALUEIN value, Context context) throws IOException, InterruptedException { context.write((KEYOUT) key, (VALUEOUT) value); } protected void cleanup(Context context) throws IOException, InterruptedException { // NOTHING } public void run(Context context) throws IOException, InterruptedException { setup(context); while (context.nextKeyValue()) { map(context.getCurrentKey(), context.getCurrentValue(), context); } cleanup(context); } } 由上面的代码,我们可以了解到,当调用到map时,通常会先执行一个setup函数,最后会执行一个cleanup函数。而默认情况下,这两个函数的内容都是nothing。因此,当map方法不符合应用要求时,可以试着通过增加setup和cleanup的内容来满足应用的需求。 二:Reducer类 在Hadoop的reducer类中,有3个主要的函数,分别是:setup,clearup,reduce。代码如下: /** * Called once at the start of the task. */ protected void setup(Context context ) throws IOException, InterruptedException { // NOTHING } /** * This method is called once for each key. Most applications will define * their reduce class by overriding this method. The default implementation * is an identity function. */ @SuppressWarnings("unchecked") protected void reduce(KEYIN key, Iterable<VALUEIN> values, Context context ) throws IOException, InterruptedException { for(VALUEIN value: values) { context.write((KEYOUT) key, (VALUEOUT) value); } } /** * Called once at the end of the task. */ protected void cleanup(Context context ) throws IOException, InterruptedException { // NOTHING } 在用户的应用程序中调用到reducer时,会直接调用reducer里面的run函数,其代码如下: /* * control how the reduce task works. */ @SuppressWarnings("unchecked") public void run(Context context) throws IOException, InterruptedException { setup(context); while (context.nextKey()) { reduce(context.getCurrentKey(), context.getValues(), context); // If a back up store is used, reset it ((ReduceContext.ValueIterator) (context.getValues().iterator())).resetBackupStore(); } cleanup(context); } } 由上面的代码,我们可以了解到,当调用到reduce时,通常会先执行一个setup函数,最后会执行一个cleanup函数。而默认情况下,这两个函数的内容都是nothing。因此,当reduce不符合应用要求时,可以试着通过增加setup和cleanup的内容来满足应用的需求。

资源下载

更多资源
优质分享App

优质分享App

近一个月的开发和优化,本站点的第一个app全新上线。该app采用极致压缩,本体才4.36MB。系统里面做了大量数据访问、缓存优化。方便用户在手机上查看文章。后续会推出HarmonyOS的适配版本。

Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

用户登录
用户注册
修改密码
忘记密码