What is the regular expression to remove spaces in SOLR

不问归期 提交于 2019-12-25 08:14:20

问题


In a Regex, how to remove all the leading, trailing and where ever spaces exist in SOLR. To remove special characters, we can have the PatternReplaceFilterFactory as

<filter class="solr.PatternReplaceFilterFactory" pattern="([^a-z])" replacement="" replace="all" />

What pattern value will be formed to remove the spaces whereever it comes.


回答1:


I don't know SOLR but based on your example I guess you could just do

<filter class="solr.PatternReplaceFilterFactory" pattern="(\s+)" replacement="" replace="all" /> to remove all spaces

or

<filter class="solr.PatternReplaceFilterFactory" pattern="(^\s+|\s+$)" replacement="" replace="all" /> to remove just leading and trailing spaces.




回答2:


Use the trim filter to remove leading and trailing spaces. http://wiki.apache.org/solr/AnalyzersTokenizersTokenFilters#solr.TrimFilterFactory

just replacing everything not a-z with nothing will cause strange things to happen and is not a good idea.




回答3:


solr.TrimFilterFactory , can be used to remove leading and trailing spaces without regex.



来源:https://stackoverflow.com/questions/9427130/what-is-the-regular-expression-to-remove-spaces-in-solr

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!