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


Java DOMUtil.getAttr方法代码示例

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


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

示例1: getProperty

import org.apache.solr.util.DOMUtil; //导入方法依赖的package包/类
public String getProperty(String coreName, String property, String defaultVal) {
  
  synchronized (coreNodes) {
    for (int idx = 0; idx < coreNodes.getLength(); ++idx) {
      Node node = coreNodes.item(idx);
      if (coreName.equals(DOMUtil.getAttr(node, CoreDescriptor.CORE_NAME,
          null))) {
        String propVal = DOMUtil.getAttr(node, property);
        if (propVal == null)
          propVal = defaultVal;
        return propVal;
      }
    }
  }
  return defaultVal;
  
}
 
开发者ID:europeana,项目名称:search,代码行数:18,代码来源:ConfigSolrXmlOld.java

示例2: bootstrapConf

import org.apache.solr.util.DOMUtil; //导入方法依赖的package包/类
/**
 * If in SolrCloud mode, upload config sets for each SolrCore in solr.xml.
 */
public static void bootstrapConf(SolrZkClient zkClient, Config cfg, String solrHome) throws IOException,
    KeeperException, InterruptedException {
  log.info("bootstraping config into ZooKeeper using solr.xml");
  NodeList nodes = (NodeList)cfg.evaluate("solr/cores/core", XPathConstants.NODESET);

  for (int i=0; i<nodes.getLength(); i++) {
    Node node = nodes.item(i);
    String rawName = DOMUtil.substituteProperty(DOMUtil.getAttr(node, "name", null), new Properties());
    String instanceDir = DOMUtil.getAttr(node, "instanceDir", null);
    File idir = new File(instanceDir);
    if (!idir.isAbsolute()) {
      idir = new File(solrHome, instanceDir);
    }
    String confName = DOMUtil.substituteProperty(DOMUtil.getAttr(node, "collection", null), new Properties());
    if (confName == null) {
      confName = rawName;
    }
    File udir = new File(idir, "conf");
    log.info("Uploading directory " + udir + " with name " + confName + " for SolrCore " + rawName);
    ZkController.uploadConfigDir(zkClient, udir, confName);
  }
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:26,代码来源:ZkController.java

示例3: addCoreProperty

import org.apache.solr.util.DOMUtil; //导入方法依赖的package包/类
private void addCoreProperty(Map<String,String> coreAttribs, Node node, String name,
    String value, String defaultValue) {
  if (node == null) {
    coreAttribs.put(name, value);
    return;
  }
  
  if (node != null) {
    String rawAttribValue = DOMUtil.getAttr(node, name, null);
    if (value == null) {
      coreAttribs.put(name, rawAttribValue);
      return;
    }
    if (rawAttribValue == null && defaultValue != null && value.equals(defaultValue)) {
      return;
    }
    if (rawAttribValue != null && value.equals(DOMUtil.substituteProperty(rawAttribValue, loader.getCoreProperties()))){
      coreAttribs.put(name, rawAttribValue);
    } else {
      coreAttribs.put(name, value);
    }
  }

}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:25,代码来源:CoreContainer.java

示例4: addCoreProperty

import org.apache.solr.util.DOMUtil; //导入方法依赖的package包/类
private void addCoreProperty(Map<String, String> coreAttribs, Node node, String name, String value, String defaultValue) {
	if(node == null) {
		coreAttribs.put(name, value);
		return;
	}

	if(node != null) {
		String rawAttribValue = DOMUtil.getAttr(node, name, null);
		if(value == null) {
			coreAttribs.put(name, rawAttribValue);
			return;
		}
		if(rawAttribValue == null && defaultValue != null && value.equals(defaultValue)) {
			return;
		}
		if(rawAttribValue != null && value.equals(DOMUtil.substituteProperty(rawAttribValue, loader.getCoreProperties()))) {
			coreAttribs.put(name, rawAttribValue);
		} else {
			coreAttribs.put(name, value);
		}
	}

}
 
开发者ID:netboynb,项目名称:search-core,代码行数:24,代码来源:CoreContainer.java

示例5: getProperty

import org.apache.solr.util.DOMUtil; //导入方法依赖的package包/类
public String getProperty(String coreName, String property, String defaultVal) {
  
  synchronized (coreNodes) {
    for (int idx = 0; idx < coreNodes.getLength(); ++idx) {
      Node node = coreNodes.item(idx);
      if (coreName.equals(DOMUtil.getAttr(node, CoreDescriptor.CORE_NAME,
          null))) {
        String propVal = DOMUtil.getAttr(node, property);
        if (propVal == null)
          propVal = defaultVal;
        return PropertiesUtil.substituteProperty(propVal, null);
      }
    }
  }
  return defaultVal;
  
}
 
开发者ID:yintaoxue,项目名称:read-open-source-code,代码行数:18,代码来源:ConfigSolrXmlOld.java

示例6: initLibs

import org.apache.solr.util.DOMUtil; //导入方法依赖的package包/类
private void initLibs() {
  NodeList nodes = (NodeList) evaluate("lib", XPathConstants.NODESET);
  if (nodes == null || nodes.getLength() == 0) return;
  
  log.info("Adding specified lib dirs to ClassLoader");
  SolrResourceLoader loader = getResourceLoader();
  
  try {
    for (int i = 0; i < nodes.getLength(); i++) {
      Node node = nodes.item(i);
      
      String baseDir = DOMUtil.getAttr(node, "dir");
      String path = DOMUtil.getAttr(node, "path");
      if (null != baseDir) {
        // :TODO: add support for a simpler 'glob' mutually exclusive of regex
        String regex = DOMUtil.getAttr(node, "regex");
        FileFilter filter = (null == regex) ? null : new RegexFileFilter(regex);
        loader.addToClassLoader(baseDir, filter, false);
      } else if (null != path) {
        final File file = FileUtils.resolvePath(new File(loader.getInstanceDir()), path);
        loader.addToClassLoader(file.getParent(), new FileFilter() {
          @Override
          public boolean accept(File pathname) {
            return pathname.equals(file);
          }
        }, false);
      } else {
        throw new RuntimeException(
            "lib: missing mandatory attributes: 'dir' or 'path'");
      }
    }
  } finally {
    loader.reloadLuceneSPI();
  }
}
 
开发者ID:yintaoxue,项目名称:read-open-source-code,代码行数:36,代码来源:SolrConfig.java

示例7: PluginInfo

import org.apache.solr.util.DOMUtil; //导入方法依赖的package包/类
public PluginInfo(Node node, String err, boolean requireName, boolean requireClass) {
  type = node.getNodeName();
  name = DOMUtil.getAttr(node, "name", requireName ? err : null);
  className = DOMUtil.getAttr(node, "class", requireClass ? err : null);
  initArgs = DOMUtil.childNodesToNamedList(node);
  attributes = unmodifiableMap(DOMUtil.toMap(node.getAttributes()));
  children = loadSubPlugins(node);
}
 
开发者ID:europeana,项目名称:search,代码行数:9,代码来源:PluginInfo.java

示例8: initLibs

import org.apache.solr.util.DOMUtil; //导入方法依赖的package包/类
private void initLibs() {
  NodeList nodes = (NodeList) evaluate("lib", XPathConstants.NODESET);
  if (nodes == null || nodes.getLength() == 0) return;
  
  log.info("Adding specified lib dirs to ClassLoader");
  
  try {
    for (int i = 0; i < nodes.getLength(); i++) {
      Node node = nodes.item(i);
      
      String baseDir = DOMUtil.getAttr(node, "dir");
      String path = DOMUtil.getAttr(node, "path");
      if (null != baseDir) {
        // :TODO: add support for a simpler 'glob' mutually eclusive of regex
        String regex = DOMUtil.getAttr(node, "regex");
        FileFilter filter = (null == regex) ? null : new RegexFileFilter(regex);
        getResourceLoader().addToClassLoader(baseDir, filter);
      } else if (null != path) {
        getResourceLoader().addToClassLoader(path);
      } else {
        throw new RuntimeException(
            "lib: missing mandatory attributes: 'dir' or 'path'");
      }
    }
  } finally {
    getResourceLoader().reloadLuceneSPI();
  }
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:29,代码来源:SolrConfig.java

示例9: loadCopyFields

import org.apache.solr.util.DOMUtil; //导入方法依赖的package包/类
/**
 * Loads the copy fields
 */
protected synchronized void loadCopyFields(Document document, XPath xpath) throws XPathExpressionException {
  String expression = "//" + COPY_FIELD;
  NodeList nodes = (NodeList)xpath.evaluate(expression, document, XPathConstants.NODESET);

  for (int i=0; i<nodes.getLength(); i++) {
    Node node = nodes.item(i);
    NamedNodeMap attrs = node.getAttributes();

    String source = DOMUtil.getAttr(attrs, SOURCE, COPY_FIELD + " definition");
    String dest   = DOMUtil.getAttr(attrs, DESTINATION,  COPY_FIELD + " definition");
    String maxChars = DOMUtil.getAttr(attrs, MAX_CHARS);

    int maxCharsInt = CopyField.UNLIMITED;
    if (maxChars != null) {
      try {
        maxCharsInt = Integer.parseInt(maxChars);
      } catch (NumberFormatException e) {
        log.warn("Couldn't parse " + MAX_CHARS + " attribute for " + COPY_FIELD + " from "
                + source + " to " + dest + " as integer. The whole field will be copied.");
      }
    }

    if (dest.equals(uniqueKeyFieldName)) {
      String msg = UNIQUE_KEY + " field ("+uniqueKeyFieldName+
        ") can not be the " + DESTINATION + " of a " + COPY_FIELD + "(" + SOURCE + "=" +source+")";
      log.error(msg);
      throw new SolrException(ErrorCode.SERVER_ERROR, msg);
    }
    
    registerCopyField(source, dest, maxCharsInt);
  }
    
  for (Map.Entry<SchemaField, Integer> entry : copyFieldTargetCounts.entrySet()) {
    if (entry.getValue() > 1 && !entry.getKey().multiValued())  {
      log.warn("Field " + entry.getKey().name + " is not multivalued "+
          "and destination for multiple " + COPY_FIELDS + " ("+
          entry.getValue()+")");
    }
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:44,代码来源:IndexSchema.java

示例10: loadQLTBMap

import org.apache.solr.util.DOMUtil; //导入方法依赖的package包/类
/**
 * Load the QLTB map from a Config.
 *
 * Read and process the "boosts/query" XPath nodes from the given
 * Config, and build them into a QLTB map. The XML format is described
 * in the class documentation.
 *
 * The result of this function is a map of (analyzed) query strings
 * with their respective lists of boosted query terms. These are
 * ConstantScoreQuery instances for each term with the corresponding
 * boost factor. (Invalid - i.e. non-numerical - boost factors are
 * logged as warnings).
 *
 * The SOLR core that is passed into this function is necessary for
 * determinating the FieldType of the boosted fields. Only with the
 * correct field type is it possible to boost non-string fields, as
 * these non-string values need to be ft.readableToIndexed().
 *
 * @param cfg
 *            Config object to read the XML QLTB from
 * @param core
 *            SOLR Core the query is performed on
 * @return QLTB map
 *
 * @throws IOException
 *             If the query could not be analysed
 */
private Map<String, List<Query>> loadQLTBMap(final Config cfg, final SolrCore core) throws IOException {
    Map<String, List<Query>> map = new HashMap<String, List<Query>>();
    NodeList nodes = (NodeList) cfg.evaluate("boosts/query", XPathConstants.NODESET);
    for (int i = 0; i < nodes.getLength(); i++) {
        Node node = nodes.item(i);
        String qstr = DOMUtil.getAttr(node, "text", "missing query 'text'");
        qstr = getAnalyzedQuery(qstr);
        NodeList children = node.getChildNodes();
        List<Query> termBoosts = new ArrayList<Query>();
        for (int j = 0; j < children.getLength(); j++) {
            Node child = children.item(j);
            if (!child.getNodeName().equals("term")) {
                continue;
            }
            String field = DOMUtil.getAttr(child, "field", "missing 'field'");
            String value = DOMUtil.getAttr(child, "value", "missing 'value'");
            String boost = DOMUtil.getAttr(child, "boost", "missing 'boost'");
            float termBoost = 1;
            try {
                termBoost = Float.parseFloat(boost);
            } catch (NumberFormatException e) {
                log.warn(
                    "invalid boost " + boost + " for query \"" + qstr
                    + "\", term: \"" + field + ":" + value + "\": "
                    +  e.getMessage()
                );
                continue;
            }
            // without readableToIndexed QLTB boosting would only work
            // for string field types
            FieldType ft = core.getLatestSchema().getField(field).getType();
            value = ft.readableToIndexed(value);
            Term t = new Term(field, value);
            TermQuery tq = new TermQuery(t);
            ConstantScoreQuery csq = new ConstantScoreQuery(tq);
            csq.setBoost(termBoost);
            termBoosts.add(csq);
        }
        map.put(qstr, termBoosts);
    }
    return map;
}
 
开发者ID:solute,项目名称:qltb,代码行数:70,代码来源:QLTBComponent.java


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