实现搜索文档(PDF、XML、HTML、MS Word)的最佳方法是什么?

发布于 2024-07-18 22:03:56 字数 70 浏览 6 评论 0原文

在 Java Web 应用程序中编写搜索功能以搜索文档的好方法是什么?

“标记搜索”是否适合此类搜索功能?

What could be a good way to code a search functionality for searching documents in a java web application?

Is 'tagged search' a good fit for such kind of search functionality?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

别理我 2024-07-25 22:03:56

为什么要重新发明轮子?

查看 Apache Lucene

另外,在 Stack Overflow 上搜索“全文搜索”,您会发现很多其他非常相似的问题。 这是另一个例子,例如:
如何在网站中实现搜索功能?

Why re-invent the wheel?

Check out Apache Lucene.

Also, search Stack Overflow for "full text search" and you'll find a lot of other very similar questions. Here's another one, for example:
How do I implement Search Functionality in a website?

素年丶 2024-07-25 22:03:56

您可以使用 Solr,它位于 Lucene 之上,是一个真正的 Web 搜索引擎应用程序,而Lucene 是一个库。 然而,Solr 或 Lucene 都不会解析 Word 文档、pdf 等来提取元数据信息。 有必要根据预定义的文档模式对文档进行索引。

You could use Solr which sits on top of Lucene, and is a real web search engine application, while the Lucene is a library. However neither Solr or Lucene parse the Word document, pdf, etc. to extract meta data information. It's necessary to index the document based on a pre-defined document schema.

雅心素梦 2024-07-25 22:03:56

至于提取Office文档的文本内容(在将其交给Lucene之前需要这样做),有Apache Tika项目,它支持相当多的文件格式,包括 Microsoft 的。

As for extracting the text content of Office documents (which you need to do before giving it to Lucene), there is the Apache Tika project, which supports quite a few file formats, including Microsoft's.

小嗷兮 2024-07-25 22:03:56

使用 Tika,从文件中获取文本的代码非常简单:

import org.apache.tika.exception.TikaException;
import org.apache.tika.metadata.Metadata;
import org.apache.tika.parser.AutoDetectParser;
import org.apache.tika.sax.BodyContentHandler;
import org.apache.tika.parser.Parser;

// exception handling not shown
Parser parser = new AutoDetectParser();
StringWriter textBuffer = new StringWriter();
InputStream input = new FileInputStream(file);
Metadata md = new Metadata();
md.set(Metadata.RESOURCE_NAME_KEY, file.getName());
parser.parse(input, new BodyContentHandler(textBuffer), md);
String text = textBuffer.toString()

到目前为止,Tika 0.3 似乎运行良好。 只要向它扔任何文件,它就会返回对该格式最有意义的内容。 我可以获得用于索引迄今为止我所提交的任何内容的文本,包括 PDF 和新的 MS Office 文件。 如果某些格式存在问题,我相信它们主要在于获取格式化文本提取而不仅仅是原始纯文本。

Using Tika, the code to get the text from a file is quite simple:

import org.apache.tika.exception.TikaException;
import org.apache.tika.metadata.Metadata;
import org.apache.tika.parser.AutoDetectParser;
import org.apache.tika.sax.BodyContentHandler;
import org.apache.tika.parser.Parser;

// exception handling not shown
Parser parser = new AutoDetectParser();
StringWriter textBuffer = new StringWriter();
InputStream input = new FileInputStream(file);
Metadata md = new Metadata();
md.set(Metadata.RESOURCE_NAME_KEY, file.getName());
parser.parse(input, new BodyContentHandler(textBuffer), md);
String text = textBuffer.toString()

So far, Tika 0.3 seems to work great. Just throw any file at it and it will give you back what makes the most sense for that format. I can get the text for indexing of anything I've thrown at it so far, including PDF's and the new MS Office files. If there are problems with some formats, I believe they mainly lie in getting formatted text extraction rather than just raw plaintext.

葬﹪忆之殇 2024-07-25 22:03:56

只是为了更新

除了 Solr 还有另一个替代方案,名为“ElasticSearch”,它是一个具有良好功能的项目,类似Solr,但无模式。

这两个项目都构建在 Lucene 之上。

Just for updating

There is another alternative instead of Solr, called "ElasticSearch", its a project with good capabilities, similar to Solr, but schemaless.

Both projecs are build on top of Lucene.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文