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


Java SolrResourceLoader.newInstance方法代码示例

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


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

示例1: init

import org.apache.solr.core.SolrResourceLoader; //导入方法依赖的package包/类
@Override
protected void init(IndexSchema schema, Map<String, String> args) {
  SolrResourceLoader loader = schema.getResourceLoader();
  if (args.containsKey(SERIALIZER_ARGNAME)) {
    serializer = loader.newInstance(args.remove(SERIALIZER_ARGNAME), TextTransformer.class);
  }
  if (args.containsKey(DISPLAYIZER_ARGNAME)) {
    displayizer = loader.newInstance(args.remove(DISPLAYIZER_ARGNAME), TextTransformer.class);
  }
  if (args.containsKey(PAYLOAD_HANDLER_ARGNAME)) {
    payloadHandler = loader.newInstance(args.remove(PAYLOAD_HANDLER_ARGNAME), FacetPayload.class);
  } else {
    payloadHandler = new DefaultPayloadHandler();
  }
  if (args.containsKey(HIERARCHY_LEVEL_ARGNAME)) {
    hierarchyLevel = loader.newInstance(args.remove(HIERARCHY_LEVEL_ARGNAME), Integer.class);
  }
  delim = initDelim(hierarchyLevel);
  delimBytes = delim.getBytes(StandardCharsets.UTF_8);
  super.init(schema, args);
}
 
开发者ID:upenn-libraries,项目名称:solrplugins,代码行数:22,代码来源:CaseInsensitiveSortingTextField.java

示例2: getConfig

import org.apache.solr.core.SolrResourceLoader; //导入方法依赖的package包/类
public static CacheConfig getConfig(SolrConfig solrConfig, Node node) {
  if (node==null) return null;
  CacheConfig config = new CacheConfig();
  config.nodeName = node.getNodeName();
  config.args = DOMUtil.toMap(node.getAttributes());
  String nameAttr = config.args.get("name");  // OPTIONAL
  if (nameAttr==null) {
    config.args.put("name",config.nodeName);
  }

  SolrResourceLoader loader = solrConfig.getResourceLoader();
  config.cacheImpl = config.args.get("class");
  config.regenImpl = config.args.get("regenerator");
  config.clazz = loader.findClass(config.cacheImpl, SolrCache.class);
  if (config.regenImpl != null) {
    config.regenerator = loader.newInstance(config.regenImpl, CacheRegenerator.class);
  }
  
  return config;
}
 
开发者ID:europeana,项目名称:search,代码行数:21,代码来源:CacheConfig.java

示例3: readSimilarity

import org.apache.solr.core.SolrResourceLoader; //导入方法依赖的package包/类
static SimilarityFactory readSimilarity(SolrResourceLoader loader, Node node) {
  if (node==null) {
    return null;
  } else {
    SimilarityFactory similarityFactory;
    final String classArg = ((Element) node).getAttribute(SimilarityFactory.CLASS_NAME);
    final Object obj = loader.newInstance(classArg, Object.class, "search.similarities.");
    if (obj instanceof SimilarityFactory) {
      // configure a factory, get a similarity back
      final NamedList<Object> namedList = DOMUtil.childNodesToNamedList(node);
      namedList.add(SimilarityFactory.CLASS_NAME, classArg);
      SolrParams params = SolrParams.toSolrParams(namedList);
      similarityFactory = (SimilarityFactory)obj;
      similarityFactory.init(params);
    } else {
      // just like always, assume it's a Similarity and get a ClassCastException - reasonable error handling
      similarityFactory = new SimilarityFactory() {
        @Override
        public Similarity getSimilarity() {
          return (Similarity) obj;
        }
      };
    }
    return similarityFactory;
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:27,代码来源:IndexSchema.java

示例4: readSimilarity

import org.apache.solr.core.SolrResourceLoader; //导入方法依赖的package包/类
static SimilarityFactory readSimilarity(SolrResourceLoader loader, Node node) {
  if (node==null) {
    return null;
  } else {
    SimilarityFactory similarityFactory;
    final Object obj = loader.newInstance(((Element) node).getAttribute("class"), Object.class, "search.similarities.");
    if (obj instanceof SimilarityFactory) {
      // configure a factory, get a similarity back
      SolrParams params = SolrParams.toSolrParams(DOMUtil.childNodesToNamedList(node));
      similarityFactory = (SimilarityFactory)obj;
      similarityFactory.init(params);
    } else {
      // just like always, assume it's a Similarity and get a ClassCastException - reasonable error handling
      similarityFactory = new SimilarityFactory() {
        @Override
        public Similarity getSimilarity() {
          return (Similarity) obj;
        }
      };
    }
    return similarityFactory;
  }
}
 
开发者ID:netboynb,项目名称:search-core,代码行数:24,代码来源:IndexSchema.java

示例5: inform

import org.apache.solr.core.SolrResourceLoader; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void inform(SolrCore core) {
  if (initParams != null) {
    log.info("Initializing Clustering Engines");

    // Our target list of engines, split into search-results and document clustering.
    SolrResourceLoader loader = core.getResourceLoader();

    for (Map.Entry<String,Object> entry : initParams) {
      if ("engine".equals(entry.getKey())) {
        NamedList<Object> engineInitParams = (NamedList<Object>) entry.getValue();
        
        String engineClassName = StringUtils.defaultIfBlank( 
            (String) engineInitParams.get("classname"),
            CarrotClusteringEngine.class.getName()); 

        // Instantiate the clustering engine and split to appropriate map. 
        final ClusteringEngine engine = loader.newInstance(engineClassName, ClusteringEngine.class);
        final String name = StringUtils.defaultIfBlank(engine.init(engineInitParams, core), "");
        final ClusteringEngine previousEntry;
        if (engine instanceof SearchClusteringEngine) {
          previousEntry = searchClusteringEngines.put(name, (SearchClusteringEngine) engine);
        } else if (engine instanceof DocumentClusteringEngine) {
          previousEntry = documentClusteringEngines.put(name, (DocumentClusteringEngine) engine);
        } else {
          log.warn("Unknown type of a clustering engine for class: " + engineClassName);
          continue;
        }
        if (previousEntry != null) {
          log.warn("Duplicate clustering engine component named '" + name + "'.");
        }
      }
    }

    // Set up the default engine key for both types of engines.
    setupDefaultEngine("search results clustering", searchClusteringEngines);
    setupDefaultEngine("document clustering", documentClusteringEngines);

    log.info("Finished Initializing Clustering Engines");
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:43,代码来源:ClusteringComponent.java

示例6: inform

import org.apache.solr.core.SolrResourceLoader; //导入方法依赖的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

示例7: newStorageIO

import org.apache.solr.core.SolrResourceLoader; //导入方法依赖的package包/类
/**
 * Creates a new StorageIO instance for a Solr core, taking into account
 * whether the core is running in cloud mode as well as initArgs. 
 */
public static StorageIO newStorageIO(String collection, SolrResourceLoader resourceLoader, NamedList<String> initArgs) {
  StorageIO storageIO = null;

  SolrZkClient zkClient = null;
  String zkConfigName = null;
  if (resourceLoader instanceof ZkSolrResourceLoader) {
    zkClient = ((ZkSolrResourceLoader)resourceLoader).getZkController().getZkClient();
    try {
      zkConfigName = ((ZkSolrResourceLoader)resourceLoader).getZkController().
          getZkStateReader().readConfigName(collection);
    } catch (Exception e) {
      log.error("Failed to get config name for collection {} due to: {}", 
          collection, e.toString());
    } 
    if (zkConfigName == null) {
      throw new SolrException(ErrorCode.SERVER_ERROR, 
          "Could not find config name for collection:" + collection);
    }
  }
  
  if (initArgs.get(STORAGE_IO_CLASS_INIT_ARG) != null) {
    storageIO = resourceLoader.newInstance(initArgs.get(STORAGE_IO_CLASS_INIT_ARG), StorageIO.class); 
  } else {
    if (zkClient != null) {
      String znodeBase = "/configs/"+zkConfigName;
      log.info("Setting up ZooKeeper-based storage for the RestManager with znodeBase: "+znodeBase);      
      storageIO = new ManagedResourceStorage.ZooKeeperStorageIO(zkClient, znodeBase);
    } else {
      storageIO = new FileStorageIO();        
    }
  }
  
  if (storageIO instanceof FileStorageIO) {
    // using local fs, if storageDir is not set in the solrconfig.xml, assume the configDir for the core
    if (initArgs.get(STORAGE_DIR_INIT_ARG) == null) {
      File configDir = new File(resourceLoader.getConfigDir());
      boolean hasAccess = false;
      try {
        hasAccess = configDir.isDirectory() && configDir.canWrite();
      } catch (java.security.AccessControlException ace) {}
      
      if (hasAccess) {
        initArgs.add(STORAGE_DIR_INIT_ARG, configDir.getAbsolutePath());
      } else {
        // most likely this is because of a unit test 
        // that doesn't have write-access to the config dir
        // while this failover approach is not ideal, it's better
        // than causing the core to fail esp. if managed resources aren't being used
        log.warn("Cannot write to config directory "+configDir.getAbsolutePath()+
            "; switching to use InMemory storage instead.");
        storageIO = new ManagedResourceStorage.InMemoryStorageIO();
      }
    }       
  }
  
  storageIO.configure(resourceLoader, initArgs);     
  
  return storageIO;
}
 
开发者ID:europeana,项目名称:search,代码行数:64,代码来源:ManagedResourceStorage.java

示例8: create

import org.apache.solr.core.SolrResourceLoader; //导入方法依赖的package包/类
@Override
protected FieldType create( SolrResourceLoader loader, 
                            String name, 
                            String className, 
                            Node node ) throws Exception {

  FieldType ft = loader.newInstance(className, FieldType.class);
  ft.setTypeName(name);
  
  String expression = "./analyzer[@type='query']";
  Node anode = (Node)xpath.evaluate(expression, node, XPathConstants.NODE);
  Analyzer queryAnalyzer = readAnalyzer(anode);

  expression = "./analyzer[@type='multiterm']";
  anode = (Node)xpath.evaluate(expression, node, XPathConstants.NODE);
  Analyzer multiAnalyzer = readAnalyzer(anode);

  // An analyzer without a type specified, or with type="index"
  expression = "./analyzer[not(@type)] | ./analyzer[@type='index']";
  anode = (Node)xpath.evaluate(expression, node, XPathConstants.NODE);
  Analyzer analyzer = readAnalyzer(anode);

  // a custom similarity[Factory]
  expression = "./similarity";
  anode = (Node)xpath.evaluate(expression, node, XPathConstants.NODE);
  SimilarityFactory simFactory = IndexSchema.readSimilarity(loader, anode);
  if (null != simFactory) {
    ft.setSimilarity(simFactory);
  }
  
  if (null == queryAnalyzer) {
    queryAnalyzer = analyzer;
    ft.setIsExplicitQueryAnalyzer(false);
  } else {
    ft.setIsExplicitQueryAnalyzer(true);
  }
  if (null == analyzer) {
    analyzer = queryAnalyzer;
    ft.setIsExplicitAnalyzer(false);
  } else {
    ft.setIsExplicitAnalyzer(true);
  }

  if (null != analyzer) {
    ft.setIndexAnalyzer(analyzer);
    ft.setQueryAnalyzer(queryAnalyzer);
    if (ft instanceof TextField) {
      if (null == multiAnalyzer) {
        multiAnalyzer = constructMultiTermAnalyzer(queryAnalyzer);
        ((TextField)ft).setIsExplicitMultiTermAnalyzer(false);
      } else {
        ((TextField)ft).setIsExplicitMultiTermAnalyzer(true);
      }
      ((TextField)ft).setMultiTermAnalyzer(multiAnalyzer);
    }
  }
  if (ft instanceof SchemaAware){
    schemaAware.add((SchemaAware) ft);
  }
  return ft;
}
 
开发者ID:europeana,项目名称:search,代码行数:62,代码来源:FieldTypePluginLoader.java

示例9: inform

import org.apache.solr.core.SolrResourceLoader; //导入方法依赖的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

示例10: inform

import org.apache.solr.core.SolrResourceLoader; //导入方法依赖的package包/类
@Override
public void inform(SolrCore core) {
  if (initParams != null) {
    log.info("Initializing Clustering Engines");
    boolean searchHasDefault = false;
    boolean documentHasDefault = false;
    for (int i = 0; i < initParams.size(); i++) {
      if (initParams.getName(i).equals("engine")) {
        NamedList engineNL = (NamedList) initParams.getVal(i);
        String className = (String) engineNL.get("classname");
        if (className == null) {
          className = CarrotClusteringEngine.class.getName();
        }
        SolrResourceLoader loader = core.getResourceLoader();
        ClusteringEngine clusterer = loader.newInstance(className, ClusteringEngine.class);
        if (clusterer != null) {
          String name = clusterer.init(engineNL, core);
          if (name != null) {
            boolean isDefault = name.equals(ClusteringEngine.DEFAULT_ENGINE_NAME);
            if (clusterer instanceof SearchClusteringEngine) {
              if (isDefault == true && searchHasDefault == false) {
                searchHasDefault = true;
              } else if (isDefault == true && searchHasDefault == true) {
                throw new RuntimeException("More than one engine is missing name: " + engineNL);
              }
              searchClusteringEngines.put(name, (SearchClusteringEngine) clusterer);
            } else if (clusterer instanceof DocumentClusteringEngine) {
              if (isDefault == true && documentHasDefault == false) {
                searchHasDefault = true;
              } else if (isDefault == true && documentHasDefault == true) {
                throw new RuntimeException("More than one engine is missing name: " + engineNL);
              }
              documentClusteringEngines.put(name, (DocumentClusteringEngine) clusterer);
            }
          } else {
            if (clusterer instanceof SearchClusteringEngine && searchHasDefault == false) {
              searchClusteringEngines.put(ClusteringEngine.DEFAULT_ENGINE_NAME, (SearchClusteringEngine) clusterer);
              searchHasDefault = true;
            } else if (clusterer instanceof DocumentClusteringEngine && documentHasDefault == false) {
              documentClusteringEngines.put(ClusteringEngine.DEFAULT_ENGINE_NAME, (DocumentClusteringEngine) clusterer);
              documentHasDefault = true;
            } else {
              throw new RuntimeException("More than one engine is missing name: " + engineNL);
            }
          }
        }
      }
    }
    log.info("Finished Initializing Clustering Engines");
  }
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:52,代码来源:ClusteringComponent.java

示例11: inform

import org.apache.solr.core.SolrResourceLoader; //导入方法依赖的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.getSchema();
      String fieldTypeName = (String) initParams.get("queryAnalyzerFieldType");
      FieldType fieldType = schema.getFieldTypes().get(fieldTypeName);
      Analyzer analyzer = fieldType == null ? new WhitespaceAnalyzer(core.getSolrConfig().luceneMatchVersion)
              : fieldType.getQueryAnalyzer();
      //TODO: There's got to be a better way!  Where's Spring when you need it?
      queryConverter.setAnalyzer(analyzer);
    }
  }
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:70,代码来源:SpellCheckComponent.java

示例12: create

import org.apache.solr.core.SolrResourceLoader; //导入方法依赖的package包/类
@Override
protected FieldType create( SolrResourceLoader loader, 
                            String name, 
                            String className, 
                            Node node ) throws Exception {

  FieldType ft = loader.newInstance(className, FieldType.class);
  ft.setTypeName(name);
  
  String expression = "./analyzer[@type='query']";
  Node anode = (Node)xpath.evaluate(expression, node, XPathConstants.NODE);
  Analyzer queryAnalyzer = readAnalyzer(anode);

  expression = "./analyzer[@type='multiterm']";
  anode = (Node)xpath.evaluate(expression, node, XPathConstants.NODE);
  Analyzer multiAnalyzer = readAnalyzer(anode);

  // An analyzer without a type specified, or with type="index"
  expression = "./analyzer[not(@type)] | ./analyzer[@type='index']";
  anode = (Node)xpath.evaluate(expression, node, XPathConstants.NODE);
  Analyzer analyzer = readAnalyzer(anode);

  // a custom similarity[Factory]
  expression = "./similarity";
  anode = (Node)xpath.evaluate(expression, node, XPathConstants.NODE);
  SimilarityFactory simFactory = IndexSchema.readSimilarity(loader, anode);
  if (null != simFactory) {
    ft.setSimilarity(simFactory);
  }
  
  if (null == queryAnalyzer) {
    queryAnalyzer = analyzer;
    ft.setIsExplicitQueryAnalyzer(false);
  } else {
    ft.setIsExplicitQueryAnalyzer(true);
  }
  if (null == analyzer) {
    analyzer = queryAnalyzer;
    ft.setIsExplicitAnalyzer(false);
  } else {
    ft.setIsExplicitAnalyzer(true);
  }

  if (null != analyzer) {
    ft.setAnalyzer(analyzer);
    ft.setQueryAnalyzer(queryAnalyzer);
    if (ft instanceof TextField) {
      if (null == multiAnalyzer) {
        multiAnalyzer = constructMultiTermAnalyzer(queryAnalyzer);
        ((TextField)ft).setIsExplicitMultiTermAnalyzer(false);
      } else {
        ((TextField)ft).setIsExplicitMultiTermAnalyzer(true);
      }
      ((TextField)ft).setMultiTermAnalyzer(multiAnalyzer);
    }
  }
  if (ft instanceof SchemaAware){
    schemaAware.add((SchemaAware) ft);
  }
  return ft;
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:62,代码来源:FieldTypePluginLoader.java

示例13: create

import org.apache.solr.core.SolrResourceLoader; //导入方法依赖的package包/类
/**
 * Create a plugin from an XML configuration.  Plugins are defined using:
 * <pre class="prettyprint">
 * {@code
 * <plugin name="name1" class="solr.ClassName">
 *      ...
 * </plugin>}
 * </pre>
 * 
 * @param name - The registered name.  In the above example: "name1"
 * @param className - class name for requested plugin.  In the above example: "solr.ClassName"
 * @param node - the XML node defining this plugin
 */
@SuppressWarnings("unchecked")
protected T create( SolrResourceLoader loader, String name, String className, Node node ) throws Exception
{
  return loader.newInstance(className, pluginClassType, getDefaultPackages());
}
 
开发者ID:europeana,项目名称:search,代码行数:19,代码来源:AbstractPluginLoader.java


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