• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java SpellingOptions类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.solr.spelling.SpellingOptions的典型用法代码示例。如果您正苦于以下问题:Java SpellingOptions类的具体用法?Java SpellingOptions怎么用?Java SpellingOptions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



SpellingOptions类属于org.apache.solr.spelling包,在下文中一共展示了SpellingOptions类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: getSuggestions

import org.apache.solr.spelling.SpellingOptions; //导入依赖的package包/类
@Override
public SpellingResult getSuggestions(SpellingOptions options) throws IOException {

  SpellingResult result = new SpellingResult();
  //just spit back out the results

  // sort the keys to make ordering predictable
  Iterator<String> iterator = options.customParams.getParameterNamesIterator();
  List<String> lst = new ArrayList<>();
  while (iterator.hasNext()) {
    lst.add(iterator.next());
  }
  Collections.sort(lst);

  int i = 0;
  for (String name : lst) {
    String value = options.customParams.get(name);
    result.add(new Token(name, i, i+1),  Collections.singletonList(value));
    i += 2;
  }    
  return result;
}
 
开发者ID:europeana,项目名称:search,代码行数:23,代码来源:DummyCustomParamSpellChecker.java


示例2: getLookupResults

import org.apache.solr.spelling.SpellingOptions; //导入依赖的package包/类
private List<LookupResult> getLookupResults(SpellingOptions options, Token currentToken) throws IOException {
    CharsRef scratch = new CharsRef();
    scratch.chars = currentToken.buffer();
    scratch.offset = 0;
    scratch.length = currentToken.length();
    boolean onlyMorePopular = (options.suggestMode == SuggestMode.SUGGEST_MORE_POPULAR) &&
            !(lookup instanceof WFSTCompletionLookup) &&
            !(lookup instanceof AnalyzingSuggester);

    List<LookupResult> suggestions = lookup.lookup(scratch, onlyMorePopular, options.count);
    if (suggestions == null || suggestions.size() == 0) {
        return null;
    }

    return suggestions;
}
 
开发者ID:DiceTechJobs,项目名称:SolrPlugins,代码行数:17,代码来源:DiceMultipleCaseSuggester.java


示例3: getSuggestions

import org.apache.solr.spelling.SpellingOptions; //导入依赖的package包/类
@Override
public SpellingResult getSuggestions(SpellingOptions options) throws IOException {
  SpellingResult result = super.getSuggestions(options);
  if (options.extendedResults) {
    for (Map.Entry<?, LinkedHashMap<String, Integer>> suggestion : result.getSuggestions().entrySet()) {
      Object token = suggestion.getKey();
      int freq = 0;
      for (Map.Entry<String, Integer> e : suggestion.getValue().entrySet()) {
        if (e.getKey().equals(token.toString())) {
          freq = e.getValue();
          break;
        }
      }
      result.addFrequency((Token) token, freq);
    }
  }
  return result;
}
 
开发者ID:safarijv,项目名称:ifpress-solr-plugin,代码行数:19,代码来源:MultiSuggester.java


示例4: getSuggestions

