Solr 中的索引和查询 URL
我有一个我想要搜索的 URL 数据库。因为 URL 并不总是写成相同的(可能有也可能没有 www),所以我正在寻找索引和查询 url 的正确方法。 我已经尝试了一些方法,我认为我已经很接近了,但不确定为什么它不起作用:
这是我的自定义字段类型:
<fieldType name="customUrlType" class="solr.TextField" positionIncrementGap="100">
<analyzer type="index">
<tokenizer class="solr.WhitespaceTokenizerFactory"/>
<filter class="solr.WordDelimiterFilterFactory" generateWordParts="1" generateNumberParts="1" catenateWords="0" catenateNumbers="0" catenateAll="0" splitOnCaseChange="0" preserveOriginal="1"/>
<filter class="solr.LowerCaseFilterFactory"/>
</analyzer>
<analyzer type="query">
<tokenizer class="solr.WhitespaceTokenizerFactory"/>
<filter class="solr.WordDelimiterFilterFactory" generateWordParts="1" generateNumberParts="1" catenateWords="0" catenateNumbers="0" catenateAll="0" splitOnCaseChange="0" preserveOriginal="0"/>
<filter class="solr.LowerCaseFilterFactory"/>
</analyzer>
</fieldType>
例如:
http://www.twitter.com/AndersonCooper 被索引时,将在不同位置包含以下单词:http、www、twitter、com、andersoncooper
如果我简单搜索 twitter .com/andersoncooper,我希望此查询与已索引的记录相匹配,这就是为什么我还使用 WDF 来拆分搜索查询, 但是搜索查询最终会像这样:
myfield:("twitter com andersoncooper") 当真正希望它匹配具有以下所有单独单词的所有记录时: twitter com andersoncooper
是否有不同的查询过滤器或分词器我应该是使用?
I have a database of URLs that I would like to search. Because URLs are not always written the same (may or may not have www), I am looking for the correct way to Index and Query urls.
I've tried a few things, and I think I'm close but not sure why it doesn't work:
Here is my custom field type:
<fieldType name="customUrlType" class="solr.TextField" positionIncrementGap="100">
<analyzer type="index">
<tokenizer class="solr.WhitespaceTokenizerFactory"/>
<filter class="solr.WordDelimiterFilterFactory" generateWordParts="1" generateNumberParts="1" catenateWords="0" catenateNumbers="0" catenateAll="0" splitOnCaseChange="0" preserveOriginal="1"/>
<filter class="solr.LowerCaseFilterFactory"/>
</analyzer>
<analyzer type="query">
<tokenizer class="solr.WhitespaceTokenizerFactory"/>
<filter class="solr.WordDelimiterFilterFactory" generateWordParts="1" generateNumberParts="1" catenateWords="0" catenateNumbers="0" catenateAll="0" splitOnCaseChange="0" preserveOriginal="0"/>
<filter class="solr.LowerCaseFilterFactory"/>
</analyzer>
</fieldType>
For example:
http://www.twitter.com/AndersonCooper when indexed, will have the following words in different positions: http,www,twitter,com,andersoncooper
If I search for simply twitter.com/andersoncooper, I would like this query to match the record that was indexed, which is why I also use the WDF to split the search query,
however the search query ends up being like so:
myfield:("twitter com andersoncooper") when really want it to match all records that have all of the following separate words: twitter com andersoncooper
Is there a different query filter or tokenizer I should be using?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这应该是最简单的解决方案:
但是根据您的要求,您需要将其设为多值并对其进行索引 1. 不进行任何更改 2. 没有 http 3. 没有 www
或使 URL 可通过前面的通配符进行搜索(我猜这会比较慢) )
This should be the most simplest solution:
But for you requirement you will need to make it multivalued and index it 1. no changes 2. without http 3. without www
or make the URL searchable via wildcards at the front (which is slower I guess)
您可以尝试关键字分词器
摘自 Packt 出版的Solr 1.4 Enterprise Search Server一书
You can try the keyword tokenizer
From the book Solr 1.4 Enterprise Search Server published by Packt
如果我从你的问题中理解了这个陈述
您正在尝试编写一个与以下两者匹配的查询:
和
(两个链接都包含 all 的令牌),但不匹配
或
如果这是正确的,您现有的配置应该可以正常工作。假设您正在使用标准查询解析器,并且您正在通过curl或其他一些基于url的机制进行查询,您需要的查询参数如下所示:
可能让您陷入困境的问题之一是默认查询运算符(查询中的术语之间)是“OR”,这就是为什么上面必须明确指定 AND 的原因。或者,为了节省一些空间,您可以将默认查询运算符更改为“AND”,如下所示:
If I understand this statement from your question
You are trying to write a query that would match both:
and
(both links contain all of the tokens), but not match either
or
If that is correct, your existing configuration should work just fine. Assuming that you are using the standard query parser and you are querying via curl or some other url based mechanism, you need the query parameter to look like this:
One of the gotchas that may have been tripping you up is that the default query operator (between terms in a query) is "OR", which is why the AND's must be explicitly specified above. Alternately to save some space, you can change the default query operator to "AND" like this: