Solr 搜索服务器:如何从要索引的内容中删除 HTML 实体
我是 Solr 的新手,没有 Java 技能,所以也许我错过了一些东西......我试图让 Solr 使用以下 CharFilter 从内容中剥离 HTML:
http://wiki.apache.org/solr/AnalyzersTokenizersTokenFilters#solr.HTMLStripCharFilterFactory
这就是我将其包含到我的 schema.xml 中的方式:
<fieldType name="text" class="solr.TextField" positionIncrementGap="100">
<analyzer type="index">
<charFilter class="solr.HTMLStripCharFilterFactory"/>
<tokenizer class="solr.StandardTokenizerFactory"/>
</analyzer>
<analyzer type="query">
<charFilter class="solr.HTMLStripCharFilterFactory"/>
<tokenizer class="solr.StandardTokenizerFactory"/>
</analyzer>
</fieldType>
<fields>
<field name="text" type="text" indexed="true" stored="true" multiValued="false" />
</fields>
如果我在 Solr 管理上使用分析器进行查询对于“d'Hèrcules”面板,我得到一个匹配项(请参阅字段):
<doc>
<long name="comment_count">0</long>
<str name="ct_model_name">theatre</str>
<str name="django_ct">timeout.work</str>
<str name="django_id">2535</str>
<bool name="family">false</bool>
<long name="hits">0</long>
<str name="id">timeout.work.2535</str>
<str name="name">Les aventures d'Hèrcules</str>
<arr name="parent_sections">
<str>Escena</str>
</arr>
<long name="rating">0</long>
<bool name="recommended">false</bool>
<arr name="sections">
<str>Escena - Infantil</str>
</arr>
<str name="text">
Les aventures d'Hèrcules Jordi Andújar <p>Prepareu-vos per viatjar a l’antiga Grècia on coneixereu l’heroi més gran de tots els temps: l’Hèrcules. De viatge cap a l’Olimp, l’heroi viurà les més increïbles aventures, lluitarà amb bèsties ferotges i perillosos monstres, i s’enfrontarà a la maldat de la temible deessa Hera. Per a tota la família</p>
</str>
...
</doc>
但我需要通过搜索非 HTML 实体形式进行匹配:例如在本例中,将是“l'Hèrcules”(注意单引号)。
我做错了什么?
顺便说一下,我正在使用 django-haystack,如果这个信息有任何用处的话。
预先感谢,
赫克托
I am newbie to Solr and have no skills in Java, so maybe I am missing something… I am trying to get Solr to strip off HTML from content, using the following CharFilter:
http://wiki.apache.org/solr/AnalyzersTokenizersTokenFilters#solr.HTMLStripCharFilterFactory
This is how I am including it into my schema.xml:
<fieldType name="text" class="solr.TextField" positionIncrementGap="100">
<analyzer type="index">
<charFilter class="solr.HTMLStripCharFilterFactory"/>
<tokenizer class="solr.StandardTokenizerFactory"/>
</analyzer>
<analyzer type="query">
<charFilter class="solr.HTMLStripCharFilterFactory"/>
<tokenizer class="solr.StandardTokenizerFactory"/>
</analyzer>
</fieldType>
<fields>
<field name="text" type="text" indexed="true" stored="true" multiValued="false" />
</fields>
If I query using the analyzer on the Solr admin panel for "d'Hèrcules", I get a match (see field):
<doc>
<long name="comment_count">0</long>
<str name="ct_model_name">theatre</str>
<str name="django_ct">timeout.work</str>
<str name="django_id">2535</str>
<bool name="family">false</bool>
<long name="hits">0</long>
<str name="id">timeout.work.2535</str>
<str name="name">Les aventures d'Hèrcules</str>
<arr name="parent_sections">
<str>Escena</str>
</arr>
<long name="rating">0</long>
<bool name="recommended">false</bool>
<arr name="sections">
<str>Escena - Infantil</str>
</arr>
<str name="text">
Les aventures d'Hèrcules Jordi Andújar <p>Prepareu-vos per viatjar a l’antiga Grècia on coneixereu l’heroi més gran de tots els temps: l’Hèrcules. De viatge cap a l’Olimp, l’heroi viurà les més increïbles aventures, lluitarà amb bèsties ferotges i perillosos monstres, i s’enfrontarà a la maldat de la temible deessa Hera. Per a tota la família</p>
</str>
...
</doc>
but I need to match by searching the non-HTML-entity form: e.g. in this case, would be "l'Hèrcules" (note the single quote).
What am I doing wrong?
By the way, I am using django-haystack, if this info is useful in any way.
Thanks in advance,
Hector
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您在 Solr 方面做得很好,您应该注意到的唯一一件事是 Solr 存储的内容和 Solr 索引的内容之间存在差异。 Solr 按原样存储数据,无需修改任何内容,而通过分析器链,您可以更改 Solr 索引数据的方式。
因此,您实际上是在告诉 Solr 从索引中删除所有 html 标签,并用相关字符替换 html 实体,但 Solr 始终会在您提交它们时返回它们。
您可以搜索
d'Hèrcules
或d'Hèrcules
并且应该得到相同的结果,因为您甚至触发了HtmlStripCharFilterFactory
在查询时,因此在这两种情况下您基本上都会提交相同的d'Hèrcules
查询,因为'
被转换为<代码>'。您对
l'Hèrcules
的搜索让我认为文档中l
和Hercules
之间的未转义字符不是' 但看起来非常相似的东西。我认为你应该检查一下。
You're doing well on Solr side, the only thing you should notice is that there's a difference between what Solr stores and what Solr indexes. Solr stores data as they are without modifying anything, while through the analyzer chain you can change the way Solr indexes data.
So you are actually telling Solr to strip any html tag from the index and to replace html entities with related characters, but Solr will always return them as you submitted them.
You can search for
d'Hèrcules
ord'Hèrcules
and you should have the same results, since you have theHtmlStripCharFilterFactory
fired even at query time, so you are basically submitting the same query ford'Hèrcules
in both cases because'
is converted to'
.Your search for
l'Hèrcules
makes me think that the unescaped character betweenl
andHercules
in your document isn't'
but something that looks really similar. I think you should check this.