简体   繁体   English

Solr-匹配以特定单词开头的句子

[英]Solr - Match sentence beginning with a particular word

Any tips on how this is done? 关于此操作的任何提示?

I've tried using the PatternTokenizerFactory , but it's not working as expected. 我试过使用PatternTokenizerFactory ,但是没有按预期工作。

Is it possible to do this without writing a custom tokenizer ? 是否可以在不编写custom tokenizer情况下执行此操作?

you can tokenize the field in question using KeyWordTokenizerFactory and then do wildcard search 您可以使用KeyWordTokenizerFactory标记有问题的字段,然后进行通配符搜索

http://solr.pl/en/2010/12/20/wildcard-queries-and-how-solr-handles-them/ http://solr.pl/en/2010/12/20/wildcard-queries-and-how-solr-handles-them/

provided that you are not doing any other operation which does not work with the above Tokenizer. 前提是您没有执行上述Tokenizer不能执行的任何其他操作。

Another way is a roundabout way. 另一种方法是回旋处。 You can create a copyfield which will have its spaces stripped out using the following technique (or some other) :- 您可以使用以下方法(或其他方法)创建一个复制字段,以将其空格删除:-

What is the regular expression to remove spaces in SOLR 在SOLR中删除空格的正则表达式是什么

You can then tokenize that copyfield using WhiteSpaceTokenizer (which essentially creates one token only since the copyfield values have no space) and then do a wildcard search on it. 然后,您可以使用WhiteSpaceTokenizer(实质上只创建一个令牌,因为copyfield值没有空格)来标记该copyfield,然后对其进行通配符搜索。

The second approach might fail in some of the cases (for eg. "wor them" will match "worth*" after the spaces are stripped) 在某些情况下,第二种方法可能会失败(例如,删除空格后,“ wor them”将匹配“ worth *”)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM