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

  • SEARCH
  • Home
  • 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 7416303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:28:07+00:00 2026-05-29T07:28:07+00:00

I am trying to make a custom filter in Lucene which simply recognizes whether

  • 0

I am trying to make a custom filter in Lucene which simply recognizes whether two consequent words in a text start with a capital letter and have the rest as lower case, in which case the two words are to be joined as one token.

The overriden incrementToken method has the following code

@Override
    public boolean incrementToken() throws IOException {
        if(!input.incrementToken()){ 
     return false;}
     //Case were the previous token WAS NOT starting with capital letter and the     rest small   
     if(previousTokenCanditateMainName==false)
     {
            if(CheckIfMainName(termAtt.term()))
            {
                previousTokenCanditateMainName=true;
                tempString=this.termAtt.term() ;                           /*This is the*/
               // myToken.offsetAtt=this.offsetAtt;                             /*Token i need to "delete"*/
            tempStartOffset=this.offsetAtt.startOffset();
            tempEndOffset=this.offsetAtt.endOffset();
            return true;
        }
        else
        {
            return true;
        }
 }
 //Case were the previous token WAS a Proper name (starting with Capital and continuiing with small letters)
     else
         {
         if(CheckIfMainName(termAtt.term()))
         {
             previousTokenCanditateMainName=false;
             posIncrAtt.setPositionIncrement(0);
             termAtt.setTermBuffer(tempString+TOKEN_SEPARATOR+this.termAtt.term());
             offsetAtt.setOffset(tempStartOffset, this.offsetAtt.endOffset());
             return true;
         }
         else
         {
             previousTokenCanditateMainName=false;
             return true;
         }
     }

}

My question is how once i find the first Token that meets my requirements can i “ignore” it.
Currently the code works perfectly with joining the two tokens but i also get an extra token with the first one of the two that I identified.
I tried using the same method setEnableIncrementsPosition(true) as does the built-in stopFilter but in that case my filter needs to be a TokenFilter type which does not allow me to override the incrementToken method.

I hope i phrased my problem properly

  • 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-29T07:28:08+00:00Added an answer on May 29, 2026 at 7:28 am

    You might have a custom method:

    private void tokenize() 
    

    where you do the splitting and the custom joins. The resulting List<String> tokens need to be held as an attribute of the tokenizer.

    In the incrementToken method you simply check if this attribute is null and initialize it if necessary.

    You also need to add the tokens in the incrementToken() method to the termAttribute

    termAttribute.append(tokens.get(tokenIndex));
    

    this includes that your Tokenizer needs to have an attribute like this:

    private CharTermAttribute termAttribute = addAttribute(CharTermAttribute.class);
    

    Probably you need also some fine tuning. But thats only a draft on how this can be achieved in a pretty simple way.

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

Sidebar

Related Questions

Im trying to make custom icons for my HTC EVO, which is running Cyanogen
I got an article app and trying to make a custom filter, I have
I'm trying to make a custom fold which goes through my sequence, and takes
I'm trying to make my custom filter work... I have the following code in
Trying to make a custom :confirm message for a rails form that returns data
I'm trying to make a custom view in Django admin. I'm reading from this
I'm trying to make a custom infowindow. Version = 2. I have added my
I am writing a custom session handler in PHP and trying to make the
trying to make a page which will recursively call a function until a limit
I'm trying to make a custom Callout view for AnnotationView. I had seen this

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.