forked from msimons/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request msimons#1 from pdegeus/master
Merged from upstream
- Loading branch information
Showing
317 changed files
with
11,146 additions
and
5,060 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
src/main/java/org/apache/lucene/analysis/miscellaneous/KeywordRepeatFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Licensed to ElasticSearch and Shay Banon under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. ElasticSearch licenses this | ||
* file to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.lucene.analysis.miscellaneous; | ||
|
||
import org.apache.lucene.analysis.TokenFilter; | ||
import org.apache.lucene.analysis.TokenStream; | ||
import org.apache.lucene.analysis.tokenattributes.KeywordAttribute; | ||
import org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute; | ||
|
||
import java.io.IOException; | ||
|
||
|
||
/** | ||
* This TokenFilter emits each incoming token twice once as keyword and once non-keyword, in other words once with | ||
* {@link KeywordAttribute#setKeyword(boolean)} set to <code>true</code> and once set to <code>false</code>. | ||
* This is useful if used with a stem filter that respects the {@link KeywordAttribute} to index the stemmed and the | ||
* un-stemmed version of a term into the same field. | ||
*/ | ||
//LUCENE MONITOR - this will be included in Lucene 4.3. (it's a plain copy of the lucene version) | ||
|
||
public final class KeywordRepeatFilter extends TokenFilter { | ||
private final KeywordAttribute keywordAttribute = addAttribute(KeywordAttribute.class); | ||
private final PositionIncrementAttribute posIncAttr = addAttribute(PositionIncrementAttribute.class); | ||
private State state; | ||
|
||
/** | ||
* Construct a token stream filtering the given input. | ||
*/ | ||
public KeywordRepeatFilter(TokenStream input) { | ||
super(input); | ||
} | ||
|
||
@Override | ||
public boolean incrementToken() throws IOException { | ||
if (state != null) { | ||
restoreState(state); | ||
posIncAttr.setPositionIncrement(0); | ||
keywordAttribute.setKeyword(false); | ||
state = null; | ||
return true; | ||
} | ||
if (input.incrementToken()) { | ||
state = captureState(); | ||
keywordAttribute.setKeyword(true); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public void reset() throws IOException { | ||
super.reset(); | ||
state = null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.