XML文件的部分索引(Bleve)

huangapple go评论86阅读模式
英文:

Partial Indexing of an XML file (Bleve)

问题

我正在评估几个不同的库,看看哪一个最适合我所需的。

目前我正在看 Bleve,但我也可以使用任何其他库。

我想要索引整个文件,除了那些以 XML 格式存储的特定文件。对于这些文件,我只想让 Bleve 索引特定的标签,因为大部分标签对搜索来说是无用的。我正在评估是否有可能实现这一点,但作为 Bleve 的新手,我不确定需要自定义哪个部分。

文档非常好,但我似乎找不到这个答案。我只需要一个带有关键词和步骤的解释,不需要代码,我只需要一个指引,因为我已经花了几个小时在谷歌搜索上转圈,但没有任何进展。

英文:

I am evaluating a couple different libraries to see which one will best fit what I need.

Right now I am looking at Bleve, but I am happy to use any library.

I am looking to index full files except specific ones which are in XML format. For those I only want Bleve to index specific tags as most of the tags are worthless to search. I am trying to evaluate if this is possible but, being new to Bleve, I am not sure what part I need to customize.

The documentation is very good, but I can't seem to find this answer. All I need is an explanation with keywords and steps, no code is required, I just need a push as I have spent hours spinning my wheels with google searches and I am getting no where.

答案1

得分: 1

可能有很多方法可以解决这个问题。这里是其中一种方法。

Bleve索引的是由键/值元数据对组成的文档集合。

在你的情况下,一个文档可以由两个键/值对表示:.xml文件的名称(用于唯一标识文档)和文件的内容。

type Doc struct {
    Name string
    Body string
}

问题在于内容是XML格式的,而Bleve不直接支持XML。

解决方法之一是通过去除不需要的标签和内容来预处理XML文件。你可以使用encoding/xml标准库来实现。

关于类似任务的示例,你可以查看https://github.com/blevesearch/fosdem-search/的代码。

在那里,他们使用自定义格式(https://github.com/blevesearch/fosdem-search/blob/master/fosdem.ical)对文件进行索引,通过将其解析为Bleve可以接受的格式(https://github.com/blevesearch/fosdem-search/blob/master/ical.go)进行索引。

英文:

There are probably many ways to approach this. Here's one.

Bleve indexes documents which are collections of key/value metadata pairs.

In your case, a document could be represented by 2 key/value pairs: name of .xml file (to uniquely identify the document) and content of the file.

type Doc struct {
    Name string
    Body string
}

The issue is that body is XML and Bleve doesn't support XML out-of-the-box.

A way to address it would be to pre-process XML file by stripping unwanted tags and content. You can do it using encoding/xml standard library.

For an example of a similar task you can see the code of https://github.com/blevesearch/fosdem-search/

In there they index file in custom format (https://github.com/blevesearch/fosdem-search/blob/master/fosdem.ical) by parsing it into a format they can submit to Bleve for indexing (https://github.com/blevesearch/fosdem-search/blob/master/ical.go).

huangapple
  • 本文由 发表于 2017年7月8日 06:45:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/44980688.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定