当前位置: 首页>>代码示例>>Java>>正文


Java CharsRefBuilder.length方法代码示例

本文整理汇总了Java中org.apache.lucene.util.CharsRefBuilder.length方法的典型用法代码示例。如果您正苦于以下问题:Java CharsRefBuilder.length方法的具体用法?Java CharsRefBuilder.length怎么用?Java CharsRefBuilder.length使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.lucene.util.CharsRefBuilder的用法示例。


在下文中一共展示了CharsRefBuilder.length方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: analyze

import org.apache.lucene.util.CharsRefBuilder; //导入方法依赖的package包/类
private CharsRef analyze(Analyzer analyzer, String text) throws IOException {
	CharsRefBuilder charsRefBuilder = new CharsRefBuilder();
	try (TokenStream ts = analyzer.tokenStream("", text)) {
		CharTermAttribute termAtt = ts.addAttribute(CharTermAttribute.class);
		PositionIncrementAttribute posIncAtt = ts.addAttribute(PositionIncrementAttribute.class);
		ts.reset();
		while (ts.incrementToken()) {
			int length = termAtt.length();
			if (length == 0) {
				throw new IllegalArgumentException("term: " + text + " analyzed to a zero-length token");
			}
			charsRefBuilder.grow(charsRefBuilder.length() + length + 1); /* current + word + separator */
			if (charsRefBuilder.length() > 0) {
				charsRefBuilder.append(CcWordSet.WORD_SEPARATOR);
			}
			charsRefBuilder.append(termAtt);
		}
		ts.end();
	}
	if (charsRefBuilder.length() == 0) {
		return null;
	}
	charsRefBuilder.append(CcWordSet.WORD_END);
	return charsRefBuilder.get();
}
 
开发者ID:thihy,项目名称:cc-analysis,代码行数:26,代码来源:CcWordsFilterTest.java

示例2: innerExecute

import org.apache.lucene.util.CharsRefBuilder; //导入方法依赖的package包/类
@Override
protected Suggest.Suggestion<? extends Suggest.Suggestion.Entry<? extends Suggest.Suggestion.Entry.Option>> innerExecute(String name,
        final CompletionSuggestionContext suggestionContext, final IndexSearcher searcher, CharsRefBuilder spare) throws IOException {
    if (suggestionContext.getFieldType() != null) {
        final CompletionFieldMapper.CompletionFieldType fieldType = suggestionContext.getFieldType();
        CompletionSuggestion completionSuggestion = new CompletionSuggestion(name, suggestionContext.getSize());
        spare.copyUTF8Bytes(suggestionContext.getText());
        CompletionSuggestion.Entry completionSuggestEntry = new CompletionSuggestion.Entry(
            new Text(spare.toString()), 0, spare.length());
        completionSuggestion.addTerm(completionSuggestEntry);
        TopSuggestDocsCollector collector = new TopDocumentsCollector(suggestionContext.getSize());
        suggest(searcher, suggestionContext.toQuery(), collector);
        int numResult = 0;
        for (TopSuggestDocs.SuggestScoreDoc suggestScoreDoc : collector.get().scoreLookupDocs()) {
            TopDocumentsCollector.SuggestDoc suggestDoc = (TopDocumentsCollector.SuggestDoc) suggestScoreDoc;
            // collect contexts
            Map<String, Set<CharSequence>> contexts = Collections.emptyMap();
            if (fieldType.hasContextMappings() && suggestDoc.getContexts().isEmpty() == false) {
                contexts = fieldType.getContextMappings().getNamedContexts(suggestDoc.getContexts());
            }
            if (numResult++ < suggestionContext.getSize()) {
                CompletionSuggestion.Entry.Option option = new CompletionSuggestion.Entry.Option(suggestDoc.doc,
                    new Text(suggestDoc.key.toString()), suggestDoc.score, contexts);
                completionSuggestEntry.addOption(option);
            } else {
                break;
            }
        }
        return completionSuggestion;
    }
    return null;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:33,代码来源:CompletionSuggester.java

示例3: analyze

import org.apache.lucene.util.CharsRefBuilder; //导入方法依赖的package包/类
/** Sugar: analyzes the text with the analyzer and
 *  separates by {@link SynonymMap#WORD_SEPARATOR}.
 *  reuse and its chars must not be null. */
public CharsRef analyze(String text, CharsRefBuilder reuse) throws IOException {
  try (TokenStream ts = analyzer.tokenStream("", text)) {
    CharTermAttribute termAtt = ts.addAttribute(CharTermAttribute.class);
    PositionIncrementAttribute posIncAtt = ts.addAttribute(PositionIncrementAttribute.class);
    ts.reset();
    reuse.clear();
    while (ts.incrementToken()) {
      int length = termAtt.length();
      if (length == 0) {
        throw new IllegalArgumentException("term: " + text + " analyzed to a zero-length token");
      }
      if (posIncAtt.getPositionIncrement() != 1) {
        throw new IllegalArgumentException("term: " + text + " analyzed to a token with posinc != 1");
      }
      reuse.grow(reuse.length() + length + 1); /* current + word + separator */
      int end = reuse.length();
      if (reuse.length() > 0) {
        reuse.setCharAt(end++, SynonymMap.WORD_SEPARATOR);
        reuse.setLength(reuse.length() + 1);
      }
      System.arraycopy(termAtt.buffer(), 0, reuse.chars(), end, length);
      reuse.setLength(reuse.length() + length);
    }
    ts.end();
  }
  if (reuse.length() == 0) {
    throw new IllegalArgumentException("term: " + text + " was completely eliminated by analyzer");
  }
  return reuse.get();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:34,代码来源:SynonymMap.java

示例4: buildResultEntry

import org.apache.lucene.util.CharsRefBuilder; //导入方法依赖的package包/类
private static PhraseSuggestion.Entry buildResultEntry(SuggestionContext suggestion, CharsRefBuilder spare, double cutoffScore) {
    spare.copyUTF8Bytes(suggestion.getText());
    return new PhraseSuggestion.Entry(new Text(spare.toString()), 0, spare.length(), cutoffScore);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:5,代码来源:PhraseSuggester.java

示例5: buildResultEntry

import org.apache.lucene.util.CharsRefBuilder; //导入方法依赖的package包/类
private PhraseSuggestion.Entry buildResultEntry(PhraseSuggestionContext suggestion, CharsRefBuilder spare, double cutoffScore) {
    spare.copyUTF8Bytes(suggestion.getText());
    return new PhraseSuggestion.Entry(new Text(spare.toString()), 0, spare.length(), cutoffScore);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:5,代码来源:PhraseSuggester.java


注:本文中的org.apache.lucene.util.CharsRefBuilder.length方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。