Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6647057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:29:32+00:00 2026-05-26T00:29:32+00:00

I have a field that I would like to treat as a single string,

  • 0

I have a field that I would like to treat as a single string, while stripping all non-alphanumeric characters from it.

For example, I would like to tokenize “123 456.78-9” as “123456789”. In order to do that I have been attempting to define my own analyzer. According to the solr page the KeywordTokenizerFactory will treat a string as a single term and I can use a PatternReplaceFilterFactory to remove the characters as I intend.

I am using the following definition within my code and it is not working:

@AnalyzerDef(name = "strippinganalyzer",
    tokenizer = @TokenizerDef(factory = KeywordTokenizerFactory.class),
    filters = {
            @TokenFilterDef(factory = PatternReplaceFilterFactory.class,
                    params = { 
                        @org.hibernate.search.annotations.Parameter(name = "pattern", value="([^a-zA-Z0-9])"),
                        @org.hibernate.search.annotations.Parameter(name="replacement", value=""),
                        @org.hibernate.search.annotations.Parameter(name="replace", value="all")
                    }
            )
    })

This matches “123*” but not “1234*” etc. What am I missing?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T00:29:32+00:00Added an answer on May 26, 2026 at 12:29 am

    Creating a custom Analyzer seems to do the trick:

    public class AlphanumericAnalyzer extends Analyzer {
    
        @Override
        public TokenStream tokenStream(String fieldName, Reader reader) {
    
            return new TrimFilter(new PatternReplaceFilter(new LowerCaseFilter(new KeywordTokenizer(reader)), Pattern.compile("[^a-zA-Z0-9]"), "", true), true);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a DATETIME field. I would like to select all the records that
I have an array that I would like to sort using a date field
I have to convert an incoming String field into a BigDecimal field that would
I have 3 similar tables, that would all have the same enum type field.
In my asp.net-mvc website I have a field that usually has a string (from
I have a table that has a link field that I would like to
I have a field that I would like to validate. I want the field
I have a field in my bean that I would like to be either
I have float field that contains (for example): 1234.5678. I would like to display
I have a field that is in this format 5551112391^HUMAN^HUMAN-800-800^6-main^^ How would I only

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.