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

Java DateField类代码示例

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

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



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

示例1: transformValue

import org.apache.solr.schema.DateField; //导入依赖的package包/类
/**
 * Can be used to transform input values based on their {@link org.apache.solr.schema.SchemaField}
 * <p/>
 * This implementation only formats dates using the {@link org.apache.solr.common.util.DateUtil}.
 *
 * @param val    The value to transform
 * @param schFld The {@link org.apache.solr.schema.SchemaField}
 * @return The potentially new value.
 */
protected String transformValue(String val, SchemaField schFld) {
  String result = val;
  if (schFld != null && schFld.getType() instanceof DateField) {
    //try to transform the date
    try {
      Date date = DateUtil.parseDate(val, dateFormats);
      DateFormat df = DateUtil.getThreadLocalDateFormat();
      result = df.format(date);

    } catch (Exception e) {
      // Let the specific fieldType handle errors
      // throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Invalid value: " + val + " for field: " + schFld, e);
    }
  }
  return result;
}
 
开发者ID:europeana,项目名称:search,代码行数:26,代码来源:SolrContentHandler.java


示例2: handleEnable

import org.apache.solr.schema.DateField; //导入依赖的package包/类
protected void handleEnable(boolean enable) throws SolrException {
  if (healthcheck == null) {
    throw new SolrException(SolrException.ErrorCode.SERVICE_UNAVAILABLE, 
      "No healthcheck file defined.");
  }
  if ( enable ) {
    try {
      // write out when the file was created
      FileUtils.write(healthcheck, 
                      DateField.formatExternal(new Date()), "UTF-8");
    } catch (IOException e) {
      throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, 
                              "Unable to write healthcheck flag file", e);
    }
  } else {
    if (healthcheck.exists() && !healthcheck.delete()){
      throw new SolrException(SolrException.ErrorCode.NOT_FOUND,
                              "Did not successfully delete healthcheck file: "
                              +healthcheck.getAbsolutePath());
    }
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:23,代码来源:PingRequestHandler.java


示例3: appendValue

import org.apache.solr.schema.DateField; //导入依赖的package包/类
private void appendValue(Object value, StringBuilder buf, String key) {
	if (value instanceof List) {
		Iterator<String>itr = ((List<String>)value).iterator();
		while (itr.hasNext()) 
			buf.append("    <"+IXMLFields.VALUE+"><![CDATA["+itr.next()+"]]></"+IXMLFields.VALUE+">\n");

	} else {
		//MUST TEST FOR DATES
		if (key.equals(ITopicQuestsOntology.CREATED_DATE_PROPERTY) || 
			key.equals(ITopicQuestsOntology.LAST_EDIT_DATE_PROPERTY)) {
			if (value instanceof Date) {
				Date d = (Date)(value); //
				buf.append("    <"+IXMLFields.VALUE+"><![CDATA["+DateField.formatExternal(d)+"]]></"+IXMLFields.VALUE+">\n");
			} else
				buf.append("    <"+IXMLFields.VALUE+"><![CDATA["+value+"]]></"+IXMLFields.VALUE+">\n");
		} else
			buf.append("    <"+IXMLFields.VALUE+"><![CDATA["+value+"]]></"+IXMLFields.VALUE+">\n");
	}
}
 
开发者ID:agibsonccc,项目名称:solrsherlock-maven,代码行数:20,代码来源:Node.java


示例4: rangeCount

import org.apache.solr.schema.DateField; //导入依赖的package包/类
/**
 * @deprecated Use rangeCount(SchemaField,String,String,boolean,boolean) which is more generalized
 */
@Deprecated
protected int rangeCount(SchemaField sf, Date low, Date high,
                         boolean iLow, boolean iHigh) throws IOException {
  Query rangeQ = ((DateField)(sf.getType())).getRangeQuery(null, sf, low, high, iLow, iHigh);
  return searcher.numDocs(rangeQ, docs);
}
 
开发者ID:europeana,项目名称:search,代码行数:10,代码来源:SimpleFacets.java


示例5: DateRangeEndpointCalculator

import org.apache.solr.schema.DateField; //导入依赖的package包/类
public DateRangeEndpointCalculator(final SchemaField f, 
                                   final Date now) { 
  super(f); 
  this.now = now;
  if (! (field.getType() instanceof DateField) ) {
    throw new IllegalArgumentException
      ("SchemaField must use filed type extending DateField");
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:10,代码来源:SimpleFacets.java


示例6: rangeCount

import org.apache.solr.schema.DateField; //导入依赖的package包/类
/**
 * @deprecated Use rangeCount(SchemaField,String,String,boolean,boolean) which is more generalized
 */
@Deprecated
protected int rangeCount(SchemaField sf, Date low, Date high,
                         boolean iLow, boolean iHigh) throws IOException {
  Query rangeQ = ((DateField)(sf.getType())).getRangeQuery(null, sf,low,high,iLow,iHigh);
  return searcher.numDocs(rangeQ , docs);
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:10,代码来源:SimpleFacets.java


示例7: parse

import org.apache.solr.schema.DateField; //导入依赖的package包/类
@Override
public Object parse(String value) {
	try {
		return DateField.parseDate(value);
	} catch(ParseException e) {
		throw new RuntimeException("value='" + value + "' parse date error", e);
	}
}
 
开发者ID:netboynb,项目名称:search-core,代码行数:9,代码来源:CollectorFilterable.java


示例8: parseDate

import org.apache.solr.schema.DateField; //导入依赖的package包/类
private Date parseDate(String s) throws Exception {
		DateField d  = new DateField();
		return d.parseMath(null, s);
//		try {
//			if (s.endsWith("Z") || s.endsWith("z"))
//				return DateField.parseDate(s.substring(0,s.length()-1));
//			return DateField.parseDate(s);
//		} catch (java.text.ParseException e ){
//			DateField d  = new DateField();
//			return d.parseMath(null, s);
//		}
	}
 
开发者ID:gibri,项目名称:kelvin,代码行数:13,代码来源:DateRangeCondition.java


示例9: getFacetRangeCounts

import org.apache.solr.schema.DateField; //导入依赖的package包/类
void getFacetRangeCounts(String facetRange, NamedList<Object> resOuter)
    throws IOException, SyntaxError {

  final IndexSchema schema = searcher.getSchema();

  parseParams(FacetParams.FACET_RANGE, facetRange);
  String f = facetValue;

  final SchemaField sf = schema.getField(f);
  final FieldType ft = sf.getType();

  RangeEndpointCalculator<?> calc = null;

  if (ft instanceof TrieField) {
    final TrieField trie = (TrieField)ft;

    switch (trie.getType()) {
      case FLOAT:
        calc = new FloatRangeEndpointCalculator(sf);
        break;
      case DOUBLE:
        calc = new DoubleRangeEndpointCalculator(sf);
        break;
      case INTEGER:
        calc = new IntegerRangeEndpointCalculator(sf);
        break;
      case LONG:
        calc = new LongRangeEndpointCalculator(sf);
        break;
      default:
        throw new SolrException
            (SolrException.ErrorCode.BAD_REQUEST,
                "Unable to range facet on tried field of unexpected type:" + f);
    }
  } else if (ft instanceof DateField) {
    calc = new DateRangeEndpointCalculator(sf, null);
  } else if (ft instanceof SortableIntField) {
    calc = new IntegerRangeEndpointCalculator(sf);
  } else if (ft instanceof SortableLongField) {
    calc = new LongRangeEndpointCalculator(sf);
  } else if (ft instanceof SortableFloatField) {
    calc = new FloatRangeEndpointCalculator(sf);
  } else if (ft instanceof SortableDoubleField) {
    calc = new DoubleRangeEndpointCalculator(sf);
  } else {
    throw new SolrException
        (SolrException.ErrorCode.BAD_REQUEST,
            "Unable to range facet on field:" + sf);
  }

  resOuter.add(key, getFacetRangeCounts(sf, calc));
}
 
开发者ID:europeana,项目名称:search,代码行数:53,代码来源:SimpleFacets.java


示例10: formatValue

import org.apache.solr.schema.DateField; //导入依赖的package包/类
@Override
public String formatValue(Date val) {
  return ((DateField)field.getType()).toExternal(val);
}
 
开发者ID:europeana,项目名称:search,代码行数:5,代码来源:SimpleFacets.java


示例11: parseVal

import org.apache.solr.schema.DateField; //导入依赖的package包/类
@Override
protected Date parseVal(String rawval) {
  return ((DateField)field.getType()).parseMath(now, rawval);
}
 
开发者ID:europeana,项目名称:search,代码行数:5,代码来源:SimpleFacets.java


示例12: writeDate

import org.apache.solr.schema.DateField; //导入依赖的package包/类
public void writeDate(String name, Date val) throws IOException {
  writeDate(name, DateField.formatExternal(val));
}
 
开发者ID:europeana,项目名称:search,代码行数:4,代码来源:TextResponseWriter.java


示例13: run

import org.apache.solr.schema.DateField; //导入依赖的package包/类
public void run() {
  // setup the request context early so the logging (including any from 
  // shouldWeDoPeriodicDelete() ) includes the core context info
  final SolrQueryRequest req = new LocalSolrQueryRequest
    (factory.core, Collections.<String,String[]>emptyMap());
  try {
    final SolrQueryResponse rsp = new SolrQueryResponse();
    SolrRequestInfo.setRequestInfo(new SolrRequestInfo(req, rsp));
    try {
      
      if (! factory.iAmInChargeOfPeriodicDeletes() ) {
        // No-Op
        return;
      }
      log.info("Begining periodic deletion of expired docs");

      UpdateRequestProcessorChain chain = core.getUpdateProcessingChain(deleteChainName);
      UpdateRequestProcessor proc = chain.createProcessor(req, rsp);
      if (null == proc) {
        log.warn("No active processors, skipping automatic deletion " + 
                 "of expired docs using chain: {}", deleteChainName);
        return;
      }
      try {
        DeleteUpdateCommand del = new DeleteUpdateCommand(req);
        del.setQuery("{!cache=false}" + expireField + ":[* TO " +
                     DateField.formatExternal(SolrRequestInfo.getRequestInfo().getNOW())
                     + "]");
        proc.processDelete(del);
        
        // TODO: should this be more configurable? 
        // TODO: in particular: should hard commit be optional?
        CommitUpdateCommand commit = new CommitUpdateCommand(req, false);
        commit.softCommit = true;
        commit.openSearcher = true;
        proc.processCommit(commit);
        
      } finally {
        proc.finish();
      }

      log.info("Finished periodic deletion of expired docs");
    } catch (IOException ioe) {
      log.error("IOException in periodic deletion of expired docs: " +
                ioe.getMessage(), ioe);
      // DO NOT RETHROW: ScheduledExecutor will supress subsequent executions
    } catch (RuntimeException re) {
      log.error("Runtime error in periodic deletion of expired docs: " + 
                re.getMessage(), re);
      // DO NOT RETHROW: ScheduledExecutor will supress subsequent executions
    } finally {
      SolrRequestInfo.clearRequestInfo();
    }
  } finally {
    req.close();
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:58,代码来源:DocExpirationUpdateProcessorFactory.java


示例14: updateCommits

import org.apache.solr.schema.DateField; //导入依赖的package包/类
private void updateCommits(List<? extends IndexCommit> commits) {
  // to be safe, we should only call delete on a commit point passed to us
  // in this specific call (may be across diff IndexWriter instances).
  // this will happen rarely, so just synchronize everything
  // for safety and to avoid race conditions

  synchronized (this) {
    long maxCommitAgeTimeStamp = -1L;
    IndexCommit newest = commits.get(commits.size() - 1);
    // SOLR-4547: Removed the filenames from this log entry because this
    // method is only called from methods that have just logged them
    // at DEBUG.
    log.info("newest commit generation = " + newest.getGeneration());
    int singleSegKept = (newest.getSegmentCount() == 1) ? 1 : 0;
    int totalKept = 1;

    // work our way from newest to oldest, skipping the first since we always want to keep it.
    for (int i=commits.size()-2; i>=0; i--) {
      IndexCommit commit = commits.get(i);

      // delete anything too old, regardless of other policies
      try {
        if (maxCommitAge != null) {
          if (maxCommitAgeTimeStamp==-1) {
            DateMathParser dmp = new DateMathParser(DateField.UTC, Locale.ROOT);
            maxCommitAgeTimeStamp = dmp.parseMath(maxCommitAge).getTime();
          }
          if (IndexDeletionPolicyWrapper.getCommitTimestamp(commit) < maxCommitAgeTimeStamp) {
            commit.delete();
            continue;
          }
        }
      } catch (Exception e) {
        log.warn("Exception while checking commit point's age for deletion", e);
      }

      if (singleSegKept < maxOptimizedCommitsToKeep && commit.getSegmentCount() == 1) {
        totalKept++;
        singleSegKept++;
        continue;
      }

      if (totalKept < maxCommitsToKeep) {
        totalKept++;
        continue;
      }
                                                
      commit.delete();
    }

  } // end synchronized
}
 
开发者ID:europeana,项目名称:search,代码行数:53,代码来源:SolrDeletionPolicy.java


示例15: testTrieDateRangeSearch

import org.apache.solr.schema.DateField; //导入依赖的package包/类
@Test
public void testTrieDateRangeSearch() throws Exception {
  for (int i = 0; i < 10; i++) {
    assertU(adoc("id", String.valueOf(i), "tdate", "1995-12-31T23:" + (i < 10 ? "0" + i : i) + ":59.999Z"));
  }
  assertU(commit());
  SolrQueryRequest req = req("q", "*:*", "fq", "tdate:[1995-12-31T23:00:59.999Z TO 1995-12-31T23:04:59.999Z]");
  assertQ("Range filter must match only 5 documents", req, "//*[@numFound='5']");

  // Test open ended range searches
  assertQ("Range filter tint:[1995-12-31T23:00:59.999Z to *] must match 10 documents", req("q", "*:*", "fq", "tdate:[1995-12-31T23:00:59.999Z TO *]"), "//*[@numFound='10']");
  assertQ("Range filter tint:[* to 1995-12-31T23:09:59.999Z] must match 10 documents", req("q", "*:*", "fq", "tdate:[* TO 1995-12-31T23:09:59.999Z]"), "//*[@numFound='10']");
  assertQ("Range filter tint:[* to *] must match 10 documents", req("q", "*:*", "fq", "tdate:[* TO *]"), "//*[@numFound='10']");

  // Test date math syntax
  SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.ROOT);
  format.setTimeZone(TimeZone.getTimeZone("UTC"));

  assertU(delQ("*:*"));
  DateMathParser dmp = new DateMathParser(DateField.UTC, Locale.ROOT);
  String largestDate = "";
  for (int i = 0; i < 10; i++) {
    // index 10 days starting with today
    String d = format.format(i == 0 ? dmp.parseMath("/DAY") : dmp.parseMath("/DAY+" + i + "DAYS"));
    assertU(adoc("id", String.valueOf(i), "tdate", d));
    if (i == 9) largestDate = d;
  }
  assertU(commit());
  assertQ("Range filter must match only 10 documents", req("q", "*:*", "fq", "tdate:[* TO *]"), "//*[@numFound='10']");
  req = req("q", "*:*", "fq", "tdate:[NOW/DAY TO NOW/DAY+5DAYS]");
  assertQ("Range filter must match only 6 documents", req, "//*[@numFound='6']");

  // Test Term Queries
  assertU(adoc("id", "11", "tdate", "1995-12-31T23:59:59.999Z"));
  assertU(commit());
  assertQ("Term query must match only 1 document", req("q", "tdate:1995-12-31T23\\:59\\:59.999Z"), "//*[@numFound='1']");
  assertQ("Term query must match only 1 document", req("q", "*:*", "fq", "tdate:1995-12-31T23\\:59\\:59.999Z"), "//*[@numFound='1']");

  // Sorting
  assertQ("Sort descending does not work correctly on tdate fields", req("q", "*:*", "sort", "tdate desc"), "//*[@numFound='11']", "//date[@name='tdate'][.='" + largestDate + "']");
  assertQ("Sort ascending does not work correctly on tdate fields", req("q", "*:*", "sort", "tdate asc"), "//*[@numFound='11']", "//date[@name='tdate'][.='1995-12-31T23:59:59.999Z']");

  // Function queries
  assertQ("Function queries does not work correctly on tdate fields", req("q", "_val_:\"sum(tdate,1.0)\""), "//*[@numFound='11']", "//date[@name='tdate'][.='" + largestDate + "']");
}
 
开发者ID:europeana,项目名称:search,代码行数:46,代码来源:TestTrie.java


示例16: updateCommits

import org.apache.solr.schema.DateField; //导入依赖的package包/类
private void updateCommits(List<IndexCommit> commits) {
  // to be safe, we should only call delete on a commit point passed to us
  // in this specific call (may be across diff IndexWriter instances).
  // this will happen rarely, so just synchronize everything
  // for safety and to avoid race conditions

  synchronized (this) {
    long maxCommitAgeTimeStamp = -1L;
    IndexCommit newest = commits.get(commits.size() - 1);
    try {
      log.info("newest commit = " + newest.getGeneration() + newest.getFileNames().toString());
    } catch (IOException e1) {
      throw new RuntimeException();
    }

    int singleSegKept = (newest.getSegmentCount() == 1) ? 1 : 0;
    int totalKept = 1;

    // work our way from newest to oldest, skipping the first since we always want to keep it.
    for (int i=commits.size()-2; i>=0; i--) {
      IndexCommit commit = commits.get(i);

      // delete anything too old, regardless of other policies
      try {
        if (maxCommitAge != null) {
          if (maxCommitAgeTimeStamp==-1) {
            DateMathParser dmp = new DateMathParser(DateField.UTC, Locale.ROOT);
            maxCommitAgeTimeStamp = dmp.parseMath(maxCommitAge).getTime();
          }
          if (IndexDeletionPolicyWrapper.getCommitTimestamp(commit) < maxCommitAgeTimeStamp) {
            commit.delete();
            continue;
          }
        }
      } catch (Exception e) {
        log.warn("Exception while checking commit point's age for deletion", e);
      }

      if (singleSegKept < maxOptimizedCommitsToKeep && commit.getSegmentCount() == 1) {
        totalKept++;
        singleSegKept++;
        continue;
      }

      if (totalKept < maxCommitsToKeep) {
        totalKept++;
        continue;
      }
                                                
      commit.delete();
    }

  } // end synchronized
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:55,代码来源:SolrDeletionPolicy.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Java SnappyDirectDecompressor类代码示例发布时间:2022-05-23
下一篇:
Java DefaultJDOMFactory类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap