2009-07-28 2 views

답변

20

이렇게하려면 자신의 분석기 클래스를 작성해야합니다. 이것은 비교적 간단합니다. 여기 제가 사용하고있는 것이 있습니다. 그것은 정지 단어 필터링을 결합합니다. 포터가 줄기를 긋고 (이것은 사용자의 요구에 너무 많이 맞을 수 있습니다.) 문자에서 악센트를 제거합니다.

/// <summary> 
/// An analyzer that implements a number of filters. Including porter stemming, 
/// Diacritic stripping, and stop word filtering. 
/// </summary> 
public class CustomAnalyzer : Analyzer 
{ 
    /// <summary> 
    /// A rather short list of stop words that is fine for basic search use. 
    /// </summary> 
    private static readonly string[] stopWords = new[] 
    { 
     "0", "1", "2", "3", "4", "5", "6", "7", "8", 
     "9", "000", "$", "£", 
     "about", "after", "all", "also", "an", "and", 
     "another", "any", "are", "as", "at", "be", 
     "because", "been", "before", "being", "between", 
     "both", "but", "by", "came", "can", "come", 
     "could", "did", "do", "does", "each", "else", 
     "for", "from", "get", "got", "has", "had", 
     "he", "have", "her", "here", "him", "himself", 
     "his", "how","if", "in", "into", "is", "it", 
     "its", "just", "like", "make", "many", "me", 
     "might", "more", "most", "much", "must", "my", 
     "never", "now", "of", "on", "only", "or", 
     "other", "our", "out", "over", "re", "said", 
     "same", "see", "should", "since", "so", "some", 
     "still", "such", "take", "than", "that", "the", 
     "their", "them", "then", "there", "these", 
     "they", "this", "those", "through", "to", "too", 
     "under", "up", "use", "very", "want", "was", 
     "way", "we", "well", "were", "what", "when", 
     "where", "which", "while", "who", "will", 
     "with", "would", "you", "your", 
     "a", "b", "c", "d", "e", "f", "g", "h", "i", 
     "j", "k", "l", "m", "n", "o", "p", "q", "r", 
     "s", "t", "u", "v", "w", "x", "y", "z" 
    }; 

    private Hashtable stopTable; 

    /// <summary> 
    /// Creates an analyzer with the default stop word list. 
    /// </summary> 
    public CustomAnalyzer() : this(stopWords) {} 

    /// <summary> 
    /// Creates an analyzer with the passed in stop words list. 
    /// </summary> 
    public CustomAnalyzer(string[] stopWords) 
    { 
     stopTable = StopFilter.MakeStopSet(stopWords);  
    } 

    public override TokenStream TokenStream(string fieldName, System.IO.TextReader reader) 
    { 
     return new PorterStemFilter(new ISOLatin1AccentFilter(new StopFilter(new LowerCaseTokenizer(reader), stopWords))); 
    } 
} 
+1

감사합니다. 나는 이것을 시도 할 것이다. – devson

+1

+1 감사합니다 잭, 내가 찾고있는 것. 만약 내가 이것을 대답으로 표시 할 수 있다면! – andy

+0

예제를 사용했지만 숫자가 '4656'(표준 분석기가 작동 함) 인 쿼리에 대한 결과를 얻지 못했습니다. StopAnalyzer.ENGLISH_STOP_WORDS에 내장 된 stop 단어를 대체했습니다. 여기에는 숫자, 아이디어 거기에? – Myster

7

Snowball 또는 PorterStemFilter을 사용할 수 있습니다. Java Analyzer documentation을 다른 필터/토큰 라이저/분석기를 결합하는 가이드로 참조하십시오. 인덱싱 및 검색에 동일한 분석기를 사용해야하므로 인덱싱시 처리 형태가 시작되어야합니다.

+0

고마워, 나는 이것을 시도 할 것이다. – devson

관련 문제