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


Java FieldType.getQueryAnalyzer方法代码示例

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


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

示例1: create

import org.apache.solr.schema.FieldType; //导入方法依赖的package包/类
@Override
public Lookup create(NamedList params, SolrCore core) {
  Object fieldTypeName = params.get(QUERY_ANALYZER);
  if (fieldTypeName == null) {
    throw new IllegalArgumentException("Error in configuration: " + QUERY_ANALYZER + " parameter is mandatory");
  }
  FieldType ft = core.getLatestSchema().getFieldTypeByName(fieldTypeName.toString());
  if (ft == null) {
    throw new IllegalArgumentException("Error in configuration: " + fieldTypeName.toString() + " is not defined in the schema");
  }
  
  Analyzer indexAnalyzer = ft.getIndexAnalyzer();
  Analyzer queryAnalyzer = ft.getQueryAnalyzer();
  
  int grams = (params.get(NGRAMS) != null) 
      ? Integer.parseInt(params.get(NGRAMS).toString()) 
      : FreeTextSuggester.DEFAULT_GRAMS;
  
  byte separator = (params.get(SEPARATOR) != null) 
      ? params.get(SEPARATOR).toString().getBytes(StandardCharsets.UTF_8)[0]
      : FreeTextSuggester.DEFAULT_SEPARATOR;
  
  return new FreeTextSuggester(indexAnalyzer, queryAnalyzer, grams, separator);
}
 
开发者ID:europeana,项目名称:search,代码行数:25,代码来源:FreeTextLookupFactory.java

示例2: selectAnalyzer

import org.apache.solr.schema.FieldType; //导入方法依赖的package包/类
private Analyzer selectAnalyzer(FieldType fieldType) {
	if(mode == null)
	 {
	     return fieldType.getAnalyzer();
	 }
	 else if(mode == Mode.INDEX)
	 {
		 return fieldType.getIndexAnalyzer();
	 }
	 else if(mode == Mode.QUERY)
	 {
		 return fieldType.getQueryAnalyzer();
	 }
	 else
	 {
		 return null;
	 }
}
 
开发者ID:Alfresco,项目名称:community-edition-old,代码行数:19,代码来源:MLAnalayser.java

示例3: create

import org.apache.solr.schema.FieldType; //导入方法依赖的package包/类
@Override
public Lookup create(NamedList params, SolrCore core) {
  Object fieldTypeName = params.get(QUERY_ANALYZER);
  if (fieldTypeName == null) {
    throw new IllegalArgumentException("Error in configuration: " + QUERY_ANALYZER + " parameter is mandatory");
  }
  FieldType ft = core.getLatestSchema().getFieldTypeByName(fieldTypeName.toString());
  if (ft == null) {
    throw new IllegalArgumentException("Error in configuration: " + fieldTypeName.toString() + " is not defined in the schema");
  }
  
  Analyzer indexAnalyzer = ft.getAnalyzer();
  Analyzer queryAnalyzer = ft.getQueryAnalyzer();
  
  int grams = (params.get(NGRAMS) != null) 
      ? Integer.parseInt(params.get(NGRAMS).toString()) 
      : FreeTextSuggester.DEFAULT_GRAMS;
  
  byte separator = (params.get(SEPARATOR) != null) 
      ? params.get(SEPARATOR).toString().getBytes(IOUtils.CHARSET_UTF_8)[0]
      : FreeTextSuggester.DEFAULT_SEPARATOR;
  
  return new FreeTextSuggester(indexAnalyzer, queryAnalyzer, grams, separator);
}
 
开发者ID:yintaoxue,项目名称:read-open-source-code,代码行数:25,代码来源:FreeTextLookupFactory.java

示例4: parse

import org.apache.solr.schema.FieldType; //导入方法依赖的package包/类
@Override
public Query parse() throws SyntaxError {
  IndexReaderContext context = req.getSearcher().getTopReaderContext();
  for(FieldFeatureExtractorFactory factory: featuresSpec){
    String fieldName = factory.getFieldName();
    FieldType fieldType = req.getSchema().getFieldType(fieldName);
    Analyzer analyzer = fieldType.getQueryAnalyzer();
    factory.init(context, FieldFeatureExtractorFactory.terms(fieldName, qstr, analyzer));
  }

  return new LinearWeightQuery(featuresSpec, weights);
}
 
开发者ID:NLP4L,项目名称:solr,代码行数:13,代码来源:LinearWeightQParserPlugin.java

示例5: parse

import org.apache.solr.schema.FieldType; //导入方法依赖的package包/类
@Override
public Query parse() throws SyntaxError {
  IndexReaderContext context = req.getSearcher().getTopReaderContext();
  for(FieldFeatureExtractorFactory factory: featuresSpec){
    String fieldName = factory.getFieldName();
    FieldType fieldType = req.getSchema().getFieldType(fieldName);
    Analyzer analyzer = fieldType.getQueryAnalyzer();
    factory.init(context, FieldFeatureExtractorFactory.terms(fieldName, qstr, analyzer));
  }

  return new PRankQuery(featuresSpec, weights, bs);
}
 
开发者ID:NLP4L,项目名称:solr,代码行数:13,代码来源:PRankQParserPlugin.java

示例6: create

import org.apache.solr.schema.FieldType; //导入方法依赖的package包/类
@Override
public Lookup create(@SuppressWarnings("rawtypes") NamedList params, SolrCore core) {
    // mandatory parameter
    Object fieldTypeName = params.get(QUERY_ANALYZER);
    if (fieldTypeName == null) {
        throw new IllegalArgumentException("Error in configuration: " + QUERY_ANALYZER + " parameter is mandatory");
    }
    FieldType ft = core.getLatestSchema().getFieldTypeByName(fieldTypeName.toString());
    if (ft == null) {
        throw new IllegalArgumentException("Error in configuration: " + fieldTypeName.toString() + " is not defined in the schema");
    }
    Analyzer indexAnalyzer = ft.getIndexAnalyzer();
    Analyzer queryAnalyzer = ft.getQueryAnalyzer();
  
    // optional parameters
  
    String indexPath = params.get(INDEX_PATH) != null ?
            params.get(INDEX_PATH).toString() :
                    DEFAULT_INDEX_PATH;
  
    int minPrefixChars = params.get(MIN_PREFIX_CHARS) != null
            ? Integer.parseInt(params.get(MIN_PREFIX_CHARS).toString())
                    : AnalyzingInfixSuggester.DEFAULT_MIN_PREFIX_CHARS;
            
    Boolean highlight = params.getBooleanArg(HIGHLIGHT);
    if (highlight == null) {
        highlight = DEFAULT_HIGHLIGHT;
    }

     try {
         return new SafariInfixSuggester(core.getSolrConfig().luceneMatchVersion, 
                                       FSDirectory.open(new File(indexPath)), indexAnalyzer,
                                       queryAnalyzer, minPrefixChars, highlight);
     } catch (IOException e) {
         throw new SolrException(ErrorCode.SERVER_ERROR, e);
     }
}
 
开发者ID:safarijv,项目名称:ifpress-solr-plugin,代码行数:38,代码来源:SafeInfixLookupFactory.java

示例7: create

