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


Java SolrDocument类代码示例

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


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

示例1: getLatestValidDateUpdated

import org.apache.solr.common.SolrDocument; //导入依赖的package包/类
/**
 * Returns the latest DATEUPDATED value on the given <code>SolrDocument</code> that is no larger than <code>untilTimestamp</code>. Returns 0 if no
 * such value is found.
 * 
 * @param doc
 * @param untilTimestamp
 * @return Latest DATEUPDATED value is less than or equals untilTimestamp on doc; 0 if none found.
 * @should return correct value
 * @should return 0 if no valid value is found
 */
public static Long getLatestValidDateUpdated(SolrDocument doc, long untilTimestamp) {
    long ret = 0;
    Collection<Object> dateUpdatedValues = doc.getFieldValues(SolrConstants.DATEUPDATED);
    if (dateUpdatedValues != null && !dateUpdatedValues.isEmpty()) {
        // Get latest DATEUPDATED values
        for (Object o : dateUpdatedValues) {
            long dateUpdated = (Long) o;
            if (dateUpdated > ret && dateUpdated <= untilTimestamp) {
                ret = dateUpdated;
            }
        }
    }

    return ret;
}
 
开发者ID:intranda,项目名称:goobi-viewer-connector,代码行数:26,代码来源:SolrSearchIndex.java

示例2: fetchExistingOrCreateNewSolrDoc

import org.apache.solr.common.SolrDocument; //导入依赖的package包/类
private SolrInputDocument fetchExistingOrCreateNewSolrDoc(String id) throws SolrServerException, IOException {
  Map<String, String> p = new HashMap<String, String>();
  p.put("q", PHRASE + ":\"" + ClientUtils.escapeQueryChars(id) + "\"");
  
  SolrParams params = new MapSolrParams(p);
  
  QueryResponse res = solrAC.query(params);
  
  if (res.getResults().size() == 0) {
    return new SolrInputDocument();
  } else if (res.getResults().size() == 1) {
    SolrDocument doc = res.getResults().get(0);
    SolrInputDocument tmp = new SolrInputDocument();
    
    for (String fieldName : doc.getFieldNames()) {
      tmp.addField(fieldName, doc.getFieldValue(fieldName));
    }
    return tmp;
  } else {
    throw new IllegalStateException("Query with params : " + p + " returned more than 1 hit!");
  }
}
 
开发者ID:sematext,项目名称:solr-autocomplete,代码行数:23,代码来源:AutocompleteUpdateRequestProcessor.java

示例3: getUrlString

import org.apache.solr.common.SolrDocument; //导入依赖的package包/类
@Override
public String getUrlString(Class<? extends Page> pageClass, QueryFacetsSelection selection, SolrDocument document) {
    final PageParameters params = new PageParameters();
    if (selection != null) {
        params.mergeWith(paramsConverter.toParameters(selection));
    }

    if (document != null) {
        params.add(VloWebAppParameters.DOCUMENT_ID, document.getFirstValue(FacetConstants.FIELD_ID));
    }

    final String style = Session.get().getStyle();
    if (style != null) {
        params.add(VloWebAppParameters.THEME, style);
    }

    final CharSequence url = RequestCycle.get().urlFor(pageClass, params);
    final String absoluteUrl = RequestCycle.get().getUrlRenderer().renderFullUrl(Url.parse(url));
    return absoluteUrl;
}
 
开发者ID:acdh-oeaw,项目名称:vlo-curation,代码行数:21,代码来源:PermalinkServiceImpl.java

示例4: getLatestVolumeTimestamp

import org.apache.solr.common.SolrDocument; //导入依赖的package包/类
/**
 * If the given SolrDocument is an anchor, retrieve the latest DATEUPDATED timestamp value from its volumes.
 * 
 * @param anchorDoc
 * @param untilTimestamp
 * @return
 * @throws SolrServerException
 */
