2015-02-27 1 views
2

Il s'agit d'un problème plutôt inhabituel auquel je suis confronté lorsque j'essaie d'implémenter mon filtre d'étalement personnalisé pour SOLR 4.x. Le dernier caractère/suffixe du premier jeton généré est ajouté aux jetons suivants dans le flux après avoir traversé mon filtre personnalisé.SOLR Dépôts de filtres d'étalement personnalisés Suffixes aux jetons suivants

S'il vous plaît se référer à la capture d'écran pour référence,

enter image description here

Champ Type Définition:

<fieldType name="text_hi_cust" class="solr.TextField" positionIncrementGap="100"> 
<analyzer> 
    <tokenizer class="solr.StandardTokenizerFactory"/> 

    <filter class="solr.StopFilterFactory" ignoreCase="true" words="lang/stopwords_hi.txt" /> 

    <filter class="com.rev.solr.utils.hindi.stemmer.HindiStemFilterFactory"/> 
</analyzer> 

Définition:

<field name="loc_hi_2" type="text_hi_cust" indexed="true" stored="true"/> 

Stemmer Filter Factory:

public class HindiStemFilterFactory extends TokenFilterFactory{ 

public HindiStemFilterFactory(Map<String, String> args) { 
    super(args); 
    // TODO Auto-generated constructor stub 
    if (!args.isEmpty()) { 
     throw new IllegalArgumentException("Unknown parameters: " + args); 
    } 
} 

@Override 
public TokenStream create(TokenStream ts) { 
    // TODO Auto-generated method stub 
    return new HindiStemFilter(ts); 
}} 

Stemmer Filtre:

public final class HindiStemFilter extends TokenFilter { 
private final CharTermAttribute termAttr; 
private final KeywordAttribute keywordAttr; 
private final HindiStemmer stemmer; 
protected HindiStemFilter(TokenStream input) { 
    super(input); 
    // TODO Auto-generated constructor stub 
    termAttr = addAttribute(CharTermAttribute.class); 
    keywordAttr = addAttribute(KeywordAttribute.class); 
    stemmer = new HindiStemmer(); 
} 
@Override 
public boolean incrementToken() throws IOException { 
    // TODO Auto-generated method stub 
    if (input.incrementToken()) { 
     if (!keywordAttr.isKeyword()) 
      termAttr.setLength(stemmer.stem(termAttr.buffer(), 
        termAttr.length())); 
     return true; 
    } else { 
     return false; 
    } 
} 
} 

Hindi Stemmer

public int stem(char buffer[], int len) throws IOException{ 
    loadDictionaries();  
    String input = new String(buffer); 
    int rootLen = getRootlength(input.trim());//Returns the length of the root word. 
    return rootLen; 
} 

Tout pointeur serait apprécié. Merci!

Répondre

0

Enfin compris le problème et sa solution. Probablement pas le meilleur, mais ça marche.

problèmes observés:

  1. Le tampon d'entrée flux lorsque converti en chaîne avait environ 7-8 espaces blancs. C'était déconner avec la manipulation de la longueur.
  2. Reposez le même tampon en utilisant la nouvelle longueur.

tige public int (char buffer [], int len) throws IOException {

String input = new String(buffer); 
int rootLen = getRootlength(input.trim()); 
for(int i=0;i<rootLen;i++){ 

    buffer[i] = input.charAt(i); 
    return rootLen; 
} 

Hope this helps!