move SynonymFilter and SynonymMap to solr package

git-svn-id: https://svn.apache.org/repos/asf/incubator/solr/trunk@374513 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yonik Seeley 2006-02-02 21:37:12 +00:00
parent 0affd73fd0
commit 1a56b86b6d
4 changed files with 25 additions and 19 deletions

View File

@ -14,10 +14,16 @@
* limitations under the License.
*/
package org.apache.lucene.analysis;
package org.apache.solr.analysis;
import org.apache.lucene.analysis.Token;
import org.apache.lucene.analysis.TokenFilter;
import org.apache.lucene.analysis.TokenStream;
import java.io.IOException;
import java.util.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
/** SynonymFilter handles multi-token synonyms with variable position increment offsets.
* <p>
@ -73,7 +79,7 @@ public class SynonymFilter extends TokenFilter {
// common case fast-path of first token not matching anything
Token firstTok = nextTok();
if (firstTok ==null) return null;
String str = ignoreCase ? firstTok.termText.toLowerCase() : firstTok.termText;
String str = ignoreCase ? firstTok.termText().toLowerCase() : firstTok.termText();
Object o = map.submap!=null ? map.submap.get(str) : null;
if (o == null) return firstTok;
@ -106,7 +112,7 @@ public class SynonymFilter extends TokenFilter {
for (int i=0; i<result.synonyms.length; i++) {
Token repTok = result.synonyms[i];
Token newTok = new Token(repTok.termText, firstTok.startOffset, lastTok.endOffset, firstTok.type);
Token newTok = new Token(repTok.termText(), firstTok.startOffset(), lastTok.endOffset(), firstTok.type());
repPos += repTok.getPositionIncrement();
if (i==0) repPos=origPos; // make position of first token equal to original
@ -176,7 +182,7 @@ public class SynonymFilter extends TokenFilter {
Token tok = nextTok();
if (tok != null) {
// check for positionIncrement!=1? if>1, should not match, if==0, check multiple at this level?
String str = ignoreCase ? tok.termText.toLowerCase() : tok.termText;
String str = ignoreCase ? tok.termText().toLowerCase() : tok.termText();
SynonymMap subMap = (SynonymMap)map.submap.get(str);

View File

@ -17,18 +17,14 @@
package org.apache.solr.analysis;
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.SynonymFilter;
import org.apache.lucene.analysis.SynonymMap;
import java.util.Map;
import java.util.ArrayList;
import java.util.List;
import java.io.IOException;
import org.apache.solr.util.StrUtils;
import org.apache.solr.analysis.BaseTokenFilterFactory;
import org.apache.solr.core.Config;
import org.apache.solr.core.SolrCore;
import org.apache.solr.util.StrUtils;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* @author yonik
* @version $Id$

View File

@ -14,11 +14,13 @@
* limitations under the License.
*/
package org.apache.lucene.analysis;
package org.apache.solr.analysis;
import org.apache.lucene.analysis.Token;
import java.util.*;
/** Mapping rules for use with {@link SynonymFilter}
/** Mapping rules for use with {@link org.apache.solr.analysis.SynonymFilter}
*
* @author yonik
* @version $Id: SynonymMap.java,v 1.2 2005/12/13 05:15:08 yonik Exp $
@ -121,7 +123,7 @@ public class SynonymMap {
int pos2 = tok2!=null ? tok2.getPositionIncrement() : 0;
while(tok1!=null || tok2!=null) {
while (tok1 != null && (pos1 <= pos2 || tok2==null)) {
Token tok = new Token(tok1.termText, tok1.startOffset, tok1.endOffset, tok1.type);
Token tok = new Token(tok1.termText(), tok1.startOffset(), tok1.endOffset(), tok1.type());
tok.setPositionIncrement(pos1-pos);
result.add(tok);
pos=pos1;
@ -129,7 +131,7 @@ public class SynonymMap {
pos1 += tok1!=null ? tok1.getPositionIncrement() : 0;
}
while (tok2 != null && (pos2 <= pos1 || tok1==null)) {
Token tok = new Token(tok2.termText, tok2.startOffset, tok2.endOffset, tok2.type);
Token tok = new Token(tok2.termText(), tok2.startOffset(), tok2.endOffset(), tok2.type());
tok.setPositionIncrement(pos2-pos);
result.add(tok);
pos=pos2;

View File

@ -17,6 +17,8 @@
package org.apache.solr.analysis;
import junit.framework.TestCase;
import org.apache.lucene.analysis.Token;
import org.apache.lucene.analysis.TokenStream;
import java.io.IOException;
import java.util.ArrayList;