public long getLatestVolumeTimestamp(SolrDocument anchorDoc, long untilTimestamp) throws SolrServerException {
    if (anchorDoc.getFieldValue(SolrConstants.ISANCHOR) != null && (Boolean) anchorDoc.getFieldValue(SolrConstants.ISANCHOR)) {
        SolrDocumentList volumes = search(SolrConstants.ISWORK + ":true AND " + SolrConstants.IDDOC_PARENT + ":" + (String) anchorDoc
                .getFieldValue(SolrConstants.IDDOC));
        if (volumes != null) {
            long latest = 0;
            for (SolrDocument volume : volumes) {
                long volumeTimestamp = getLatestValidDateUpdated(volume, untilTimestamp);
                if (latest < volumeTimestamp) {
                    latest = volumeTimestamp;
                }
            }

            if (latest > 0) {
                return latest;
            }
        }
    }

    return -1;
}
 
开发者ID:intranda,项目名称:goobi-viewer-connector,代码行数:30,代码来源:SolrSearchIndex.java

示例5: createListIdentifiers

import org.apache.solr.common.SolrDocument; //导入依赖的package包/类
/**
 * for the server request ?verb=ListIdentifiers this method build the xml section
 * 
 * @param handler
 * @param firstRow
 * @param numRows
 * @return
 * @throws SolrServerException
 */
public Element createListIdentifiers(RequestHandler handler, int firstRow, int numRows) throws SolrServerException {
    Map<String, String> datestamp = filterDatestampFromRequest(handler);
    SolrDocumentList listIdentifiers = solr.getListIdentifiers(datestamp, firstRow, numRows, false);
    if (listIdentifiers == null || listIdentifiers.isEmpty()) {
        return new ErrorCode().getNoRecordsMatch();
    }

    Namespace xmlns = DataManager.getInstance().getConfiguration().getStandardNameSpace();
    Element xmlListIdentifiers = new Element("ListIdentifiers", xmlns);
    long totalHits = listIdentifiers.getNumFound();
    for (int i = 0; i < listIdentifiers.size(); i++) {
        SolrDocument doc = listIdentifiers.get(i);
        Element header = getHeader(doc, null, handler);
        xmlListIdentifiers.addContent(header);
    }

    // Create resumption token
    if (totalHits > firstRow + numRows) {
        Element resumption = createResumptionTokenAndElement(totalHits, firstRow + numRows, xmlns, handler);
        xmlListIdentifiers.addContent(resumption);
    }

    return xmlListIdentifiers;
}
 
开发者ID:intranda,项目名称:goobi-viewer-connector,代码行数:34,代码来源:XMLGeneration.java

示例6: readNextPage

import org.apache.solr.common.SolrDocument; //导入依赖的package包/类
private boolean readNextPage() {
	if (totalCountOfRows < 0 || startOfCurrentPage < totalCountOfRows) {
		mySolrQuery.set("start", startOfCurrentPage);
		mySolrQuery.set("rows", pageSize);
		startOfCurrentPage += pageSize;
		QueryResponse rsp = null;
		List<Object[]> rows = new ArrayList<>();
		try {
			rsp = solrClientFactory.getClient().query(mySolrQuery);
			SolrDocumentList docs = rsp.getResults();
			totalCountOfRows = docs.getNumFound();
			for (SolrDocument doc : docs) {
				rows.add(doc2Row(doc));
			}
		} catch (Exception e) {
			logger.error(e);
		}
		rowIteratorWithinCurrentPage = rows.iterator();
		return true;
	}
	return false;
}
 
开发者ID:jenkin2016,项目名称:solr-sql,代码行数:23,代码来源:SolrTable.java

示例7: buildRealTimeGetResult

