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

Java DOMUtils类代码示例

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

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



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

示例1: getQuery

import org.apache.lucene.queryparser.xml.DOMUtils; //导入依赖的package包/类
@Override
public Query getQuery(Element e) throws ParserException {
  String text = DOMUtils.getText(e);
  try {
    Query q = null;
    if (unSafeParser != null) {
      //synchronize on unsafe parser
      synchronized (unSafeParser) {
        q = unSafeParser.parse(text);
      }
    } else {
      String fieldName = DOMUtils.getAttribute(e, "fieldName", defaultField);
      //Create new parser
      QueryParser parser = createQueryParser(fieldName, analyzer);
      q = parser.parse(text);
    }
    q.setBoost(DOMUtils.getAttribute(e, "boost", 1.0f));
    return q;
  } catch (ParseException e1) {
    throw new ParserException(e1.getMessage());
  }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:23,代码来源:UserInputQueryBuilder.java


示例2: getFilter

import org.apache.lucene.queryparser.xml.DOMUtils; //导入依赖的package包/类
@Override
public Filter getFilter(Element e) throws ParserException {
  List<BytesRef> terms = new ArrayList<>();
  String text = DOMUtils.getNonBlankTextOrFail(e);
  String fieldName = DOMUtils.getAttributeWithInheritanceOrFail(e, "fieldName");

  TokenStream ts = null;
  try {
    ts = analyzer.tokenStream(fieldName, text);
    TermToBytesRefAttribute termAtt = ts.addAttribute(TermToBytesRefAttribute.class);
    BytesRef bytes = termAtt.getBytesRef();
    ts.reset();
    while (ts.incrementToken()) {
      termAtt.fillBytesRef();
      terms.add(BytesRef.deepCopyOf(bytes));
    }
    ts.end();
  }
  catch (IOException ioe) {
    throw new RuntimeException("Error constructing terms from index:" + ioe);
  } finally {
    IOUtils.closeWhileHandlingException(ts);
  }
  return new TermsFilter(fieldName, terms);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:26,代码来源:TermsFilterBuilder.java


示例3: getFilter

import org.apache.lucene.queryparser.xml.DOMUtils; //导入依赖的package包/类
@Override
public Filter getFilter(Element e) throws ParserException {
  BooleanFilter bf = new BooleanFilter();
  NodeList nl = e.getChildNodes();

  for (int i = 0; i < nl.getLength(); i++) {
    Node node = nl.item(i);
    if (node.getNodeName().equals("Clause")) {
      Element clauseElem = (Element) node;
      BooleanClause.Occur occurs = BooleanQueryBuilder.getOccursValue(clauseElem);

      Element clauseFilter = DOMUtils.getFirstChildOrFail(clauseElem);
      Filter f = factory.getFilter(clauseFilter);
      bf.add(new FilterClause(f, occurs));
    }
  }

  return bf;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:20,代码来源:BooleanFilterBuilder.java


示例4: getQuery

import org.apache.lucene.queryparser.xml.DOMUtils; //导入依赖的package包/类
@Override
public Query getQuery(Element e) throws ParserException {
  Element mainQueryElem = DOMUtils.getChildByTagOrFail(e, "Query");
  mainQueryElem = DOMUtils.getFirstChildOrFail(mainQueryElem);
  Query mainQuery = factory.getQuery(mainQueryElem);

  Element boostQueryElem = DOMUtils.getChildByTagOrFail(e, "BoostQuery");
  float boost = DOMUtils.getAttribute(boostQueryElem, "boost", DEFAULT_BOOST);
  boostQueryElem = DOMUtils.getFirstChildOrFail(boostQueryElem);
  Query boostQuery = factory.getQuery(boostQueryElem);

  BoostingQuery bq = new BoostingQuery(mainQuery, boostQuery, boost);

  bq.setBoost(DOMUtils.getAttribute(e, "boost", 1.0f));
  return bq;

}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:18,代码来源:BoostingQueryBuilder.java


示例5: getQuery

import org.apache.lucene.queryparser.xml.DOMUtils; //导入依赖的package包/类
@Override
public Query getQuery(Element e) throws ParserException {
  BooleanQuery bq = new BooleanQuery(DOMUtils.getAttribute(e, "disableCoord", false));
  bq.setMinimumNumberShouldMatch(DOMUtils.getAttribute(e, "minimumNumberShouldMatch", 0));
  bq.setBoost(DOMUtils.getAttribute(e, "boost", 1.0f));

  NodeList nl = e.getChildNodes();
  for (int i = 0; i < nl.getLength(); i++) {
    Node node = nl.item(i);
    if (node.getNodeName().equals("Clause")) {
      Element clauseElem = (Element) node;
      BooleanClause.Occur occurs = getOccursValue(clauseElem);

      Element clauseQuery = DOMUtils.getFirstChildOrFail(clauseElem);
      Query q = factory.getQuery(clauseQuery);
      bq.add(new BooleanClause(q, occurs));
    }
  }

  return bq;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:22,代码来源:BooleanQueryBuilder.java


示例6: getQuery

import org.apache.lucene.queryparser.xml.DOMUtils; //导入依赖的package包/类
@Override
public Query getQuery(Element e) throws ParserException {
  NodeList nl = e.getElementsByTagName("Field");
  int maxNumTerms = DOMUtils.getAttribute(e, "maxNumTerms", DEFAULT_MAX_NUM_TERMS);
  FuzzyLikeThisQuery fbq = new FuzzyLikeThisQuery(maxNumTerms, analyzer);
  fbq.setIgnoreTF(DOMUtils.getAttribute(e, "ignoreTF", DEFAULT_IGNORE_TF));

  for (int i = 0; i < nl.getLength(); i++) {
    Element fieldElem = (Element) nl.item(i);
    float minSimilarity = DOMUtils.getAttribute(fieldElem, "minSimilarity", DEFAULT_MIN_SIMILARITY);
    int prefixLength = DOMUtils.getAttribute(fieldElem, "prefixLength", DEFAULT_PREFIX_LENGTH);
    String fieldName = DOMUtils.getAttributeWithInheritance(fieldElem, "fieldName");

    String value = DOMUtils.getText(fieldElem);
    fbq.addTerms(value, fieldName, minSimilarity, prefixLength);
  }

  fbq.setBoost(DOMUtils.getAttribute(e, "boost", 1.0f));
  return fbq;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:21,代码来源:FuzzyLikeThisQueryBuilder.java


示例7: getFilter

import org.apache.lucene.queryparser.xml.DOMUtils; //导入依赖的package包/类
@Override
public Filter getFilter(Element e) throws ParserException {
  String fieldName = DOMUtils.getAttributeWithInheritanceOrFail(e, "fieldName");
  DuplicateFilter df = new DuplicateFilter(fieldName);

  String keepMode = DOMUtils.getAttribute(e, "keepMode", "first");
  if (keepMode.equalsIgnoreCase("first")) {
    df.setKeepMode(DuplicateFilter.KeepMode.KM_USE_FIRST_OCCURRENCE);
  } else if (keepMode.equalsIgnoreCase("last")) {
    df.setKeepMode(DuplicateFilter.KeepMode.KM_USE_LAST_OCCURRENCE);
  } else {
    throw new ParserException("Illegal keepMode attribute in DuplicateFilter:" + keepMode);
  }

  String processingMode = DOMUtils.getAttribute(e, "processingMode", "full");
  if (processingMode.equalsIgnoreCase("full")) {
    df.setProcessingMode(DuplicateFilter.ProcessingMode.PM_FULL_VALIDATION);
  } else if (processingMode.equalsIgnoreCase("fast")) {
    df.setProcessingMode(DuplicateFilter.ProcessingMode.PM_FAST_INVALIDATION);
  } else {
    throw new ParserException("Illegal processingMode attribute in DuplicateFilter:" + processingMode);
  }

  return df;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:26,代码来源:DuplicateFilterBuilder.java


示例8: getQuery

import org.apache.lucene.queryparser.xml.DOMUtils; //导入依赖的package包/类
@Override
public Query getQuery(Element e) throws ParserException {
  float tieBreaker = DOMUtils.getAttribute(e, "tieBreaker", 0.0f); 
  DisjunctionMaxQuery dq = new DisjunctionMaxQuery(tieBreaker);
  dq.setBoost(DOMUtils.getAttribute(e, "boost", 1.0f));

  NodeList nl = e.getChildNodes();
  for (int i = 0; i < nl.getLength(); i++) {
    Node node = nl.item(i);
    if (node instanceof Element) { // all elements are disjuncts.
      Element queryElem = (Element) node;
      Query q = factory.getQuery(queryElem);
      dq.add(q);
    }
  }

  return dq;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:19,代码来源:DisjunctionMaxQueryBuilder.java


示例9: getSpanQuery

import org.apache.lucene.queryparser.xml.DOMUtils; //导入依赖的package包/类
@Override
public SpanQuery getSpanQuery(Element e) throws ParserException {
  Element includeElem = DOMUtils.getChildByTagOrFail(e, "Include");
  includeElem = DOMUtils.getFirstChildOrFail(includeElem);

  Element excludeElem = DOMUtils.getChildByTagOrFail(e, "Exclude");
  excludeElem = DOMUtils.getFirstChildOrFail(excludeElem);

  SpanQuery include = factory.getSpanQuery(includeElem);
  SpanQuery exclude = factory.getSpanQuery(excludeElem);

  SpanNotQuery snq = new SpanNotQuery(include, exclude);

  snq.setBoost(DOMUtils.getAttribute(e, "boost", 1.0f));
  return snq;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:17,代码来源:SpanNotBuilder.java


示例10: getFilter

import org.apache.lucene.queryparser.xml.DOMUtils; //导入依赖的package包/类
@Override
public Filter getFilter(Element e) throws ParserException {
  List<BytesRef> terms = new ArrayList<BytesRef>();
  String text = DOMUtils.getNonBlankTextOrFail(e);
  String fieldName = DOMUtils.getAttributeWithInheritanceOrFail(e, "fieldName");

  try {
    TokenStream ts = analyzer.tokenStream(fieldName, new StringReader(text));
    TermToBytesRefAttribute termAtt = ts.addAttribute(TermToBytesRefAttribute.class);
    Term term = null;
    BytesRef bytes = termAtt.getBytesRef();
    ts.reset();
    while (ts.incrementToken()) {
      termAtt.fillBytesRef();
      terms.add(BytesRef.deepCopyOf(bytes));
    }
    ts.end();
    ts.close();
  }
  catch (IOException ioe) {
    throw new RuntimeException("Error constructing terms from index:" + ioe);
  }
  return new TermsFilter(fieldName, terms);
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:25,代码来源:TermsFilterBuilder.java


示例11: getSpanQuery

import org.apache.lucene.queryparser.xml.DOMUtils; //导入依赖的package包/类
@Override
public SpanQuery getSpanQuery(Element e) throws ParserException {
  String fieldName = DOMUtils.getAttributeWithInheritanceOrFail(e, "fieldName");
  String value = DOMUtils.getNonBlankTextOrFail(e);

  try {
    List<SpanQuery> clausesList = new ArrayList<SpanQuery>();
    TokenStream ts = analyzer.tokenStream(fieldName, new StringReader(value));
    TermToBytesRefAttribute termAtt = ts.addAttribute(TermToBytesRefAttribute.class);
    BytesRef bytes = termAtt.getBytesRef();
    ts.reset();
    while (ts.incrementToken()) {
      termAtt.fillBytesRef();
      SpanTermQuery stq = new SpanTermQuery(new Term(fieldName, BytesRef.deepCopyOf(bytes)));
      clausesList.add(stq);
    }
    ts.end();
    ts.close();
    SpanOrQuery soq = new SpanOrQuery(clausesList.toArray(new SpanQuery[clausesList.size()]));
    soq.setBoost(DOMUtils.getAttribute(e, "boost", 1.0f));
    return soq;
  }
  catch (IOException ioe) {
    throw new ParserException("IOException parsing value:" + value);
  }
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:27,代码来源:SpanOrTermsBuilder.java


示例12: getFilter

import org.apache.lucene.queryparser.xml.DOMUtils; //导入依赖的package包/类
@Override
public Filter getFilter(Element e) throws ParserException {
  List<BytesRef> terms = new ArrayList<BytesRef>();
  String text = DOMUtils.getNonBlankTextOrFail(e);
  String fieldName = DOMUtils.getAttributeWithInheritanceOrFail(e, "fieldName");

  TokenStream ts = null;
  try {
    ts = analyzer.tokenStream(fieldName, text);
    TermToBytesRefAttribute termAtt = ts.addAttribute(TermToBytesRefAttribute.class);
    BytesRef bytes = termAtt.getBytesRef();
    ts.reset();
    while (ts.incrementToken()) {
      termAtt.fillBytesRef();
      terms.add(BytesRef.deepCopyOf(bytes));
    }
    ts.end();
  }
  catch (IOException ioe) {
    throw new RuntimeException("Error constructing terms from index:" + ioe);
  } finally {
    IOUtils.closeWhileHandlingException(ts);
  }
  return new TermsFilter(fieldName, terms);
}
 
开发者ID:yintaoxue,项目名称:read-open-source-code,代码行数:26,代码来源:TermsFilterBuilder.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Java SortOrder类代码示例发布时间:2022-05-22
下一篇:
Java FunctionCustom类代码示例发布时间: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