import org.apache.solr.schema.FieldType; //导入方法依赖的package包/类
@Override
public Lookup create(NamedList params, SolrCore core) {
  // mandatory parameter
  Object fieldTypeName = params.get(QUERY_ANALYZER);
  if (fieldTypeName == null) {
    throw new IllegalArgumentException("Error in configuration: " + QUERY_ANALYZER + " parameter is mandatory");
  }
  FieldType ft = core.getSchema().getFieldTypeByName(fieldTypeName.toString());
  Analyzer indexAnalyzer = ft.getAnalyzer();
  Analyzer queryAnalyzer = ft.getQueryAnalyzer();
  
  // optional parameters
  
  boolean exactMatchFirst = params.get(EXACT_MATCH_FIRST) != null
  ? Boolean.valueOf(params.get(EXACT_MATCH_FIRST).toString())
  : true;
  
  boolean preserveSep = params.get(PRESERVE_SEP) != null
  ? Boolean.valueOf(params.get(PRESERVE_SEP).toString())
  : true;
  
  int flags = 0;
  if (exactMatchFirst) {
    flags |= AnalyzingSuggester.EXACT_FIRST;
  }
  if (preserveSep) {
    flags |= AnalyzingSuggester.PRESERVE_SEP;
  }
  
  int maxSurfaceFormsPerAnalyzedForm = params.get(MAX_SURFACE_FORMS) != null
  ? Integer.parseInt(params.get(MAX_SURFACE_FORMS).toString())
  : 256;
  
  int maxGraphExpansions = params.get(MAX_EXPANSIONS) != null
  ? Integer.parseInt(params.get(MAX_EXPANSIONS).toString())
  : -1;

  
  return new AnalyzingSuggester(indexAnalyzer, queryAnalyzer, flags, maxSurfaceFormsPerAnalyzedForm, maxGraphExpansions);
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:41,代码来源:AnalyzingLookupFactory.java

示例8: create

import org.apache.solr.schema.FieldType; //导入方法依赖的package包/类
@Override
public Lookup create(NamedList params, SolrCore core) {
  // mandatory parameter
  Object fieldTypeName = params.get(QUERY_ANALYZER);
  if (fieldTypeName == null) {
    throw new IllegalArgumentException("Error in configuration: " + QUERY_ANALYZER + " parameter is mandatory");
  }
  FieldType ft = core.getLatestSchema().getFieldTypeByName(fieldTypeName.toString());
  if (ft == null) {
    throw new IllegalArgumentException("Error in configuration: " + fieldTypeName.toString() + " is not defined in the schema");
  }
  Analyzer indexAnalyzer = ft.getAnalyzer();
  Analyzer queryAnalyzer = ft.getQueryAnalyzer();
  
  // optional parameters
  
  String indexPath = params.get(INDEX_PATH) != null
  ? params.get(INDEX_PATH).toString()
  : DEFAULT_INDEX_PATH;
  
  int minPrefixChars = params.get(MIN_PREFIX_CHARS) != null
  ? Integer.parseInt(params.get(MIN_PREFIX_CHARS).toString())
  : AnalyzingInfixSuggester.DEFAULT_MIN_PREFIX_CHARS;

  BlenderType blenderType = getBlenderType(params.get(BLENDER_TYPE));
  
  int numFactor = params.get(NUM_FACTOR) != null
  ? Integer.parseInt(params.get(NUM_FACTOR).toString())
  : BlendedInfixSuggester.DEFAULT_NUM_FACTOR;
  
  try {
    return new BlendedInfixSuggester(core.getSolrConfig().luceneMatchVersion, 
        new File(indexPath), indexAnalyzer, queryAnalyzer, minPrefixChars, blenderType, numFactor);
  } catch (IOException e) {
    throw new RuntimeException();
  }
}
 
开发者ID:yintaoxue,项目名称:read-open-source-code,代码行数:38,代码来源:BlendedInfixLookupFactory.java

示例9: create

import org.apache.solr.schema.FieldType; //导入方法依赖的package包/类
@Override
public Lookup create(NamedList params, SolrCore core) {
  // mandatory parameter
  Object fieldTypeName = params.get(QUERY_ANALYZER);
  if (fieldTypeName == null) {
    throw new IllegalArgumentException("Error in configuration: " + QUERY_ANALYZER + " parameter is mandatory");
  }
  FieldType ft = core.getLatestSchema().getFieldTypeByName(fieldTypeName.toString());
  if (ft == null) {
    throw new IllegalArgumentException("Error in configuration: " + fieldTypeName.toString() + " is not defined in the schema");
  }
  Analyzer indexAnalyzer = ft.getAnalyzer();
  Analyzer queryAnalyzer = ft.getQueryAnalyzer();
  
  // optional parameters
  
  String indexPath = params.get(INDEX_PATH) != null
  ? params.get(INDEX_PATH).toString()
  : DEFAULT_INDEX_PATH;
  
  int minPrefixChars = params.get(MIN_PREFIX_CHARS) != null
  ? Integer.parseInt(params.get(MIN_PREFIX_CHARS).toString())
  : AnalyzingInfixSuggester.DEFAULT_MIN_PREFIX_CHARS;

  try {
    return new AnalyzingInfixSuggester(core.getSolrConfig().luceneMatchVersion, 
        new File(indexPath), indexAnalyzer, queryAnalyzer, minPrefixChars);
  } catch (IOException e) {
    throw new RuntimeException();
  }
}
 
开发者ID:yintaoxue,项目名称:read-open-source-code,代码行数:32,代码来源:AnalyzingInfixLookupFactory.java

示例10: inform

import org.apache.solr.schema.FieldType; //导入方法依赖的package包/类
@Override
public void inform(SolrCore core) {
  if (initParams != null) {
    LOG.info("Initializing spell checkers");
    boolean hasDefault = false;
    for (int i = 0; i < initParams.size(); i++) {
      if (initParams.getName(i).equals("spellchecker")) {
        NamedList spellchecker = (NamedList) initParams.getVal(i);
        String className = (String) spellchecker.get("classname");
        // TODO: this is a little bit sneaky: warn if class isnt supplied
        // so that its mandatory in a future release?
        if (className == null)
          className = IndexBasedSpellChecker.class.getName();
        SolrResourceLoader loader = core.getResourceLoader();
        SolrSpellChecker checker = loader.newInstance(className, SolrSpellChecker.class);
        if (checker != null) {
          String dictionary = checker.init(spellchecker, core);
          if (dictionary != null) {
            boolean isDefault = dictionary.equals(SolrSpellChecker.DEFAULT_DICTIONARY_NAME);
            if (isDefault == true && hasDefault == false){
              hasDefault = true;
            } else if (isDefault == true && hasDefault == true){
              throw new RuntimeException("More than one dictionary is missing name.");
            }
            spellCheckers.put(dictionary, checker);
          } else {
            if (hasDefault == false){
              spellCheckers.put(SolrSpellChecker.DEFAULT_DICTIONARY_NAME, checker);
              hasDefault = true;
            } else {
              throw new RuntimeException("More than one dictionary is missing name.");
            }
          }
          // Register event listeners for this SpellChecker
          core.registerFirstSearcherListener(new SpellCheckerListener(core, checker, false, false));
          boolean buildOnCommit = Boolean.parseBoolean((String) spellchecker.get("buildOnCommit"));
          boolean buildOnOptimize = Boolean.parseBoolean((String) spellchecker.get("buildOnOptimize"));
          if (buildOnCommit || buildOnOptimize)   {
            LOG.info("Registering newSearcher listener for spellchecker: " + checker.getDictionaryName());
            core.registerNewSearcherListener(new SpellCheckerListener(core, checker, buildOnCommit, buildOnOptimize));
          }
        } else {
          throw new RuntimeException("Can't load spell checker: " + className);
        }
      }
   }

    Map<String, QueryConverter> queryConverters = new HashMap<>();
    core.initPlugins(queryConverters,QueryConverter.class);

    //ensure that there is at least one query converter defined
    if (queryConverters.size() == 0) {
      LOG.info("No queryConverter defined, using default converter");
      queryConverters.put("queryConverter", new SpellingQueryConverter());
    }

    //there should only be one
    if (queryConverters.size() == 1) {
      queryConverter = queryConverters.values().iterator().next();
      IndexSchema schema = core.getLatestSchema();
      String fieldTypeName = (String) initParams.get("queryAnalyzerFieldType");
      FieldType fieldType = schema.getFieldTypes().get(fieldTypeName);
      Analyzer analyzer = fieldType == null ? new WhitespaceAnalyzer()
              : fieldType.getQueryAnalyzer();
      //TODO: There's got to be a better way!  Where's Spring when you need it?
      queryConverter.setAnalyzer(analyzer);
    }
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:70,代码来源:SpellCheckComponent.java

示例11: create

import org.apache.solr.schema.FieldType; //导入方法依赖的package包/类
@Override
public Lookup create(NamedList params, SolrCore core) {
  // mandatory parameter
  Object fieldTypeName = params.get(QUERY_ANALYZER);
  if (fieldTypeName == null) {
    throw new IllegalArgumentException("Error in configuration: " + QUERY_ANALYZER + " parameter is mandatory");
  }
  FieldType ft = core.getLatestSchema().getFieldTypeByName(fieldTypeName.toString());
  if (ft == null) {
    throw new IllegalArgumentException("Error in configuration: " + fieldTypeName.toString() + " is not defined in the schema");
  }
  Analyzer indexAnalyzer = ft.getIndexAnalyzer();
  Analyzer queryAnalyzer = ft.getQueryAnalyzer();
  
  // optional parameters
  
  String indexPath = params.get(INDEX_PATH) != null
  ? params.get(INDEX_PATH).toString()
  : DEFAULT_INDEX_PATH;
  if (new File(indexPath).isAbsolute() == false) {
    indexPath = core.getDataDir() + File.separator + indexPath;
  }
  
  int minPrefixChars = params.get(MIN_PREFIX_CHARS) != null
  ? Integer.parseInt(params.get(MIN_PREFIX_CHARS).toString())
  : AnalyzingInfixSuggester.DEFAULT_MIN_PREFIX_CHARS;

  BlenderType blenderType = getBlenderType(params.get(BLENDER_TYPE));
  
  int numFactor = params.get(NUM_FACTOR) != null
  ? Integer.parseInt(params.get(NUM_FACTOR).toString())
  : BlendedInfixSuggester.DEFAULT_NUM_FACTOR;
  
  try {
    return new BlendedInfixSuggester(core.getSolrConfig().luceneMatchVersion, 
                                     FSDirectory.open(new File(indexPath)),
                                     indexAnalyzer, queryAnalyzer, minPrefixChars,
                                     blenderType, numFactor) {
      @Override
      public List<LookupResult> lookup(CharSequence key, Set<BytesRef> contexts, int num, boolean allTermsRequired, boolean doHighlight) throws IOException {
        List<LookupResult> res = super.lookup(key, contexts, num, allTermsRequired, doHighlight);
        if (doHighlight) {
          List<LookupResult> res2 = new ArrayList<>();
          for(LookupResult hit : res) {
            res2.add(new LookupResult(hit.highlightKey.toString(),
                                      hit.highlightKey,
                                      hit.value,
                                      hit.payload,
                                      hit.contexts));
          }
          res = res2;
        }

        return res;
      }
    };
  } catch (IOException e) {
    throw new RuntimeException();
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:61,代码来源:BlendedInfixLookupFactory.java

示例12: create

import org.apache.solr.schema.FieldType; //导入方法依赖的package包/类
@Override
public Lookup create(NamedList params, SolrCore core) {
  
  // mandatory parameter
  Object fieldTypeName = params.get(AnalyzingLookupFactory.QUERY_ANALYZER);
  if (fieldTypeName == null) {
    throw new IllegalArgumentException("Error in configuration: " + AnalyzingLookupFactory.QUERY_ANALYZER + " parameter is mandatory");
  }
  // retrieve index and query analyzers for the field
  FieldType ft = core.getLatestSchema().getFieldTypeByName(fieldTypeName.toString());
  if (ft == null) {
    throw new IllegalArgumentException("Error in configuration: " + fieldTypeName.toString() + " is not defined in the schema");
  }
  Analyzer indexAnalyzer = ft.getIndexAnalyzer();
  Analyzer queryAnalyzer = ft.getQueryAnalyzer();
  
  // optional parameters
  boolean exactMatchFirst = (params.get(AnalyzingLookupFactory.EXACT_MATCH_FIRST) != null)
  ? Boolean.valueOf(params.get(AnalyzingLookupFactory.EXACT_MATCH_FIRST).toString())
  : true;
      
  boolean preserveSep = (params.get(AnalyzingLookupFactory.PRESERVE_SEP) != null)
  ? Boolean.valueOf(params.get(AnalyzingLookupFactory.PRESERVE_SEP).toString())
  : true;
      
  int options = 0;
  if (exactMatchFirst) {
    options |= FuzzySuggester.EXACT_FIRST;
  }
  if (preserveSep) {
    options |= FuzzySuggester.PRESERVE_SEP;
  }
  
  int maxSurfaceFormsPerAnalyzedForm = (params.get(AnalyzingLookupFactory.MAX_SURFACE_FORMS) != null)
  ? Integer.parseInt(params.get(AnalyzingLookupFactory.MAX_SURFACE_FORMS).toString())
  : 256;
      
  int maxGraphExpansions = (params.get(AnalyzingLookupFactory.MAX_EXPANSIONS) != null)
  ? Integer.parseInt(params.get(AnalyzingLookupFactory.MAX_EXPANSIONS).toString())
  : -1;

  boolean preservePositionIncrements = params.get(AnalyzingLookupFactory.PRESERVE_POSITION_INCREMENTS) != null
  ? Boolean.valueOf(params.get(AnalyzingLookupFactory.PRESERVE_POSITION_INCREMENTS).toString())
  : false;
  
  int maxEdits = (params.get(MAX_EDITS) != null)
  ? Integer.parseInt(params.get(MAX_EDITS).toString())
  : FuzzySuggester.DEFAULT_MAX_EDITS;
  
  boolean transpositions = (params.get(TRANSPOSITIONS) != null)
  ? Boolean.parseBoolean(params.get(TRANSPOSITIONS).toString())
  : FuzzySuggester.DEFAULT_TRANSPOSITIONS;
      
  int nonFuzzyPrefix = (params.get(NON_FUZZY_PREFIX) != null)
  ? Integer.parseInt(params.get(NON_FUZZY_PREFIX).toString())
  :FuzzySuggester.DEFAULT_NON_FUZZY_PREFIX;
  
  
  int minFuzzyLength = (params.get(MIN_FUZZY_LENGTH) != null)
  ? Integer.parseInt(params.get(MIN_FUZZY_LENGTH).toString())
  :FuzzySuggester.DEFAULT_MIN_FUZZY_LENGTH;
  
  boolean unicodeAware = (params.get(UNICODE_AWARE) != null)
  ? Boolean.valueOf(params.get(UNICODE_AWARE).toString())
  : FuzzySuggester.DEFAULT_UNICODE_AWARE;
  
  return new FuzzySuggester(indexAnalyzer, queryAnalyzer, options, maxSurfaceFormsPerAnalyzedForm,
      maxGraphExpansions, preservePositionIncrements, maxEdits, transpositions, nonFuzzyPrefix,
      minFuzzyLength, unicodeAware);
}
 
开发者ID:europeana,项目名称:search,代码行数:71,代码来源:FuzzyLookupFactory.java

示例13: create

import org.apache.solr.schema.FieldType; //导入方法依赖的package包/类
@Override
public Lookup create(NamedList params, SolrCore core) {
  // mandatory parameter
  Object fieldTypeName = params.get(QUERY_ANALYZER);
  if (fieldTypeName == null) {
    throw new IllegalArgumentException("Error in configuration: " + QUERY_ANALYZER + " parameter is mandatory");
  }
  FieldType ft = core.getLatestSchema().getFieldTypeByName(fieldTypeName.toString());
  if (ft == null) {
    throw new IllegalArgumentException("Error in configuration: " + fieldTypeName.toString() + " is not defined in the schema");
  }
  Analyzer indexAnalyzer = ft.getIndexAnalyzer();
  Analyzer queryAnalyzer = ft.getQueryAnalyzer();
  
  // optional parameters
  
  String indexPath = params.get(INDEX_PATH) != null
  ? params.get(INDEX_PATH).toString()
  : DEFAULT_INDEX_PATH;
  if (new File(indexPath).isAbsolute() == false) {
    indexPath = core.getDataDir() + File.separator + indexPath;
  }
  
  int minPrefixChars = params.get(MIN_PREFIX_CHARS) != null
  ? Integer.parseInt(params.get(MIN_PREFIX_CHARS).toString())
  : AnalyzingInfixSuggester.DEFAULT_MIN_PREFIX_CHARS;

  try {
    return new AnalyzingInfixSuggester(core.getSolrConfig().luceneMatchVersion, 
                                       FSDirectory.open(new File(indexPath)), indexAnalyzer,
                                       queryAnalyzer, minPrefixChars) {
      @Override
      public List<LookupResult> lookup(CharSequence key, Set<BytesRef> contexts, int num, boolean allTermsRequired, boolean doHighlight) throws IOException {
        List<LookupResult> res = super.lookup(key, contexts, num, allTermsRequired, doHighlight);
        if (doHighlight) {
          List<LookupResult> res2 = new ArrayList<>();
          for(LookupResult hit : res) {
            res2.add(new LookupResult(hit.highlightKey.toString(),
                                      hit.highlightKey,
                                      hit.value,
                                      hit.payload,
                                      hit.contexts));
          }
          res = res2;
        }

        return res;
      }
    };
  } catch (IOException e) {
    throw new RuntimeException();
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:54,代码来源:AnalyzingInfixLookupFactory.java

示例14: create

import org.apache.solr.schema.FieldType; //导入方法依赖的package包/类
@Override
public Lookup create(NamedList params, SolrCore core) {
  // mandatory parameter
  Object fieldTypeName = params.get(QUERY_ANALYZER);
  if (fieldTypeName == null) {
    throw new IllegalArgumentException("Error in configuration: " + QUERY_ANALYZER + " parameter is mandatory");
  }
  FieldType ft = core.getLatestSchema().getFieldTypeByName(fieldTypeName.toString());
  if (ft == null) {
    throw new IllegalArgumentException("Error in configuration: " + fieldTypeName.toString() + " is not defined in the schema");
  }
  
  Analyzer indexAnalyzer = ft.getIndexAnalyzer();
  Analyzer queryAnalyzer = ft.getQueryAnalyzer();
  
  // optional parameters
  
  boolean exactMatchFirst = params.get(EXACT_MATCH_FIRST) != null
  ? Boolean.valueOf(params.get(EXACT_MATCH_FIRST).toString())
  : true;
  
  boolean preserveSep = params.get(PRESERVE_SEP) != null
  ? Boolean.valueOf(params.get(PRESERVE_SEP).toString())
  : true;
  
  int flags = 0;
  if (exactMatchFirst) {
    flags |= AnalyzingSuggester.EXACT_FIRST;
  }
  if (preserveSep) {
    flags |= AnalyzingSuggester.PRESERVE_SEP;
  }
  
  int maxSurfaceFormsPerAnalyzedForm = params.get(MAX_SURFACE_FORMS) != null
  ? Integer.parseInt(params.get(MAX_SURFACE_FORMS).toString())
  : 256;
  
  int maxGraphExpansions = params.get(MAX_EXPANSIONS) != null
  ? Integer.parseInt(params.get(MAX_EXPANSIONS).toString())
  : -1;
  
  boolean preservePositionIncrements = params.get(PRESERVE_POSITION_INCREMENTS) != null
  ? Boolean.valueOf(params.get(PRESERVE_POSITION_INCREMENTS).toString())
  : false;

  
  return new AnalyzingSuggester(indexAnalyzer, queryAnalyzer, flags, maxSurfaceFormsPerAnalyzedForm,
      maxGraphExpansions, preservePositionIncrements);
}
 
开发者ID:europeana,项目名称:search,代码行数:50,代码来源:AnalyzingLookupFactory.java

示例15: inform

import org.apache.solr.schema.FieldType; //导入方法依赖的package包/类
@Override
public void inform(SolrCore core) {
    if (initParams != null) {
        LOG.info("Initializing spell checkers");
        boolean hasDefault = false;
        for (int i = 0; i < initParams.size(); i++) {
            if (initParams.getName(i).equals("spellchecker")) {
                NamedList spellchecker = (NamedList) initParams.getVal(i);
                String className = (String) spellchecker.get("classname");
                // TODO: this is a little bit sneaky: warn if class isnt supplied
                // so that its mandatory in a future release?
                if (className == null)
                    className = IndexBasedSpellChecker.class.getName();
                SolrResourceLoader loader = core.getResourceLoader();
                SolrSpellChecker checker = loader.newInstance(className, SolrSpellChecker.class);
                if (checker != null) {
                    String dictionary = checker.init(spellchecker, core);
                    if (dictionary != null) {
                        boolean isDefault = dictionary.equals(SolrSpellChecker.DEFAULT_DICTIONARY_NAME);
                        if (isDefault == true && hasDefault == false){
                            hasDefault = true;
                        } else if (isDefault == true && hasDefault == true){
                            throw new RuntimeException("More than one dictionary is missing name.");
                        }
                        spellCheckers.put(dictionary, checker);
                    } else {
                        if (hasDefault == false){
                            spellCheckers.put(SolrSpellChecker.DEFAULT_DICTIONARY_NAME, checker);
                            hasDefault = true;
                        } else {
                            throw new RuntimeException("More than one dictionary is missing name.");
                        }
                    }
                    // Register event listeners for this SpellChecker
                    core.registerFirstSearcherListener(new SpellCheckerListener(core, checker, false, false));
                    boolean buildOnCommit = Boolean.parseBoolean((String) spellchecker.get("buildOnCommit"));
                    boolean buildOnOptimize = Boolean.parseBoolean((String) spellchecker.get("buildOnOptimize"));
                    if (buildOnCommit || buildOnOptimize)   {
                        LOG.info("Registering newSearcher listener for spellchecker: " + checker.getDictionaryName());
                        core.registerNewSearcherListener(new SpellCheckerListener(core, checker, buildOnCommit, buildOnOptimize));
                    }
                } else {
                    throw new RuntimeException("Can't load spell checker: " + className);
                }
            }
        }

        Map<String, QueryConverter> queryConverters = new HashMap<String, QueryConverter>();
        core.initPlugins(queryConverters,QueryConverter.class);

        //ensure that there is at least one query converter defined
        if (queryConverters.size() == 0) {
            LOG.info("No queryConverter defined, using default converter");
            queryConverters.put("queryConverter", new SpellingQueryConverter());
        }

        //there should only be one
        if (queryConverters.size() == 1) {
            queryConverter = queryConverters.values().iterator().next();
            IndexSchema schema = core.getLatestSchema();
            String fieldTypeName = (String) initParams.get("queryAnalyzerFieldType");
            FieldType fieldType = schema.getFieldTypes().get(fieldTypeName);
            Analyzer analyzer = fieldType == null ? new WhitespaceAnalyzer() : fieldType.getQueryAnalyzer();
            //TODO: There's got to be a better way!  Where's Spring when you need it?
            queryConverter.setAnalyzer(analyzer);
        }
    }
}
 
开发者ID:DiceTechJobs,项目名称:SolrPlugins,代码行数:69,代码来源:DiceSpellCheckComponent.java


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