import org.apache.solr.common.SolrDocument; //导入依赖的package包/类
public static GetResult buildRealTimeGetResult(QueryResponse response, RealTimeGet query, DocumentFactory factory) {
    final String DOC = "doc";

    long nResults = 0;
    List<Document> docResults = new ArrayList<>();

    final SolrDocumentList results = response.getResults();
    if(results != null && results.size() >0){
        docResults = buildResultList(results, null, factory, null);
        nResults = docResults.size();
    } else {
        final SolrDocument solrDoc = (SolrDocument)response.getResponse().get(DOC);
        if(solrDoc != null) {
            final SolrDocumentList solrDocuments = new SolrDocumentList();
            solrDocuments.add(solrDoc);
            docResults = buildResultList(solrDocuments, null, factory, null);
            nResults = 1;
        }
    }

    return new GetResult(nResults,docResults,query,factory);
}
 
开发者ID:RBMHTechnology,项目名称:vind,代码行数:23,代码来源:SolrUtils.java

示例8: newMapper

import org.apache.solr.common.SolrDocument; //导入依赖的package包/类
private Function<Object, Object> newMapper(String mapper) {
	if (mapper.equals(MAPPER_NEW_URI)) {
		return object -> {
			try {
				return Dependent.newUri((Artifact) object);
			} catch (URISyntaxException exception) {
				throw new RuntimeException(exception);
			}
		};
	}
	if (mapper.equals(MAPPER_NEW_ARTIFACT_WITH_VERSION)) {
		return object -> Match.newArtifactWithVersion((SolrDocument) object);
	}
	if (mapper.equals(MAPPER_NEW_ARTIFACT_WITH_LATEST_VERSION)) {
		return object -> Match.newArtifactWithLatestVersion((SolrDocument) object);
	}
	if (mapper.equals(MAPPER_NEW_SOLR_QUERY_FOR_ALL_VERSIONS)) {
		return object -> Match.newSolrQueryForAllVersions((Artifact) object);
	}
	if (mapper.equals(MAPPER_NEW_SOLR_QUERY_FOR_LATEST_VERSION)) {
		return object -> Match.newSolrQueryForLatestVersion((Artifact) object);
	}
	throw new IllegalArgumentException(
			"Mapper must be one of newUri, newArtifactWithVersion, newArtifactWithLatestVersion or newSolrQuery");
}
 
开发者ID:maenu,项目名称:kowalski,代码行数:26,代码来源:WorkerPoolParser.java

示例9: prepareUpdate

import org.apache.solr.common.SolrDocument; //导入依赖的package包/类
/**
 * Prepares the given record for an update. Creation timestamp is preserved. A new update timestamp is added, child docs are removed.
 * 
 * @param indexObj {@link IndexObject}
 * @throws IOException -
 * @throws SolrServerException
 * @throws FatalIndexerException
 */
private void prepareUpdate(IndexObject indexObj) throws IOException, SolrServerException, FatalIndexerException {
    String pi = indexObj.getPi().trim();
    SolrDocumentList hits = hotfolder.getSolrHelper().search(SolrConstants.PI + ":" + pi, null);
    if (hits != null && hits.getNumFound() > 0) {
        logger.debug("This file has already been indexed, initiating an UPDATE instead...");
        indexObj.setUpdate(true);
        SolrDocument doc = hits.get(0);
        // Set creation timestamp, if exists (should never be updated)
        Object dateCreated = doc.getFieldValue(SolrConstants.DATECREATED);
        if (dateCreated != null) {
            // Set creation timestamp, if exists (should never be updated)
            indexObj.setDateCreated((Long) dateCreated);
        }
        // Set update timestamp
        Collection<Object> dateUpdatedValues = doc.getFieldValues(SolrConstants.DATEUPDATED);
        if (dateUpdatedValues != null) {
            for (Object date : dateUpdatedValues) {
                indexObj.getDateUpdated().add((Long) date);
            }
        }
        // Recursively delete all children
        deleteWithPI(pi, false, hotfolder.getSolrHelper());
    }
}
 
开发者ID:intranda,项目名称:goobi-viewer-indexer,代码行数:33,代码来源:LidoIndexer.java

示例10: updateDoc

