當前位置: 首頁>>代碼示例>>Java>>正文


Java SolrCore.getResourceLoader方法代碼示例

本文整理匯總了Java中org.apache.solr.core.SolrCore.getResourceLoader方法的典型用法代碼示例。如果您正苦於以下問題:Java SolrCore.getResourceLoader方法的具體用法?Java SolrCore.getResourceLoader怎麽用?Java SolrCore.getResourceLoader使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.solr.core.SolrCore的用法示例。


在下文中一共展示了SolrCore.getResourceLoader方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: inform

import org.apache.solr.core.SolrCore; //導入方法依賴的package包/類
@Override
public void inform(SolrCore core) {
  resourceLoader = core.getResourceLoader();

  // test that our engines & scripts are valid

  SolrQueryResponse rsp = new SolrQueryResponse();
  SolrQueryRequest req = new LocalSolrQueryRequest(core, new ModifiableSolrParams());
  try {
    initEngines(req, rsp);
  } catch (Exception e) {
    String msg = "Unable to initialize scripts: " + e.getMessage();
    log.error(msg, e);
    throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, msg, e);
  } finally {
    req.close();
  }

  
}
 
開發者ID:europeana,項目名稱:search,代碼行數:21,代碼來源:StatelessScriptUpdateProcessorFactory.java

示例2: SolrResourceLocator

import org.apache.solr.core.SolrCore; //導入方法依賴的package包/類
public SolrResourceLocator(SolrCore core, SolrParams initParams) {
  resourceLoader = core.getResourceLoader();
  
  @SuppressWarnings("deprecation")
  String lexicalResourcesDir = initParams.get(CarrotParams.LEXICAL_RESOURCES_DIR);
  String resourcesDir = initParams.get(CarrotParams.RESOURCES_DIR);
  carrot2ResourcesDir = firstNonNull(resourcesDir, lexicalResourcesDir, CarrotClusteringEngine.CARROT_RESOURCES_PREFIX);
}
 
開發者ID:europeana,項目名稱:search,代碼行數:9,代碼來源:SolrResourceLocator.java

示例3: inform

import org.apache.solr.core.SolrCore; //導入方法依賴的package包/類
@Override
public void inform(SolrCore core) {
  solrResourceLoader = core.getResourceLoader();

  for (TypeMapping typeMapping : typeMappings) {
    typeMapping.populateValueClasses(core);
  }
}
 
開發者ID:europeana,項目名稱:search,代碼行數:9,代碼來源:AddSchemaFieldsUpdateProcessorFactory.java

示例4: getAdminFileFromZooKeeper

import org.apache.solr.core.SolrCore; //導入方法依賴的package包/類
public static String getAdminFileFromZooKeeper(SolrQueryRequest req, SolrQueryResponse rsp, SolrZkClient zkClient,
                                               Set<String> hiddenFiles)
    throws KeeperException, InterruptedException {
  String adminFile = null;
  SolrCore core = req.getCore();

  final ZkSolrResourceLoader loader = (ZkSolrResourceLoader) core
      .getResourceLoader();
  String confPath = loader.getCollectionZkPath();

  String fname = req.getParams().get("file", null);
  if (fname == null) {
    adminFile = confPath;
  } else {
    fname = fname.replace('\\', '/'); // normalize slashes
    if (isHiddenFile(req, rsp, fname, true, hiddenFiles)) {
      return null;
    }
    if (fname.startsWith("/")) { // Only files relative to conf are valid
      fname = fname.substring(1);
    }
    adminFile = confPath + "/" + fname;
  }

  // Make sure the file exists, is readable and is not a hidden file
  if (!zkClient.exists(adminFile, true)) {
    log.error("Can not find: " + adminFile);
    rsp.setException(new SolrException(SolrException.ErrorCode.NOT_FOUND, "Can not find: "
        + adminFile));
    return null;
  }

  return adminFile;
}
 
開發者ID:europeana,項目名稱:search,代碼行數:35,代碼來源:ShowFileRequestHandler.java

示例5: inform

import org.apache.solr.core.SolrCore; //導入方法依賴的package包/類
public void inform(SolrCore core) {
	loader = core.getResourceLoader();
	//solrHome = new File(loader.getInstanceDir());
}
 
開發者ID:wanghaile,項目名稱:mmseg4j,代碼行數:5,代碼來源:MMseg4jHandler.java

示例6: inform

import org.apache.solr.core.SolrCore; //導入方法依賴的package包/類
@Override
public void inform( SolrCore core ) {
  if (initParams != null) {
    SolrResourceLoader resourceLoader = core.getResourceLoader( );
      
    synonymsFile = (String)initParams.get( "synonyms" );
    if (synonymsFile != null) {
      Analyzer analyzer = new Analyzer() {
      @Override
        protected TokenStreamComponents createComponents(String fieldName) {
          Tokenizer tokenizer = new KeywordTokenizer();
          return new TokenStreamComponents(tokenizer, tokenizer );
        }
      };
              
      try {
        SolrSynonymParser parser = new SolrSynonymParser(true, true, analyzer);
        CharsetDecoder decoder = StandardCharsets.UTF_8.newDecoder().onMalformedInput(CodingErrorAction.REPORT)
                                                                    .onUnmappableCharacter(CodingErrorAction.REPORT);
                  
        parser.parse(new InputStreamReader( resourceLoader.openResource(synonymsFile), decoder));
        this.synonyms = parser.build( );
      }
      catch ( Exception e ) {
        // ???
        Log.warn( "Parsing Synonyms Got Exception " + e );
      }
    }
      
    String stopwordsFile = (String)initParams.get( "stopwords" );
    if (stopwordsFile != null) {
      this.stopwords = new HashSet<String>( );
      try {
        BufferedReader br = new BufferedReader( new InputStreamReader( resourceLoader.openResource( stopwordsFile )));
        String line = null;
        while ((line = br.readLine( )) != null) {
          stopwords.add( line.toLowerCase( ) );
        }
        br.close( );
      }
      catch ( IOException ioe ) {
        Log.warn( "Adding Stopwords Got Exception " + ioe );
      }
    }
  }
    
  core.registerFirstSearcherListener( this );
  core.registerNewSearcherListener( this );
}
 
開發者ID:lucidworks,項目名稱:query-autofiltering-component,代碼行數:50,代碼來源:QueryAutoFilteringComponent.java

示例7: inform

import org.apache.solr.core.SolrCore; //導入方法依賴的package包/類
@Override
public void inform( SolrCore core ) {
  if (initParams != null) {
    SolrResourceLoader resourceLoader = core.getResourceLoader( );
      
    synonymsFile = (String)initParams.get( "synonyms" );
    if (synonymsFile != null) {
      Analyzer analyzer = new Analyzer() {
      @Override
        protected TokenStreamComponents createComponents(String fieldName, Reader reader) {
          Tokenizer tokenizer = new KeywordTokenizer( reader );
          return new TokenStreamComponents(tokenizer, tokenizer );
        }
      };
              
      try {
        SolrSynonymParser parser = new SolrSynonymParser(true, true, analyzer);
        CharsetDecoder decoder = StandardCharsets.UTF_8.newDecoder().onMalformedInput(CodingErrorAction.REPORT)
                                                                    .onUnmappableCharacter(CodingErrorAction.REPORT);
                  
        parser.parse(new InputStreamReader( resourceLoader.openResource(synonymsFile), decoder));
        this.synonyms = parser.build( );
      }
      catch ( Exception e ) {
        // ???
        Log.warn( "Parsing Synonyms Got Exception " + e );
      }
    }
      
    String stopwordsFile = (String)initParams.get( "stopwords" );
    if (stopwordsFile != null) {
      this.stopwords = new HashSet<String>( );
      try {
        BufferedReader br = new BufferedReader( new InputStreamReader( resourceLoader.openResource( stopwordsFile )));
        String line = null;
        while ((line = br.readLine( )) != null) {
          stopwords.add( line.toLowerCase( ) );
        }
        br.close( );
      }
      catch ( IOException ioe ) {
        Log.warn( "Adding Stopwords Got Exception " + ioe );
      }
    }
  }
    
  core.registerFirstSearcherListener( this );
  core.registerNewSearcherListener( this );
}
 
開發者ID:lucidworks,項目名稱:query-autofiltering-component,代碼行數:50,代碼來源:QueryAutoFilteringComponent.java

示例8: inform

import org.apache.solr.core.SolrCore; //導入方法依賴的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

示例9: inform

import org.apache.solr.core.SolrCore; //導入方法依賴的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

示例10: inform

import org.apache.solr.core.SolrCore; //導入方法依賴的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.core.SolrCore.getResourceLoader方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。