本文整理汇总了Java中org.apache.lucene.document.DateTools.Resolution类的典型用法代码示例。如果您正苦于以下问题:Java Resolution类的具体用法?Java Resolution怎么用?Java Resolution使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Resolution类属于org.apache.lucene.document.DateTools包,在下文中一共展示了Resolution类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: StandardQueryConfigHandler
import org.apache.lucene.document.DateTools.Resolution; //导入依赖的package包/类
public StandardQueryConfigHandler() {
// Add listener that will build the FieldConfig.
addFieldConfigListener(new FieldBoostMapFCListener(this));
addFieldConfigListener(new FieldDateResolutionFCListener(this));
addFieldConfigListener(new NumericFieldConfigListener(this));
// Default Values
set(ConfigurationKeys.ALLOW_LEADING_WILDCARD, false); // default in 2.9
set(ConfigurationKeys.ANALYZER, null); //default value 2.4
set(ConfigurationKeys.DEFAULT_OPERATOR, Operator.OR);
set(ConfigurationKeys.PHRASE_SLOP, 0); //default value 2.4
set(ConfigurationKeys.LOWERCASE_EXPANDED_TERMS, true); //default value 2.4
set(ConfigurationKeys.ENABLE_POSITION_INCREMENTS, false); //default value 2.4
set(ConfigurationKeys.FIELD_BOOST_MAP, new LinkedHashMap<String, Float>());
set(ConfigurationKeys.FUZZY_CONFIG, new FuzzyConfig());
set(ConfigurationKeys.LOCALE, Locale.getDefault());
set(ConfigurationKeys.MULTI_TERM_REWRITE_METHOD, MultiTermQuery.CONSTANT_SCORE_AUTO_REWRITE_DEFAULT);
set(ConfigurationKeys.FIELD_DATE_RESOLUTION_MAP, new HashMap<CharSequence, DateTools.Resolution>());
}
示例2: buildFieldConfig
import org.apache.lucene.document.DateTools.Resolution; //导入依赖的package包/类
@Override
public void buildFieldConfig(FieldConfig fieldConfig) {
DateTools.Resolution dateRes = null;
Map<CharSequence, DateTools.Resolution> dateResMap = this.config.get(ConfigurationKeys.FIELD_DATE_RESOLUTION_MAP);
if (dateResMap != null) {
dateRes = dateResMap.get(
fieldConfig.getField());
}
if (dateRes == null) {
dateRes = this.config.get(ConfigurationKeys.DATE_RESOLUTION);
}
if (dateRes != null) {
fieldConfig.set(ConfigurationKeys.DATE_RESOLUTION, dateRes);
}
}
示例3: query
import org.apache.lucene.document.DateTools.Resolution; //导入依赖的package包/类
/**
* Returns the Lucene {@link Query} represented by the specified
* {@link Search} and key filter.
*
* @param expression
* the expression
* @param command
* the command
* @return a Lucene {@link Query}
*/
private Query query(String expression, ReadCommand command) {
try {
QueryParser queryParser = new QueryParser("query", this.indexOptions.search.defaultAnalyzer);
queryParser.setDateResolution(Resolution.SECOND);
Query searchQuery = queryParser.parse(expression);
return searchQuery;
} catch (ParseException e) {
// TODO Auto-generated catch block
throw new FhirIndexException(e);
}
// TODO: mejorar las busquedas por tipo
// Optional<Query> maybeKeyRangeQuery = query(command);
// if (maybeKeyRangeQuery.isPresent()) {
// BooleanQuery.Builder builder = new BooleanQuery.Builder();
// builder.add(maybeKeyRangeQuery.get(), FILTER);
// builder.add(searchQuery, MUST);
// return builder.build();
// } else {
// }
}
示例4: transformDateFields
import org.apache.lucene.document.DateTools.Resolution; //导入依赖的package包/类
/**
* Transforms the user entered date string to lucene date string format
* by trying to reconstruct the Date object either by local or by ISO (yyy-MM-dd)
* DateTools calculates in GMT (comparing to the server TimeZone), so it should be adjusted
* @param originalFieldValue
* @param locale
* @return
*/
private static String transformDateFields(String originalFieldValue, Locale locale) {
String dateString = originalFieldValue;
Date date;
//DateTimeUtils dtu = new DateTimeUtils(locale);
date = DateTimeUtils.getInstance().parseGUIDate(originalFieldValue, locale);
if (date==null) {
date = DateTimeUtils.getInstance().parseShortDate(originalFieldValue, locale);
}
//set the date according to offset from the GMT
//see http://www.gossamer-threads.com/lists/lucene/java-user/39303?search_string=DateTools;#39303
Calendar cal = new GregorianCalendar();
int minutesOffset = (cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET)) / (60 * 1000);
if (date!=null) {
cal.setTime(date);
cal.add(Calendar.MINUTE, minutesOffset);
return DateTools.dateToString(cal.getTime(), Resolution.DAY);
}
date = DateTimeUtils.getInstance().parseISODate(originalFieldValue);
if (date!=null) {
cal.setTime(date);
cal.add(Calendar.MINUTE, minutesOffset);
return DateTools.dateToString(cal.getTime(), Resolution.DAY);
}
return dateString;
}
示例5: indexProtocolSearchableFieldsBean
import org.apache.lucene.document.DateTools.Resolution; //导入依赖的package包/类
public void indexProtocolSearchableFieldsBean(ProtocolSearchableFieldsBean protocolFieldsBean) throws IOException {
IndexWriter writer = getIndexWriter(false);
Document doc = new Document();
doc.add(new StringField("protocolId", protocolFieldsBean.getProtocolId(), Field.Store.YES));
if(protocolFieldsBean.getProtocolFileDesc()!=null)
doc.add(new StringField("protocolFileDesc", protocolFieldsBean.getProtocolFileDesc(), Field.Store.YES));
if(protocolFieldsBean.getProtocolFileId()!=null)
doc.add(new StringField("protocolFileId", protocolFieldsBean.getProtocolFileId(), Field.Store.YES));
doc.add(new StringField("protocolName", protocolFieldsBean.getProtocolName(), Field.Store.YES));
if(protocolFieldsBean.getProtocolFileName()!=null)
doc.add(new StringField("protocolFileName", protocolFieldsBean.getProtocolFileName(), Field.Store.YES));
if(protocolFieldsBean.getCreatedDate()!=null){
try{
doc.add(new Field("createdDate", DateTools.stringToDate(DateTools.dateToString(protocolFieldsBean.getCreatedDate(),Resolution.SECOND)).toString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
}catch(ParseException e){
e.printStackTrace();
}
}
String fullSearchableText = protocolFieldsBean.getProtocolName() + " " + protocolFieldsBean.getProtocolFileName();
doc.add(new TextField("content", fullSearchableText, Field.Store.NO));
writer.addDocument(doc);
}
示例6: createDocument
import org.apache.lucene.document.DateTools.Resolution; //导入依赖的package包/类
/**
* Creates a Lucene document from an issue.
*
* @param issue
* @return a Lucene document
*/
private Document createDocument(IssueModel issue) {
Document doc = new Document();
doc.add(new Field(FIELD_OBJECT_TYPE, SearchObjectType.issue.name(), Store.YES,
Field.Index.NOT_ANALYZED));
doc.add(new Field(FIELD_ISSUE, issue.id, Store.YES, Index.ANALYZED));
doc.add(new Field(FIELD_BRANCH, IssueUtils.GB_ISSUES, Store.YES, Index.ANALYZED));
doc.add(new Field(FIELD_DATE, DateTools.dateToString(issue.created, Resolution.MINUTE),
Store.YES, Field.Index.NO));
doc.add(new Field(FIELD_AUTHOR, issue.reporter, Store.YES, Index.ANALYZED));
List<String> attachments = new ArrayList<String>();
for (Attachment attachment : issue.getAttachments()) {
attachments.add(attachment.name.toLowerCase());
}
doc.add(new Field(FIELD_ATTACHMENT, StringUtils.flattenStrings(attachments), Store.YES,
Index.ANALYZED));
doc.add(new Field(FIELD_SUMMARY, issue.summary, Store.YES, Index.ANALYZED));
doc.add(new Field(FIELD_CONTENT, issue.toString(), Store.YES, Index.ANALYZED));
doc.add(new Field(FIELD_LABEL, StringUtils.flattenStrings(issue.getLabels()), Store.YES,
Index.ANALYZED));
return doc;
}
示例7: createDocument
import org.apache.lucene.document.DateTools.Resolution; //导入依赖的package包/类
/**
* 获得Lucene格式的Document
*
* @param c
* 文章对象
* @return
*/
public static Document createDocument(Content c) {
Document doc = new Document();
doc.add(new Field(ID, c.getId().toString(), Field.Store.YES,
Field.Index.NOT_ANALYZED));
doc.add(new Field(SITE_ID, c.getSite().getId().toString(),
Field.Store.NO, Field.Index.NOT_ANALYZED));
doc.add(new Field(RELEASE_DATE, DateTools.dateToString(c
.getReleaseDate(), Resolution.DAY), Field.Store.NO,
Field.Index.NOT_ANALYZED));
Channel channel = c.getChannel();
while (channel != null) {
doc.add(new Field(CHANNEL_ID_ARRAY, channel.getId().toString(),
Field.Store.NO, Field.Index.NOT_ANALYZED));
channel = channel.getParent();
}
doc.add(new Field(TITLE, c.getTitle(), Field.Store.NO,
Field.Index.ANALYZED));
if (!StringUtils.isBlank(c.getTxt())) {
doc.add(new Field(CONTENT, c.getTxt(), Field.Store.NO,
Field.Index.ANALYZED));
}
if(c.getAttr()!=null&&StringUtils.isNotBlank(c.getAttr().get("workplace"))){
doc.add(new Field(WORKPLACE, c.getAttr().get("workplace"), Field.Store.NO,
Field.Index.ANALYZED));
}
if(c.getAttr()!=null&&StringUtils.isNotBlank(c.getAttr().get("category"))){
doc.add(new Field(CATEGORY, c.getAttr().get("category"), Field.Store.NO,
Field.Index.ANALYZED));
}
return doc;
}
示例8: setDateResolution
import org.apache.lucene.document.DateTools.Resolution; //导入依赖的package包/类
@Override
public void setDateResolution(CommonQueryParserConfiguration cqpC,
CharSequence field, Resolution value) {
assert (cqpC instanceof StandardQueryParser);
StandardQueryParser qp = (StandardQueryParser) cqpC;
qp.getDateResolutionMap().put(field, value);
}
示例9: setDateResolution
import org.apache.lucene.document.DateTools.Resolution; //导入依赖的package包/类
@Override
public void setDateResolution(CommonQueryParserConfiguration cqpC,
CharSequence field, Resolution value) {
assert (cqpC instanceof QueryParser);
QueryParser qp = (QueryParser) cqpC;
qp.setDateResolution(field.toString(), value);
}
示例10: createDocument
import org.apache.lucene.document.DateTools.Resolution; //导入依赖的package包/类
/**
* Creates a Lucene document for a commit
*
* @param commit
* @param tags
* @return a Lucene document
*/
private Document createDocument(RevCommit commit, List<String> tags) {
Document doc = new Document();
doc.add(new Field(FIELD_OBJECT_TYPE, SearchObjectType.commit.name(), StringField.TYPE_STORED));
doc.add(new Field(FIELD_COMMIT, commit.getName(), TextField.TYPE_STORED));
doc.add(new Field(FIELD_DATE, DateTools.timeToString(commit.getCommitTime() * 1000L, Resolution.MINUTE), StringField.TYPE_STORED));
doc.add(new Field(FIELD_AUTHOR, getAuthor(commit), TextField.TYPE_STORED));
doc.add(new Field(FIELD_COMMITTER, getCommitter(commit), TextField.TYPE_STORED));
doc.add(new Field(FIELD_SUMMARY, commit.getShortMessage(), TextField.TYPE_STORED));
doc.add(new Field(FIELD_CONTENT, commit.getFullMessage(), TextField.TYPE_STORED));
if (!ArrayUtils.isEmpty(tags)) {
doc.add(new Field(FIELD_TAG, StringUtils.flattenStrings(tags), TextField.TYPE_STORED));
}
return doc;
}
示例11: setDateResolution
import org.apache.lucene.document.DateTools.Resolution; //导入依赖的package包/类
@Override
public void setDateResolution(CommonQueryParserConfiguration cqpC,
CharSequence field, Resolution value) {
assert (cqpC instanceof QueryParser);
QueryParser qp = (QueryParser) cqpC;
qp.setDateResolution(field.toString(), value);
}
示例12: indexSampleSearchableFieldsBean
import org.apache.lucene.document.DateTools.Resolution; //导入依赖的package包/类
public void indexSampleSearchableFieldsBean(SampleSearchableFieldsBean sampleFieldsBean) throws IOException {
IndexWriter writer = getIndexWriter(false);
Document doc = new Document();
doc.add(new StringField("sampleId", sampleFieldsBean.getSampleId(), Field.Store.YES));
doc.add(new StringField("sampleName", sampleFieldsBean.getSampleName(), Field.Store.YES));
if(sampleFieldsBean.getSamplePocName()!=null)
doc.add(new StringField("samplePocName", sampleFieldsBean.getSamplePocName(), Field.Store.YES));
if(sampleFieldsBean.getNanoEntityName()!=null)
doc.add(new StringField("nanoEntityName", sampleFieldsBean.getNanoEntityName(), Field.Store.YES));
if(sampleFieldsBean.getNanoEntityDesc()!=null)
doc.add(new StringField("nanoEntityDesc", sampleFieldsBean.getNanoEntityDesc(), Field.Store.YES));
if(sampleFieldsBean.getFuncEntityName()!=null)
doc.add(new StringField("funcEntityName", sampleFieldsBean.getFuncEntityName(), Field.Store.YES));
if(sampleFieldsBean.getFunction()!=null)
doc.add(new StringField("function", sampleFieldsBean.getFunction(), Field.Store.YES));
if(sampleFieldsBean.getCharacterization()!=null)
doc.add(new StringField("characterization", sampleFieldsBean.getCharacterization(), Field.Store.YES));
if(sampleFieldsBean.getCreatedDate()!=null)
try{
doc.add(new Field("createdDate", DateTools.stringToDate(DateTools.dateToString(sampleFieldsBean.getCreatedDate(),Resolution.SECOND)).toString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
}catch(ParseException e){
e.printStackTrace();
}
if(sampleFieldsBean.getSampleKeywords().size()>0)
for(int i = 0; i < sampleFieldsBean.getSampleKeywords().size();i++){
doc.add(new StringField("sampleKeywords", sampleFieldsBean.getSampleKeywords().get(i), Field.Store.YES));
}
String fullSearchableText = sampleFieldsBean.getSampleName() + " " + sampleFieldsBean.getSamplePocName() + " " + sampleFieldsBean.getNanoEntityName() + " " + sampleFieldsBean.getNanoEntityDesc() + " " + sampleFieldsBean.getFuncEntityName() + " " + sampleFieldsBean.getFunction() + " " + sampleFieldsBean.getCharacterization();
String keywords = "";
for( int i = 0; i < sampleFieldsBean.getSampleKeywords().size(); i++){
String keyword = sampleFieldsBean.getSampleKeywords().get(i);
keywords = keywords + " " + keyword;
}
fullSearchableText = fullSearchableText + " " + keywords;
doc.add(new TextField("content", fullSearchableText, Field.Store.NO));
writer.addDocument(doc);
}
示例13: Search
import org.apache.lucene.document.DateTools.Resolution; //导入依赖的package包/类
/**
* Initializes a new instance of Search with a query,
* a set of facets (in {@link String} form with integer counts), an
* analyzer and a custom sort.
* @param qquery The query to be executed during the search.
* @param ffacets The facets for which to search.
* @param aanalyzer The analyzer with which to parse the
* query.
* @param ssort The custom sort order.
* @throws ParseException A fatal exception occurred while
* parsing the String query.
*/
public Search(
final String qquery,
final Map<String, Integer> ffacets,
final Analyzer aanalyzer,
final Sort ssort)
throws ParseException {
QueryParser parser =
new SearchQueryParser(
Lucene.LUCENE_VERSION,
Lucene.DEFAULT_QUERY_FIELD,
aanalyzer
);
parser.setDateResolution(Resolution.HOUR);
query = parser.parse(qquery);
if (ffacets == null) {
facets = null;
} else {
facets = new ArrayList<FacetRequest>(ffacets.size());
for (Entry<String, Integer> facet : ffacets.entrySet()) {
final CategoryPath facetPath =
new CategoryPath(facet.getKey(), '/');
final CountFacetRequest facetRequest =
new CountFacetRequest(facetPath, facet.getValue());
facets.add(facetRequest);
}
}
sort = ssort;
}
示例14: adjustIfDate
import org.apache.lucene.document.DateTools.Resolution; //导入依赖的package包/类
public static String adjustIfDate(String texteLibre) {
String result;
try {
Date date = new SimpleDateFormat("yyyy-MM-dd").parse(texteLibre.trim());
result = DateTools.dateToString(date, Resolution.DAY);
} catch (Exception e) {
result = texteLibre;
}
return result;
}
示例15: addRecipe
import org.apache.lucene.document.DateTools.Resolution; //导入依赖的package包/类
public void addRecipe(String recipeName)
throws SQLException, DBRecipe.RecipeNotFoundException, IOException {
recipeName = recipeName.toLowerCase(Locale.GERMAN);
if (checkIfRecipeExists(recipeName)) {
removeRecipe(recipeName);
}
try (DBGetRecipe dbGetRecipe = new DBGetRecipe()) {
Recipe recipe = dbGetRecipe.get(recipeName);
int id = dbGetRecipe.getActiveIdfromRecipe(recipeName);
String date = DateTools.dateToString(new Date(), Resolution.DAY);
List<Step> steps = Steps.loadRecipeSteps(recipeName);
StringBuilder stepText = new StringBuilder();
for (Step step : steps) {
stepText.append(" ").append(step.getText());
}
try (IndexWriter writer = new IndexWriter(index, createIndexWriterConfig())) {
Document doc = new Document();
doc.add(new TextField("title", recipe.getName(), Field.Store.YES));
doc.add(new TextField("description", recipe.getDescription() == null ? "" : recipe
.getDescription(),
Field.Store.YES));
doc.add(new TextField("steps", stepText.toString(), Field.Store.YES));
doc.add(new IntField("version_id", id, Field.Store.YES));
doc.add(new TextField("date", date, Field.Store.YES));
writer.addDocument(doc);
writer.commit();
logger.info("added " + recipeName + " to index");
} catch (CorruptIndexException | LockObtainFailedException e) {
throw new IOException(e);
}
}
}