import org.apache.solr.common.SolrDocument; //导入依赖的package包/类
/**
 * Performs an atomic update of the given solr document. Updates defined in partialUpdates will be applied to the existing document without making
 * any changes to other fields.
 * 
 * @param doc
 * @param partialUpdates Map of update operations (usage: Map<field, Map<operation, value>>)
 * @return
 * @throws FatalIndexerException
 * @should update doc correctly
 * @should add GROUPFIELD if original doc doesn't have it
 */
public boolean updateDoc(SolrDocument doc, Map<String, Map<String, Object>> partialUpdates) throws FatalIndexerException {
    String iddoc = (String) doc.getFieldValue(SolrConstants.IDDOC);
    SolrInputDocument newDoc = new SolrInputDocument();
    newDoc.addField(SolrConstants.IDDOC, iddoc);
    if (!doc.containsKey(SolrConstants.GROUPFIELD)) {
        logger.warn("Document to update {} doesn't contain {} adding now.", iddoc, SolrConstants.GROUPFIELD);
        Map<String, Object> update = new HashMap<>();
        update.put("set", iddoc);
        newDoc.addField(SolrConstants.GROUPFIELD, update);
    }
    for (String field : partialUpdates.keySet()) {
        newDoc.addField(field, partialUpdates.get(field));
    }
    if (writeToIndex(newDoc)) {
        commit(false);
        return true;
    }

    return false;
}
 
开发者ID:intranda,项目名称:goobi-viewer-indexer,代码行数:32,代码来源:SolrHelper.java

示例11: removeGrievingAnchors

import org.apache.solr.common.SolrDocument; //导入依赖的package包/类
public int removeGrievingAnchors() throws FatalIndexerException {
    String[] fields = { SolrConstants.IDDOC, SolrConstants.PI };
    try {
        List<String> toDelete = new ArrayList<>();
        SolrDocumentList anchors = search(SolrConstants.ISANCHOR + ":true", Arrays.asList(fields));
        for (SolrDocument anchor : anchors) {
            String iddoc = (String) anchor.getFirstValue(SolrConstants.IDDOC);
            String pi = (String) anchor.getFirstValue(SolrConstants.PI);
            if (search(SolrConstants.PI_PARENT + ":" + pi, Collections.singletonList(SolrConstants.IDDOC)).getNumFound() == 0) {
                toDelete.add(iddoc);
                logger.info("{} has no volumes and will be deleted.", pi);
            }
        }
        if (!toDelete.isEmpty()) {
            deleteDocuments(toDelete);
            commit(false);
            return toDelete.size();
        }
    } catch (SolrServerException e) {
        logger.error(e.getMessage(), e);
    }

    return 0;
}
 
开发者ID:intranda,项目名称:goobi-viewer-indexer,代码行数:25,代码来源:SolrHelper.java

示例12: toHassoResult

import org.apache.solr.common.SolrDocument; //导入依赖的package包/类
@Override
protected ConversationResult toHassoResult(ComponentConfiguration conf, SolrDocument solrDocument, String type) {
    final ConversationResult hassoResult = new ConversationResult(getCreatorName(conf));

    hassoResult.setScore(Double.parseDouble(String.valueOf(solrDocument.getFieldValue("score"))));

    hassoResult.setContent(String.valueOf(solrDocument.getFirstValue(FIELD_MESSAGE)));
    hassoResult.setReplySuggestion(hassoResult.getContent());

    hassoResult.setConversationId(String.valueOf(solrDocument.getFieldValue(FIELD_CONVERSATION_ID)));
    hassoResult.setMessageId(String.valueOf(solrDocument.getFieldValue(FIELD_MESSAGE_ID)));
    hassoResult.setMessageIdx(Integer.parseInt(String.valueOf(solrDocument.getFieldValue(FIELD_MESSAGE_IDX))));

    hassoResult.setVotes(Integer.parseInt(String.valueOf(solrDocument.getFieldValue(FIELD_VOTE))));

    hassoResult.setTimestamp((Date) solrDocument.getFieldValue(FIELD_TIME));
    hassoResult.setUserName((String) solrDocument.getFieldValue(FIELD_USER_NAME));

    return hassoResult;
}
 
