background preloader

Apache Tika - Apache Tika

Apache Tika - Apache Tika

Lucene教程 - Lucene安装、配置、实例 Index Microsoft Office Files with Lucene | acidum.de Christoph Hartmann on January 7th, 2009 Within my current research project I faced the challenge to index a whole bunch of files. To be platform independent the Java programming language was the first choice. Then I came along the Lucene project. Lucene is an open-source project that “provides Java-based indexing and search technology”. I looked at two projects: While Tika is not available as a binary download Aperture is. Just download the Tika source code viasvn checkout tika and use maven to install the binary into your local maven repository. The following part do the core binding between Tika and Lucene. logger.debug("Indexing " + file);try { Document doc = null; // parse the document synchronized (contentParserAccess) { doc = contentParser.getDocument(file); } // put it into Lucene if (doc ! The ContentParser calls the TikaParser for each file and put the metadata it returns into a Lucene document. A custom tika parser may looks like:

全文検索エンジン「Lucene.Net」を使う 「Lucene.Net」は.NET Framework上で利用できる「全文検索エンジン」です。例えば、ASP.NETを使ってWebサイトを作成する際に、サイト内のコンテンツを検索する検索ページを作成したいという場合や、Windowsアプリケーションで全文検索機能を利用したい場合にLucene.Netが利用できます。 Lucene.NetはApache Software Foundationが開発しているプロジェクトの1つで、オープンソースで開発されています。Java言語で記述された「Lucene」がそのオリジナルであり、これは、Wikipediaをはじめ多くのWebサイトで現在利用されています( Lucene-java WikiのPowerdBy ) Luceneの.NET版であるLucene.NETは、Java版と同様Apache Software Foundationの「 Lucene.Netプロジェクト 」で提供されています。今回は、このLucene.Netを紹介します。 Lucene.Netの概要 全文検索とは、簡単にいうと「複数のテキストから特定の文字列を検索する」機能です。 「逐次検索型」は、UNIXのgrepコマンドのように、実行するたびにテキストをすべて走査して検索を行うものです。 Lucene.NETはインデックス型で、事前にテキストからトークンを切り出しておき、インデックスを作成したうえで検索処理を実行します。 全文検索を行うLucene.NET本体に加えて、日本語の環境では、テキストからトークンを切り出すための独自の処理が必要となります。 英文では単語ごとにスペースで区切られて文章が記述されているため、文章を解析するための処理はそれほど複雑ではありませんが、単語の区切りが明確でない日本語の文章を解析するには、独自の高度な形態素解析処理が必要となります。 オリジナルであるJava版のLuceneを含め、Apache Software Foundationで配布されているLuceneには、日本語に対応したトークンを取り出す機能(=日本語アナライザ)が付属していません。 Lucene.Netによる全文検索処理 Lucene.Netでは、主に次の2つの処理を行います。 インデックス作成処理 検索処理 インデックスを作成すれば、検索処理が利用可能となります。

Lucene - Index File Formats Index File Formats This document defines the index file formats used in Lucene version 3.0. If you are using a different version of Lucene, please consult the copy of docs/fileformats.html that was distributed with the version you are using. Apache Lucene is written in Java, but several efforts are underway to write versions of Lucene in other programming languages. As Lucene evolves, this document should evolve. Compatibility notes are provided in this document, describing how file formats have changed from prior versions. In version 2.1, the file format was changed to allow lock-less commits (ie, no more commit lock). In version 2.3, the file format was changed to allow segments to share a single set of doc store (vectors & stored fields) files. Definitions The fundamental concepts in Lucene are index, document, field and term. An index contains a sequence of documents. A document is a sequence of fields. The same string in two different fields is considered a different term. Segments

Lucene索引中的编码问题,好郁闷 - 巴士飞扬-技术BLOG 这几天一直在研究Lucene索引,遇到一些问题,搞得我头都大了.我不知道别人是怎么做的. 开始时,我是把内容读取出来,直接索引在索引文件里,这样就方便在查询时读取内容并高亮显示.但是给果发现,这个东西很受字符编码的影响,于是,我就在文件读取时加上一个编码,可是发现中文检索不出来. 我是这样做的,索引文件contents: doc.add(new Field("contents", new FileReader(file))); 结果这样做导致问题的出现,原来FileReader读取文件内容时是采取的系统编码,这样就导致UTF-8的文件可能以GBK方式读取进来(因为我发现GBK的没出现问题)进行索引,结果导致在检索时,检索不到. 后来,我就换了一个: doc.add(new Field("contents", FileDocument.readFileContents(file.getCanonicalPath(), charset), Field.Store.YES, Field.Index.TOKENIZED)); 其中readFileContents是我自己写的按照charset编码读取文件内容的函数.这样做能解决索引的问题.但是,这样索引是把文件内容都写到索引中,会导致索引文件很大很大,也就会增加索引时的负担.所以,我还是放弃这样的解决办法了. 回过来继续使用前一个索引方案,但是对它进行改进.后来想想,我只要把doc.add(new Field("contents", new FileReader(file)));里的第二个参数FileReader,让他能以相应的编码来加载文件就可以了.于是我看了一下FileReader的构造函数,没有带编码的构造函数.怎么办.迷惑之中,我尝试用InputStreamReader类实例来代替FileReader,没想到,结果居然能成功,代码如下: doc.add(new Field("contents", new InputStreamReader(new FileInputStream(file.getCanonicalPath()), charset))); 他们是Field.Index.TOKENIZED和Field.Store.NO的。 Tags: FileReader Lucene InputStreamReader 索引 搜索引擎 |

IndexWriterConfig (Lucene 4.6.0 API) Expert: set the interval between indexed terms. Large values cause less memory to be used by IndexReader, but slow random-access to terms. Small values cause more memory to be used by an IndexReader, and speed random-access to terms. This parameter determines the amount of computation required per query term, regardless of the number of documents that contain that term. In particular, numUniqueTerms/interval terms are read into memory by an IndexReader, and, on average, interval/2 terms must be scanned for each random term access. Takes effect immediately, but only applies to newly flushed/merged segments. NOTE: This parameter does not apply to all PostingsFormat implementations, including the default one in this release. Note that other implementations may have their own parameters, or no parameters at all.

Lucene / Solr 开发经验(二)_Goldhwi.狼 1 lucene简介 1.1 什么是lucene Lucene是一个全文搜索框架,而不是应用产品。因此它并不像www.baidu.com 或者google Desktop那么拿来就能用,它只是提供了一种工具让你能实现这些产品。 1.2 lucene能做什么 要回答这个问题,先要了解lucene的本质。 1.3 你该不该选择lucene 下面给出一些测试数据,如果你觉得可以接受,那么可以选择。 2 lucene的工作方式 lucene提供的服务实际包含两部分:一入一出。 2.1写入流程 源字符串首先经过analyzer处理,包括:分词,分成一个个单词;去除stopword(可选)。 2.2读出流程 用户提供搜索关键词,经过analyzer处理。 3 一些需要知道的概念 lucene用到一些概念,了解它们的含义,有利于下面的讲解。 3.1 analyzer Analyzer 是分析器,它的作用是把一个字符串按某种规则划分成一个个词语,并去除其中的无效词语,这里说的无效词语是指英文中的“of”、 “the”,中文中的 “的”、“地”等词语,这些词语在文章中大量出现,但是本身不包含什么关键信息,去掉有利于缩小索引文件、提高效率、提高命中率。 3.2 document 用户提供的源是一条条记录,它们可以是文本文件、字符串或者数据库表的一条记录等等。 3.3 field 一个Document可以包含多个信息域,例如一篇文章可以包含“标题”、“正文”、“最后修改时间”等信息域,这些信息域就是通过Field在Document中存储的。 3.4 term term是搜索的最小单位,它表示文档的一个词语,term由两部分组成:它表示的词语和这个词语所出现的field。 3.5 tocken tocken是term的一次出现,它包含trem文本和相应的起止偏移,以及一个类型字符串。 3.6 segment 添加索引时并不是每个document都马上添加到同一个索引文件,它们首先被写入到不同的小文件,然后再合并成一个大索引文件,这里每个小文件都是一个segment。 4 lucene的结构 lucene包括core和sandbox两部分,其中core是lucene稳定的核心部分,sandbox包含了一些附加功能,例如highlighter、各种分析器。 5 如何建索引 5.1 最简单的能完成索引的代码片断

Lucene Query Syntax - Lucene Tutorial.com Lucene has a custom query syntax for querying its indexes. Here are some query examples demonstrating the query syntax. Keyword matching Search for word "foo" in the title field. title:foo Search for phrase "foo bar" in the title field. title:"foo bar" Search for phrase "foo bar" in the title field AND the phrase "quick fox" in the body field. title:"foo bar" AND body:"quick fox" Search for either the phrase "foo bar" in the title field AND the phrase "quick fox" in the body field, or the word "fox" in the title field. (title:"foo bar" AND body:"quick fox") OR title:fox Search for word "foo" and not "bar" in the title field. title:foo -title:bar Wildcard matching Search for any word that starts with "foo" in the title field. title:foo* Search for any word that starts with "foo" and ends with bar in the title field. title:foo*bar Note that Lucene doesn't support using a * symbol as the first character of a search. Proximity matching Lucene supports finding words are a within a specific distance away.

Related: