Search in sources :

Example 6 with Document

use of com.google.appengine.api.search.Document in project teammates by TEAMMATES.

the class DataMigrationForFeedbackResponseCommentSearchDocument method postAction.

/**
 * {@inheritDoc}
 */
@Override
protected void postAction() {
    if (isPreview()) {
        return;
    }
    LoopHelper loopHelper = new LoopHelper(BATCH_SIZE, "documents processed.");
    List<Document> documentsToUpdate = new ArrayList<>();
    for (FeedbackResponseCommentAttributes comment : commentsToMigrate) {
        loopHelper.recordLoop();
        documentsToUpdate.add(new FeedbackResponseCommentSearchDocument(comment).build());
        if (documentsToUpdate.size() == BATCH_SIZE) {
            updateAndClearDocuments(documentsToUpdate);
        }
    }
    updateAndClearDocuments(documentsToUpdate);
}
Also used : FeedbackResponseCommentSearchDocument(teammates.storage.search.FeedbackResponseCommentSearchDocument) FeedbackResponseCommentAttributes(teammates.common.datatransfer.attributes.FeedbackResponseCommentAttributes) LoopHelper(teammates.client.scripts.util.LoopHelper) ArrayList(java.util.ArrayList) Document(com.google.appengine.api.search.Document) FeedbackResponseCommentSearchDocument(teammates.storage.search.FeedbackResponseCommentSearchDocument)

Example 7 with Document

use of com.google.appengine.api.search.Document in project teammates by TEAMMATES.

the class DataMigrationForFeedbackResponseCommentSearchDocumentDateFormat method isMigrationNeeded.

/**
 * {@inheritDoc}
 */
@Override
protected boolean isMigrationNeeded(FeedbackResponseCommentAttributes comment) {
    Document document = index.get(comment.getId().toString());
    if (document == null) {
        return false;
    }
    String sampleDateString = extractSampleDateString(document);
    return !isInInstantFormat(sampleDateString);
}
Also used : Document(com.google.appengine.api.search.Document)

Example 8 with Document

use of com.google.appengine.api.search.Document in project teammates by TEAMMATES.

the class DataMigrationForOrphanedCommentSearchDocuments method postAction.

@Override
protected void postAction() {
    println("Number of documents in the old format that have existing parent comments: " + numOfDocumentsNotDeleted);
    if (numOfDocumentsNotDeleted > 0) {
        println("Warning: these documents will not be deleted. Please run the other migration script again.");
    }
    if (isPreview()) {
        return;
    }
    LoopHelper loopHelper = new LoopHelper(BATCH_SIZE, "documents processed.");
    List<Document> batch = new ArrayList<>(BATCH_SIZE);
    for (Document document : documentsToDelete) {
        loopHelper.recordLoop();
        batch.add(document);
        if (batch.size() == BATCH_SIZE) {
            batchDeleteAndClear(batch);
        }
    }
    batchDeleteAndClear(batch);
}
Also used : LoopHelper(teammates.client.scripts.util.LoopHelper) ArrayList(java.util.ArrayList) Document(com.google.appengine.api.search.Document) ScoredDocument(com.google.appengine.api.search.ScoredDocument)

Example 9 with Document

use of com.google.appengine.api.search.Document in project teammates by TEAMMATES.

the class DataMigrationForOrphanedCommentSearchDocuments method getEntities.

@Override
protected List<Document> getEntities() {
    List<Document> allResults = new ArrayList<>();
    Cursor cursor = Cursor.newBuilder().build();
    while (cursor != null) {
        cursor = getMoreResults(cursor, allResults);
    }
    return allResults;
}
Also used : ArrayList(java.util.ArrayList) Document(com.google.appengine.api.search.Document) ScoredDocument(com.google.appengine.api.search.ScoredDocument) Cursor(com.google.appengine.api.search.Cursor)

Example 10 with Document

use of com.google.appengine.api.search.Document in project java-docs-samples by GoogleCloudPlatform.

the class DocumentServlet method doGet.

@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    PrintWriter out = resp.getWriter();
    Document document = Document.newBuilder().addField(Field.newBuilder().setName("coverLetter").setText("CoverLetter")).addField(Field.newBuilder().setName("resume").setHTML("<html></html>")).addField(Field.newBuilder().setName("fullName").setAtom("Foo Bar")).addField(Field.newBuilder().setName("submissionDate").setDate(new Date())).build();
    // [START access_document]
    String coverLetter = document.getOnlyField("coverLetter").getText();
    String resume = document.getOnlyField("resume").getHTML();
    String fullName = document.getOnlyField("fullName").getAtom();
    Date submissionDate = document.getOnlyField("submissionDate").getDate();
    // [END access_document]
    out.println("coverLetter: " + coverLetter);
    out.println("resume: " + resume);
    out.println("fullName: " + fullName);
    out.println("submissionDate: " + submissionDate.toString());
}
Also used : Document(com.google.appengine.api.search.Document) Date(java.util.Date) PrintWriter(java.io.PrintWriter)

Aggregations

Document (com.google.appengine.api.search.Document)19 ScoredDocument (com.google.appengine.api.search.ScoredDocument)8 PrintWriter (java.io.PrintWriter)6 Index (com.google.appengine.api.search.Index)5 ArrayList (java.util.ArrayList)5 Test (org.junit.Test)3 IndexSpec (com.google.appengine.api.search.IndexSpec)2 Date (java.util.Date)2 LoopHelper (teammates.client.scripts.util.LoopHelper)2 Cursor (com.google.appengine.api.search.Cursor)1 FieldType (com.google.appengine.api.search.Field.FieldType)1 GetRequest (com.google.appengine.api.search.GetRequest)1 OperationResult (com.google.appengine.api.search.OperationResult)1 PutException (com.google.appengine.api.search.PutException)1 PutResponse (com.google.appengine.api.search.PutResponse)1 Schema (com.google.appengine.api.search.Schema)1 SearchException (com.google.appengine.api.search.SearchException)1 StatusCode (com.google.appengine.api.search.StatusCode)1 User (com.google.appengine.api.users.User)1 Permission (com.willshex.blogwt.shared.api.datatype.Permission)1