import org.apache.solr.spelling.SpellingOptions; //导入依赖的package包/类
@Override
public SpellingResult getSuggestions(SpellingOptions options) throws IOException {

  SpellingResult result = new SpellingResult();
  //just spit back out the results

  // sort the keys to make ordering predictable
  Iterator<String> iterator = options.customParams.getParameterNamesIterator();
  List<String> lst = new ArrayList<String>();
  while (iterator.hasNext()) {
    lst.add(iterator.next());
  }
  Collections.sort(lst);

  int i = 0;
  for (String name : lst) {
    String value = options.customParams.get(name);
    result.add(new Token(name, i, i+1),  Collections.singletonList(value));
    i += 2;
  }    
  return result;
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:23,代码来源:DummyCustomParamSpellChecker.java


示例5: getSuggestions

import org.apache.solr.spelling.SpellingOptions; //导入依赖的package包/类
@Override
public SpellingResult getSuggestions(SpellingOptions options) throws IOException {
  LOG.debug("getSuggestions: " + options.tokens);
  if (lookup == null) {
    LOG.info("Lookup is null - invoke spellchecker.build first");
    return EMPTY_RESULT;
  }
  SpellingResult res = new SpellingResult();
  CharsRef scratch = new CharsRef();
  for (Token t : options.tokens) {
    scratch.chars = t.buffer();
    scratch.offset = 0;
    scratch.length = t.length();
    boolean onlyMorePopular = (options.suggestMode == SuggestMode.SUGGEST_MORE_POPULAR) &&
      !(lookup instanceof WFSTCompletionLookup) &&
      !(lookup instanceof AnalyzingSuggester);
    List<LookupResult> suggestions = lookup.lookup(scratch, onlyMorePopular, options.count);
    if (suggestions == null) {
      continue;
    }
    if (options.suggestMode != SuggestMode.SUGGEST_MORE_POPULAR) {
      Collections.sort(suggestions);
    }
    for (LookupResult lr : suggestions) {
      res.add(t, lr.key.toString(), (int)lr.value);
    }
  }
  return res;
}
 
开发者ID:europeana,项目名称:search,代码行数:30,代码来源:Suggester.java


示例6: getSuggestions

import org.apache.solr.spelling.SpellingOptions; //导入依赖的package包/类
@Override
public SpellingResult getSuggestions(SpellingOptions options) throws IOException {
    LOG.debug("getSuggestions: " + options.tokens);
    if (lookup == null) {
        LOG.info("Lookup is null - invoke spellchecker.build first");
        return EMPTY_RESULT;
    }
    SpellingResult res = new SpellingResult();
    CharsRef scratch = new CharsRef();

    for (Token currentToken : options.tokens) {
        scratch.chars = currentToken.buffer();
        scratch.offset = 0;
        scratch.length = currentToken.length();
        boolean onlyMorePopular = (options.suggestMode == SuggestMode.SUGGEST_MORE_POPULAR) &&
                !(lookup instanceof WFSTCompletionLookup) &&
                !(lookup instanceof AnalyzingSuggester);

        // get more than the requested suggestions as a lot get collapsed by the corrections
        List<LookupResult> suggestions = lookup.lookup(scratch, onlyMorePopular, options.count * 10);
        if (suggestions == null || suggestions.size() == 0) {
            continue;
        }

        if (options.suggestMode != SuggestMode.SUGGEST_MORE_POPULAR) {
            Collections.sort(suggestions);
        }

        final LinkedHashMap<String, Integer> lhm = new LinkedHashMap<String, Integer>();
        for (LookupResult lr : suggestions) {
            String suggestion = lr.key.toString();
            if(this.suggestionAnalyzer != null) {
                String correction = getAnalyzerResult(suggestion);
                // multiple could map to the same, so don't repeat suggestions
                if(!isStringNullOrEmpty(correction)){
                    if(lhm.containsKey(correction)){
                        lhm.put(correction, lhm.get(correction) + (int) lr.value);
                    }
                    else {
                        lhm.put(correction, (int) lr.value);
                    }
                }
            }
            else {
                lhm.put(suggestion, (int) lr.value);
            }

            if(lhm.size() >= options.count){
                break;
            }
        }

        // sort by new doc frequency
        Map<String, Integer> orderedMap = null;
        if (options.suggestMode != SuggestMode.SUGGEST_MORE_POPULAR){
            // retain the sort order from above
            orderedMap = lhm;
        }
        else {
            orderedMap = new TreeMap<String, Integer>(new Comparator<String>() {
                @Override
                public int compare(String s1, String s2) {
                    return lhm.get(s2).compareTo(lhm.get(s1));
                }
            });
            orderedMap.putAll(lhm);
        }

        for(Map.Entry<String, Integer> entry: orderedMap.entrySet()){
            res.add(currentToken, entry.getKey(), entry.getValue());
        }

    }
    return res;
}
 
开发者ID:DiceTechJobs,项目名称:SolrPlugins,代码行数:76,代码来源:DiceSuggester.java


示例7: getSuggestions

import org.apache.solr.spelling.SpellingOptions; //导入依赖的package包/类
@Override
public SpellingResult getSuggestions(SpellingOptions options) throws IOException {
    LOG.debug("getSuggestions: " + options.tokens);
    if (lookup == null) {
        LOG.info("Lookup is null - invoke spellchecker.build first");
        return EMPTY_RESULT;
    }

    SpellingResult res = new SpellingResult();
    for (Token currentToken : options.tokens) {
        String tokenText = currentToken.toString();

        // we need to ensure that we combine matches for different cases, and take the most common
        // where multiple case versions exist
        final Hashtable<String, LookupResult> htSuggestions = new Hashtable<String, LookupResult>();
        final Hashtable<String, Integer> htSuggestionCounts = new Hashtable<String, Integer>();

        for(String sToken: generateCaseVariants(tokenText)){

            Token newToken = newToken(currentToken, sToken);
            List<LookupResult> tmpSuggestions = getLookupResults(options, newToken);
            if(tmpSuggestions != null){
                for(LookupResult lu: tmpSuggestions) {
                    final String key = lu.key.toString().toLowerCase();
                    LookupResult existing = htSuggestions.get(key);
                    if(existing != null) {
                        // replace if more frequent
                        if (lu.value > existing.value) {
                            htSuggestions.put(key, lu);
                        }
                        htSuggestionCounts.put(key, htSuggestionCounts.get(key) + (int)lu.value);
                    }
                    else{
                        htSuggestions.put(key, lu);
                        htSuggestionCounts.put(key, (int)lu.value);
                    }
                }
            }
        }

        List<String> suggestions = new ArrayList<String>(htSuggestions.keySet());
        if (options.suggestMode != SuggestMode.SUGGEST_MORE_POPULAR) {
            Collections.sort(suggestions);
        }
        else{
            Collections.sort(suggestions, new Comparator<String>() {
                public int compare(String sug1, String sug2) {
                    int sug1Count = htSuggestionCounts.get(sug1);
                    int sug2Count = htSuggestionCounts.get(sug2);
                    return sug2Count - sug1Count;
                }
            });
        }

        for (String match : suggestions) {
            LookupResult lr = htSuggestions.get(match);
            res.add(currentToken, lr.key.toString(), (int)lr.value);
        }

    }
    return res;
}
 
开发者ID:DiceTechJobs,项目名称:SolrPlugins,代码行数:63,代码来源:DiceMultipleCaseSuggester.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Pipe类代码示例发布时间:2022-05-22
下一篇:
Java FactoryBlockPattern类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap