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 6110723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:32:54+00:00 2026-05-23T14:32:54+00:00

I am currently using what I (mistakenly) thought would be a fairly straightforward implementation

  • 0

I am currently using what I (mistakenly) thought would be a fairly straightforward implementation of Solr’s NGramTokenizerFactory, but I’m getting strange results that are inconsistent between the admin analyzer and actual query results, and I’m hoping for some guidance.

I am trying to get user inputs to match my NGram (minGramSize=2, maxGramSize=2) index. My schema for indexing and query time is below, in which

  1. I strip all non alphanumeric characters using PatternReplaceCharFilter.
  2. I tokenize with NGramTokenizerFactory.
  3. I lowercase using LowerCaseFilterFactory (which leaves non-letter tokens in place, so my numbers will remain).

Using the schema below, I would think that a search for “PCB-1260” (with a properly escaped dash) should match an indexed Ngram tokenized and lowercased value of “Arochlor-1260” (i.e., the bigrams for 1260 are “12 26 60” in both the indexed value and the queried value).

Unfortunately, I get no results unless I delete the dash. [EDIT – even when I properly escape the dash and leave it in the query, I also get no results]. This seems odd because I’m doing a complete pattern replacement of all alphanumeric characters using PatternReplaceCharFilter – which I assume removes all whitespace and dashes.

The query analyzer in the admin page shows proper matching using the schema below – so I’m at a bit of a loss. Is there something fundamental about the PatternReplaceCharFilter or the NGramTokenizerFactory that I’m missing here?

I’ve checked the code and other posts, but can’t seem to figure this one out. After a week of banging my head against the wall, I submit this one to the authority of the stack….

<fieldtype name="tokentext" class="solr.TextField" positionincrementgap="100">
    <analyzer type="index">
        <charfilter class="solr.PatternReplaceCharFilterFactory" pattern="([^A-Za-z0-9])" replacement=""/>
        <tokenizer class="solr.NGramTokenizerFactory" mingramsize="2" maxgramsize="2"/>
        <filter class="solr.LowerCaseFilterFactory"/>
    </analyzer>
    <analyzer type="query">
        <charfilter class="solr.PatternReplaceCharFilterFactory" pattern="[^A-Za-z0-9]" replacement=""/>
        <tokenizer class="solr.NGramTokenizerFactory" mingramsize="2" maxgramsize="2"/>
        <filter class="solr.LowerCaseFilterFactory"/>
    </analyzer>
</fieldtype>
  • 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-23T14:32:54+00:00Added an answer on May 23, 2026 at 2:32 pm

    So – something is definitely odd with PatternReplaceCharFilter failing to remove dashes at query time. Ultimately, I just did some pre-query processing in php of the user input with preg_replace before sending to Solr, and – viola! – worked like a charm with the expected results. Puzzling that the PatternReplaceCharFilter wasn’t behaving…

    Here’s the pre-query php code that I used to get rid of the dashes, if anyone needs it.

    $pattern = '/([-])/';
    $replacement = ' ';
    $usrpar = preg_replace($pattern, $replacement, $raw_user_search_contents);
    $res = htmlentities($usrpar, ENT_QUOTES, 'utf-8');
    

    After that, I just passed $res to Solr…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently using the awesome attachment-fu plugin for a Rails app, but as a
We are currently using a somewhat complicated deployment setup that involves a remote SVN
I am currently working with a subversion repository but I am using git to
I am currently using Watir with Firefox and it seems that when I try
I'm currently using Pubnub , but i'll probably exceed the free quota. Is there
Im currently using base64_encode for some $_GET params that i don't want regular user
Im currently using a method that looks like the following code to add script
Currently using System.Web.UI.WebControls.FileUpload wrapped in our own control. We have licenses for Telerik. I
Im currently using vs2008 with asp.net mvc framework for web development. Im missing a
I'm currently using VS2005 Profesional and .NET 2.0, and since our project is rather

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.