开发者ID:redlink-gmbh,项目名称:smarti,代码行数:21,代码来源:ConversationMltQueryBuilder.java

示例13: indexPDFDocumentToExtractingRequestHandler

import org.apache.solr.common.SolrDocument; //导入依赖的package包/类
@Test
public void indexPDFDocumentToExtractingRequestHandler() throws Exception {
    solrEndpoint.setRequestHandler("/update/extract");

    Exchange exchange = createExchangeWithBody(new File("src/test/resources/data/tutorial.pdf"));
    exchange.getIn().setHeader(SolrConstants.OPERATION, SolrConstants.OPERATION_INSERT);
    exchange.getIn().setHeader("SolrParam.literal.id", "tutorial.pdf");

    template.send("direct:start", exchange);
    solrCommit();

    QueryResponse response = executeSolrQuery("*:*");
    assertEquals(0, response.getStatus());
    assertEquals(1, response.getResults().getNumFound());

    SolrDocument doc = response.getResults().get(0);
    assertEquals("Solr", doc.getFieldValue("subject"));
    assertEquals("tutorial.pdf", doc.getFieldValue("id"));
    assertEquals(Arrays.asList("application/pdf"), doc.getFieldValue("content_type"));
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:21,代码来源:SolrUpdateTest.java

示例14: responseIs

import org.apache.solr.common.SolrDocument; //导入依赖的package包/类
private synchronized boolean responseIs( QueryResponse rsp, String field, String ... queries ) {
  System.out.println( field  + " " + rsp.getResults( ).size( ) );
  HashSet<String> expected = new HashSet<String>( );
  for ( int i = 0; i < queries.length; i++) {
    System.out.println( "adding '" + queries[i] + "'" );
    expected.add( queries[i] );
  }
  for (SolrDocument doc : rsp.getResults() ) {
    String val = String.valueOf( doc.getFirstValue( field ) );
    System.out.println( "   '" + val + "'" );
    if (expected.contains( val )) {
      System.out.println( "removing '" + val + "'" );
      expected.remove( val );
    }
  }
  System.out.println( expected.size( ) + " left " );
  return expected.size() == 0;
}
 
开发者ID:detnavillus,项目名称:multifield_suggester_code,代码行数:19,代码来源:TestSuggestCollectionBuilder.java

示例15: solrQuery

import org.apache.solr.common.SolrDocument; //导入依赖的package包/类
protected MCROAISolrResult solrQuery(Optional<String> cursor) throws SolrServerException, IOException {
    SolrQuery query = getBaseQuery(CommonParams.Q);

    // set support
    if (this.set != null) {
        String setId = this.set.getSetId();
        MCROAISetConfiguration<SolrQuery, SolrDocument, String> setConfig = getSetManager().getConfig(setId);
        setConfig.getHandler().apply(this.set, query);
    }
    // from & until
    if (this.from != null || this.until != null) {
        String fromUntilCondition = buildFromUntilCondition(this.from, this.until);
        query.add(CommonParams.FQ, fromUntilCondition);
    }

    // cursor
    query.set(CursorMarkParams.CURSOR_MARK_PARAM, cursor.orElse(CursorMarkParams.CURSOR_MARK_START));
    query.set(CommonParams.ROWS, String.valueOf(getPartitionSize()));
    query.set(CommonParams.SORT, "id asc");

    // do the query
    SolrClient solrClient = MCRSolrClientFactory.getSolrClient();
    QueryResponse response = solrClient.query(query);
    Collection<MCROAISetResolver<String, SolrDocument>> setResolver = getSetResolver(response.getResults());
    return new MCROAISolrResult(response, d -> toHeader(d, setResolver));
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:27,代码来源:MCROAISolrSearcher.java


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