我回來了,因爲我不滿意我的解決方案(不工作...)。 我修改了StopWords列表(我壓制了「c」字),並且在幹部排除列表中放置了(「C」,「C++」,「C#」)。 我修改了構造函數來設置Stem排除列表。
在我的課堂索引的文件我已經有了:
// I've verified my custom constructor was called
@Analyzer(impl = CustomFrenchAnalyzer.class)
...
我創建我的自定義分析構建查詢的打印和發送到Lucene的,對於關鍵字C,C++,C#查詢是SContent:c(而不是c,C++或c#就像我會)
如果有人知道爲什麼?
這裏是我CustomFrenchAnalyzer類:
public class CustomFrenchAnalyzer extends Analyzer {
protected static final Log LOG = LogFactory.getLog(CustomFrenchAnalyzer.class);
/**
* Extended list of custom French stopwords (Without "c").
*/
public final static String[] FRENCH_STOP_WORDS = { "a", "afin", "ai", "ainsi", "après", "attendu", "au", "aujourd", "auquel", "aussi", "autre", "autres", "aux", "auxquelles", "auxquels", "avait",
"avant", "avec", "avoir", "car", "ce", "ceci", "cela", "celle", "celles", "celui", "cependant", "certain", "certaine", "certaines", "certains", "ces", "cet", "cette", "ceux", "chez",
"ci", "combien", "comme", "comment", "concernant", "contre", "d", "dans", "de", "debout", "dedans", "dehors", "delà", "depuis", "derrière", "des", "désormais", "desquelles", "desquels",
"dessous", "dessus", "devant", "devers", "devra", "divers", "diverse", "diverses", "doit", "donc", "dont", "du", "duquel", "durant", "dès", "elle", "elles", "en", "entre", "environ",
"est", "et", "etc", "etre", "eu", "eux", "excepté", "hormis", "hors", "hélas", "hui", "il", "ils", "j", "je", "jusqu", "jusque", "l", "la", "laquelle", "le", "lequel", "les",
"lesquelles", "lesquels", "leur", "leurs", "lorsque", "lui", "là", "ma", "mais", "malgré", "me", "merci", "mes", "mien", "mienne", "miennes", "miens", "moi", "moins", "mon", "moyennant",
"même", "mêmes", "n", "ne", "ni", "non", "nos", "notre", "nous", "néanmoins", "nôtre", "nôtres", "on", "ont", "ou", "outre", "où", "par", "parmi", "partant", "pas", "passé", "pendant",
"plein", "plus", "plusieurs", "pour", "pourquoi", "proche", "près", "puisque", "qu", "quand", "que", "quel", "quelle", "quelles", "quels", "qui", "quoi", "quoique", "revoici", "revoilà",
"s", "sa", "sans", "sauf", "se", "selon", "seront", "ses", "si", "sien", "sienne", "siennes", "siens", "sinon", "soi", "soit", "son", "sont", "sous", "suivant", "sur", "ta", "te", "tes",
"tien", "tienne", "tiennes", "tiens", "toi", "ton", "tous", "tout", "toute", "toutes", "tu", "un", "une", "va", "vers", "voici", "voilà", "vos", "votre", "vous", "vu", "vôtre", "vôtres",
"y", "à", "ça", "ès", "été", "être", "ô" };
/**
* Contains the stopwords used with the StopFilter.
*/
private Set stoptable = new HashSet();
/**
* Contains words that should be indexed but not stemmed.
*/
private Set excltable = new HashSet<String>(Arrays.asList("C", "C++", "C#"));
private String[] exclListe = { "C", "C++", "C#" };
/**
* Builds an analyzer with the default stop words ({@link #FRENCH_STOP_WORDS}).
*/
public CustomFrenchAnalyzer() {
setStemExclusionTable(exclListe);
stoptable = StopFilter.makeStopSet(FRENCH_STOP_WORDS);
}
/**
* Builds an analyzer with the given stop words.
*/
public CustomFrenchAnalyzer(String[] stopwords) {
stoptable = StopFilter.makeStopSet(stopwords);
}
/**
* Builds an analyzer with the given stop words.
*
* @throws IOException
*/
public CustomFrenchAnalyzer(File stopwords) throws IOException {
stoptable = new HashSet(WordlistLoader.getWordSet(stopwords));
}
/**
* Builds an exclusionlist from an array of Strings.
*/
public void setStemExclusionTable(String[] exclusionlist) {
excltable = StopFilter.makeStopSet(exclusionlist);
}
/**
* Builds an exclusionlist from the words contained in the given file.
*
* @throws IOException
*/
/*
* public void setStemExclusionTable(File exclusionlist) throws IOException { excltable = new HashSet(WordlistLoader.getWordSet(exclusionlist)); }
*/
/**
* Creates a TokenStream which tokenizes all the text in the provided Reader.
*
* @return A TokenStream build from a StandardTokenizer filtered with StandardFilter, StopFilter, FrenchStemFilter and LowerCaseFilter
*/
public final TokenStream tokenStream(String fieldName, Reader reader) {
if (fieldName == null)
throw new IllegalArgumentException("fieldName must not be null");
if (reader == null)
throw new IllegalArgumentException("reader must not be null");
TokenStream result = new StandardTokenizer(reader);
result = new StandardFilter(result);
result = new StopFilter(result, stoptable);
result = new FrenchStemFilter(result, excltable);
// Convert to lowercase after stemming!
result = new LowerCaseFilter(result);
return result;
}
}
感謝