在 Apache SOLR 中索引降价文档以进行全文搜索
Indexing markdown documents for full text search in Apache SOLR
我正在使用 Apache SOLR 来索引降价文档。
如您所知,Markdown 基本上是带有特殊标签的纯文本,用于格式化,如粗体和斜体。
问题是:如果 markdown 有粗体或斜体格式,则全文搜索不起作用。但是,如果降价文档没有格式元素(粗体、斜体或标题、链接等)——全文搜索有效。总而言之,当 markdown 文档与纯文本相同时(即没有任何单词具有任何 markdown 格式),它是有效的。
我已经得出结论,我需要在索引文档之前将 markdown 转换为纯文本。只有这样,全文搜索才能在所有情况下按预期工作。
我在不同的在线论坛上进行了一些搜索和阅读。我想我需要实现一个自定义分析器。自定义分析器需要先将markdown转为明文,再进行索引。
我认为这种情况类似于 Apache Tika
对 Microsoft 文档所做的事情。它解析 ms office 文档并提取纯文本。
我想我需要类似的东西。
我也认为降价文档 - 我需要解析并转换为纯文本。
我已经找到了一种将 markdown 转换为明文的方法。
但是,我不确定是否真的需要创建自定义分析器。我阅读了一些自定义分析器的代码——但它们都使用 tokenFilters
。据我了解,tokenFilters
逐个标记地对流进行操作。在我的例子中,整个 markdown
语料库必须转换为 plain text
。因此,请为此提出一种方法。
我想到的另一种方法是先将 markdown 转换为明文,然后将明文与 markdown 一起保存到磁盘。但是,我想避免这种情况并在 SOLR 中处理这种情况。我希望 SOLR 将其转换为纯文本,然后对其进行索引。
- 我是否应该创建一个
custom analyzer
来将 markdown
文档保存到 plain text
?还是需要 custom query parser
?
- 谁能给出相同的代码示例(伪代码也可以)。
请帮忙。
Use a StandardTokenizer - 它会拆分大多数非数字字符,这应该适合将 Markdown 索引为单个术语,而不是保持 Markdown 语法不变。
This tokenizer splits the text field into tokens, treating whitespace and punctuation as delimiters. Delimiter characters are discarded, with the following exceptions:
Periods (dots) that are not followed by whitespace are kept as part of the token, including Internet domain names.
The "@" character is among the set of token-splitting punctuation, so email addresses are not preserved as single tokens.
如果你也想在单词之间分割句点,你可以使用 PatternReplaceCharFilterFactory
在没有白色的点分隔的单词后插入 spacespace.
我正在使用 Apache SOLR 来索引降价文档。
如您所知,Markdown 基本上是带有特殊标签的纯文本,用于格式化,如粗体和斜体。
问题是:如果 markdown 有粗体或斜体格式,则全文搜索不起作用。但是,如果降价文档没有格式元素(粗体、斜体或标题、链接等)——全文搜索有效。总而言之,当 markdown 文档与纯文本相同时(即没有任何单词具有任何 markdown 格式),它是有效的。
我已经得出结论,我需要在索引文档之前将 markdown 转换为纯文本。只有这样,全文搜索才能在所有情况下按预期工作。
我在不同的在线论坛上进行了一些搜索和阅读。我想我需要实现一个自定义分析器。自定义分析器需要先将markdown转为明文,再进行索引。
我认为这种情况类似于 Apache Tika
对 Microsoft 文档所做的事情。它解析 ms office 文档并提取纯文本。
我想我需要类似的东西。
我也认为降价文档 - 我需要解析并转换为纯文本。
我已经找到了一种将 markdown 转换为明文的方法。
但是,我不确定是否真的需要创建自定义分析器。我阅读了一些自定义分析器的代码——但它们都使用 tokenFilters
。据我了解,tokenFilters
逐个标记地对流进行操作。在我的例子中,整个 markdown
语料库必须转换为 plain text
。因此,请为此提出一种方法。
我想到的另一种方法是先将 markdown 转换为明文,然后将明文与 markdown 一起保存到磁盘。但是,我想避免这种情况并在 SOLR 中处理这种情况。我希望 SOLR 将其转换为纯文本,然后对其进行索引。
- 我是否应该创建一个
custom analyzer
来将markdown
文档保存到plain text
?还是需要custom query parser
? - 谁能给出相同的代码示例(伪代码也可以)。
请帮忙。
Use a StandardTokenizer - 它会拆分大多数非数字字符,这应该适合将 Markdown 索引为单个术语,而不是保持 Markdown 语法不变。
This tokenizer splits the text field into tokens, treating whitespace and punctuation as delimiters. Delimiter characters are discarded, with the following exceptions:
Periods (dots) that are not followed by whitespace are kept as part of the token, including Internet domain names.
The "@" character is among the set of token-splitting punctuation, so email addresses are not preserved as single tokens.
如果你也想在单词之间分割句点,你可以使用 PatternReplaceCharFilterFactory 在没有白色的点分隔的单词后插入 spacespace.