问题
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