本文整理汇总了Java中org.apache.solr.common.params.CursorMarkParams.CURSOR_MARK_START属性的典型用法代码示例。如果您正苦于以下问题:Java CursorMarkParams.CURSOR_MARK_START属性的具体用法?Java CursorMarkParams.CURSOR_MARK_START怎么用?Java CursorMarkParams.CURSOR_MARK_START使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.apache.solr.common.params.CursorMarkParams
的用法示例。
在下文中一共展示了CursorMarkParams.CURSOR_MARK_START属性的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processAllDocs
/**
* Loop over all the documents returned by the query. This method queries the DB multiple times. Every time we get
* data back, we pass it onto a processor, and stop processing data if the processor tells us it's had enough.
*
* @param server the solr db
* @param q the query
* @param uniqueKey the solr uniqueKey field to sort on. Required for solr's Cursor functionality.
*@param processor the processor to handle the data. If the function returns true, we stop fetching more data.
* @throws IOException
* @throws SolrServerException
*/
static void processAllDocs(SolrClient server, SolrQuery q,
String uniqueKey, Function<Collection<SolrDocument>, Boolean> processor
) throws IOException, SolrServerException {
boolean done = false;
String oldCursorMark;
String cursorMark = CursorMarkParams.CURSOR_MARK_START;
QueryResponse resp;
// Cursor functionality requires a sort containing a uniqueKey field tie breaker
q.addSort(uniqueKey, SolrQuery.ORDER.desc);
while (!done) {
oldCursorMark = cursorMark;
q.set(CursorMarkParams.CURSOR_MARK_PARAM, cursorMark);
resp = server.query(q);
done = processor.apply(resp.getResults());
cursorMark = resp.getNextCursorMark();
done = done || oldCursorMark.equals(cursorMark);
}
}
示例2: DelegatingCursor
protected DelegatingCursor(SolrQuery query, String initalCursorMark) {
this.referenceQuery = query;
this.cursorMark = StringUtils.hasText(initalCursorMark) ? initalCursorMark : CursorMarkParams.CURSOR_MARK_START;
this.state = State.REDAY;
this.delegate = Collections.<T> emptyList().iterator();
}
示例3: processQuery
private void processQuery(SolrQuery query, WorkLog workLog) throws SolrServerException, IOException {
log.debug("Query for rule : {}", query.toString());
Timer.Context context = getTimer(getName() + ".processQuery").time();
// need to commit here so that we can ignore documents just processed
client.commit();
boolean more = true;
String cursor = CursorMarkParams.CURSOR_MARK_START;
while (more) {
query.set(CursorMarkParams.CURSOR_MARK_PARAM, cursor);
Timer.Context contextQuery = getTimer(getName() + ".query").time();
QueryResponse response = client.query(query);
workLog.ranSearch();
SolrDocumentList results = response.getResults();
log.debug("Found {} (of {} docs) in QT = {} ms", results.size(), results.getNumFound(), response.getQTime());
String nextCursor = response.getNextCursorMark();
if (nextCursor == null || cursor.equals(nextCursor)) {
more = false;
}
distributeResponse(results, workLog);
cursor = nextCursor;
contextQuery.stop();
}
// We do this at a higher level too, so this would seem redundant. There is a trade-off. Allowing parallelism
// between rules means rules can sometimes be re-processed redundantly. The higher level waitUntilCaughtUp() will
// ensure we never process rules at the same time rules are being changed.
// By doing a wait here as well however, we can collect accurate statistics about how much actual write activity we
// are really generating by passing the workLog into the work pool.
// When we have a better awareness of the typical work patterns it might be worth disabling this method call and
// then stop collecting the metrics to improve throughput.
waitUntilCaughtUp();
context.stop();
}
示例4: SolrDeepPagingIterator
/**
* Builds a new iterator with the given data.
*
* @param solr the SOLR facade.
* @param query the query that will be submitted.
*/
SolrDeepPagingIterator(final SolrServer solr, final SolrQuery query) {
this.solr = solr;
this.query = query;
this.sentCursorMark = CursorMarkParams.CURSOR_MARK_START;
this.query.set(CursorMarkParams.CURSOR_MARK_PARAM, CursorMarkParams.CURSOR_MARK_START);
}
示例5: testPagingWithCursorMark
@Test
public void testPagingWithCursorMark() throws QueryException {
int pageSize = 2;
String cursorMark = CursorMarkParams.CURSOR_MARK_START;
boolean done = false;
List<String> ids = new ArrayList<>();
// page through until the returned cursorMark is equal to the previous cursorMark
while (!done) {
// required to include a sort on the uniqueKey field to use cursorMark
Query query = new ExampleSummaryQuery("*:*", cursorMark, pageSize);
query.addSort(ExampleField.CREATE_DATE, SortOrder.DESC);
query.addSort(ExampleField.ID, SortOrder.ASC);
QueryResults<ExampleSummary> results = queryService.search(query);
assertNotNull(results);
assertNotNull(results.getResults());
assertTrue(results.getResults().size() <= pageSize);
assertEquals(5, results.getTotalResults());
assertEquals(0, results.getOffset());
assertEquals(pageSize, results.getPageSize());
assertNotNull(results.getCursorMark());
results.getResults().stream().forEach(r -> ids.add(r.getId()));
if (results.getCursorMark().equals(cursorMark)) {
done = true;
}
cursorMark = results.getCursorMark();
}
// verify we got ids 1-5 in order
assertEquals(5, ids.size());
for (int i=0; i < 5; i++) {
assertEquals(String.valueOf(5-i), ids.get(i));
}
}
示例6: BoundedSolrReader
private BoundedSolrReader(BoundedSolrSource source) {
this.source = source;
this.cursorMark = CursorMarkParams.CURSOR_MARK_START;
}
示例7: removeLink
@Override
public void removeLink(Term parent, Term term, String relationshipType)
{
try
{
SolrCommand command = this.getCommand();
SolrClient client = command.getClient();
String qText = ClientUtils.escapeQueryChars(parent.getId());
SolrQuery query = new SolrQuery();
query.setQuery(ENTITY + ":" + term.getId() + " AND " + RELATIONSHIPS + ":*" + qText + "*");
query.setFields(ID, RELATIONSHIPS, QUALIFIER);
query.setRows(5000);
query.addSort("id", ORDER.asc); // Pay attention to this line
String cursorMark = CursorMarkParams.CURSOR_MARK_START;
boolean done = false;
while (!done)
{
query.set(CursorMarkParams.CURSOR_MARK_PARAM, cursorMark);
QueryResponse response = client.query(query);
String nextCursorMark = response.getNextCursorMark();
SolrDocumentList list = response.getResults();
Iterator<SolrDocument> iterator = list.iterator();
while (iterator.hasNext())
{
SolrDocument document = iterator.next();
String value = (String) document.getFieldValue(RELATIONSHIPS);
JSONArray relationships = this.deserialize(value);
JSONArray update = new JSONArray();
boolean found = false;
for (int i = 0; i < relationships.length(); i++)
{
JSONObject relationship = relationships.getJSONObject(i);
if (relationship.getString(ID).equals(parent.getId()))
{
found = true;
}
if (!found)
{
update.put(relationship);
}
}
// Create a new editable SolrInputDocument
SolrInputDocument updateDoc = new SolrInputDocument();
updateDoc.addField(ID, (String) document.get(ID));
updateDoc.addField(RELATIONSHIPS, this.serialize(update));
updateDoc.addField(QUALIFIER, (String) document.get(QUALIFIER));
client.add(updateDoc);
}
if (cursorMark.equals(nextCursorMark))
{
done = true;
}
cursorMark = nextCursorMark;
}
command.doIt();
}
catch (SolrServerException | IOException | JSONException e)
{
throw new ProgrammingErrorException(e);
}
}
示例8: addSynonym
@Override
public void addSynonym(Term term, OntologyEntryIF synonym)
{
try
{
SolrCommand command = this.getCommand();
SolrClient client = command.getClient();
SolrQuery query = new SolrQuery();
query.setQuery(RELATIONSHIPS + ":*" + ClientUtils.escapeQueryChars(term.getId()) + "*");
query.setFields(ENTITY, RELATIONSHIPS, QUALIFIER);
query.setRows(5000);
query.addSort("id", ORDER.asc); // Pay attention to this line
String cursorMark = CursorMarkParams.CURSOR_MARK_START;
boolean done = false;
while (!done)
{
query.set(CursorMarkParams.CURSOR_MARK_PARAM, cursorMark);
QueryResponse response = client.query(query);
String nextCursorMark = response.getNextCursorMark();
SolrDocumentList list = response.getResults();
Iterator<SolrDocument> iterator = list.iterator();
while (iterator.hasNext())
{
SolrDocument document = iterator.next();
String value = (String) document.getFieldValue(RELATIONSHIPS);
JSONArray relationships = this.deserialize(value);
for (int i = 0; i < relationships.length(); i++)
{
JSONObject relationship = relationships.getJSONObject(i);
if (relationship.getString(ID).equals(term.getId()))
{
relationship.put(ID, synonym.getId());
relationship.put(LABEL, synonym.getLabel());
}
}
// Create a new editable SolrInputDocument
SolrInputDocument clone = new SolrInputDocument();
clone.addField(ENTITY, (String) document.get(ENTITY));
clone.addField(RELATIONSHIPS, this.serialize(relationships));
clone.addField(QUALIFIER, (String) document.get(QUALIFIER));
client.add(clone);
}
if (cursorMark.equals(nextCursorMark))
{
done = true;
}
cursorMark = nextCursorMark;
}
command.doIt();
}
catch (SolrServerException | IOException | JSONException e)
{
throw new ProgrammingErrorException(e);
}
}
示例9: updateSynonym
@Override
public void updateSynonym(OntologyEntryIF synonym)
{
try
{
SolrCommand command = this.getCommand();
SolrClient client = command.getClient();
SolrQuery query = new SolrQuery();
query.setQuery(RELATIONSHIPS + ":*" + ClientUtils.escapeQueryChars(synonym.getId()) + "*");
query.setFields(ID, RELATIONSHIPS, QUALIFIER);
query.setRows(5000);
query.addSort("id", ORDER.asc); // Pay attention to this line
String cursorMark = CursorMarkParams.CURSOR_MARK_START;
boolean done = false;
while (!done)
{
query.set(CursorMarkParams.CURSOR_MARK_PARAM, cursorMark);
QueryResponse response = client.query(query);
String nextCursorMark = response.getNextCursorMark();
SolrDocumentList list = response.getResults();
Iterator<SolrDocument> iterator = list.iterator();
while (iterator.hasNext())
{
SolrDocument document = iterator.next();
String value = (String) document.getFieldValue(RELATIONSHIPS);
JSONArray relationships = this.deserialize(value);
for (int i = 0; i < relationships.length(); i++)
{
JSONObject relationship = relationships.getJSONObject(i);
if (relationship.getString(ID).equals(synonym.getId()))
{
relationship.put(LABEL, synonym.getLabel());
}
}
// Create a new editable SolrInputDocument
SolrInputDocument updateDoc = new SolrInputDocument();
updateDoc.addField(ID, (String) document.get(ID));
updateDoc.addField(RELATIONSHIPS, this.serialize(relationships));
updateDoc.addField(QUALIFIER, (String) document.get(QUALIFIER));
client.add(updateDoc);
}
if (cursorMark.equals(nextCursorMark))
{
done = true;
}
cursorMark = nextCursorMark;
}
command.doIt();
}
catch (SolrServerException | IOException | JSONException e)
{
throw new ProgrammingErrorException(e);
}
}