2016-07-22 65 views
2

我正在使用自定義分析器來構建使用Lucene 5.4.1版本的索引文件,並且我試圖使用Luke在索引文件中查找數據。我正在嘗試將我的自定義分析器添加到Luke中,但是我沒有在分析器選項卡中找到它。Luke + lucene 5.4.1

我使用以下語法用於添加我的分析器盧克java命令「樞軸盧克與 - deps.jar; CatalogSearchAnalyzer.jar」 org.getopt.luke.Luke

我的分析器代碼`

public class CatalogSearchAnalyzer extends Analyzer { 
private Version matchVersion; 
private String termValue; 
private boolean retMultiple; 
public static final String[] STOP_WORDS = { "a", "and", "are", "as", "at", 
     "be", "but", "by", "for", "if", "in", "into", "is", "it", "no", 
     "not", "of", "on", "or", "such", "t", "that", "the", "their", 
     "then", "there", "these", "they", "this", "to", "was", "will", 
     "with" }; 
private CharArraySet stopTable; 
private int maxTokenLength; 

public CatalogSearchAnalyzer(Version matchVersion) { 
    this.stopTable = StopFilter.makeStopSet(STOP_WORDS); 
    this.maxTokenLength = 255; 

    this.matchVersion = matchVersion; 
} 

public CatalogSearchAnalyzer() { 
    this(STOP_WORDS); 
} 

public void setTermValue(String termValue) { 
} 

public void setRetMultiple(boolean retMultiple) { 
} 

public CatalogSearchAnalyzer(String[] stopWords) { 
    this.stopTable = StopFilter.makeStopSet(STOP_WORDS); 
    this.maxTokenLength = 255; 

    StopFilter.makeStopSet(stopWords); 
} 

private TokenStream getStemmingFilter(TokenStream result) { 
    PorterStemFilter temp = new PorterStemFilter(result); 
    temp.setRetMultiple(this.retMultiple); 
    return temp; 
} 

protected Analyzer.TokenStreamComponents createComponents(String fieldName)   { 
    StandardTokenizer st = new StandardTokenizer(); 
    st.setMaxTokenLength(this.maxTokenLength); 
    Tokenizer tk = st; 
    TokenStream ts = new StandardFilter(tk); 
    ts = new LowerCaseFilter(ts); 
    ts = new StopFilter(ts, this.stopTable); 
    ts = getStemmingFilter(ts); 
    return new Analyzer.TokenStreamComponents(tk, ts) { 
     protected void setReader(Reader reader) { 
      int m = CatalogSearchAnalyzer.this.maxTokenLength; 
      if (this.source instanceof CmgtTokenizer) { 
       ((CmgtTokenizer) this.source).setMaxTokenLength(m); 
      } 
      super.setReader(reader); 
     } 
    }; 
} 
} 

` 我沒有得到任何異常,而我的罐子加入盧克。

預先感謝您對此進行調查。

+0

試非樞軸版盧克https://github.com/DmitryKey/luke/releases/tag/luke-5.5.0 –

+0

^如果它沒有幫助,隨時在github上打開一個問題 –

+1

謝謝D_K它的工作,我想知道Luke – raj

回答