本文整理汇总了Java中com.google.appengine.api.search.Document.Builder方法的典型用法代码示例。如果您正苦于以下问题:Java Document.Builder方法的具体用法?Java Document.Builder怎么用?Java Document.Builder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.appengine.api.search.Document
的用法示例。
在下文中一共展示了Document.Builder方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildDocument
import com.google.appengine.api.search.Document; //导入方法依赖的package包/类
/**
* Builds a new Place document to insert in the Places index.
* @param placeId the identifier of the place in the database.
* @param placeName the name of the place.
* @param placeAddress the address of the place.
* @param location the GPS location of the place, as a GeoPt.
* @return the Place document created.
*/
public static Document buildDocument(
final Long placeId, final String placeName,
final String placeAddress, final GeoPt location) {
GeoPoint geoPoint = new GeoPoint(location.getLatitude(),
location.getLongitude());
Document.Builder builder = Document.newBuilder()
.addField(Field.newBuilder().setName("id")
.setText(placeId.toString()))
.addField(Field.newBuilder().setName("name").setText(placeName))
.addField(Field.newBuilder().setName("address")
.setText(placeAddress))
.addField(Field.newBuilder().setName("place_location")
.setGeoPoint(geoPoint));
// geo-location doesn't work under dev_server, so let's add another
// field to use for retrieving documents
if (environment.value() == Development) {
builder.addField(Field.newBuilder().setName("value").setNumber(1));
}
return builder.build();
}
示例2: parseDocument
import com.google.appengine.api.search.Document; //导入方法依赖的package包/类
/**
* Parses a object to an {@link Document}.
*
* @param obj
* the object to be parsed
* @param documentId
* user defined id of document (e.g. 'Key' of a datastore entity).
* @param typeOfObj
* the base class of the given object
* @return a {@link Document}
* @throws IllegalAccessException
* @throws IllegalArgumentException
*/
Document parseDocument(Object obj, String documentId, Class<?> classOfObj) throws IllegalArgumentException,
IllegalAccessException {
String id = documentId;
if (id == null) {
java.lang.reflect.Field field = getDocumentIdField(classOfObj);
id = String.valueOf(getId(obj, classOfObj, field.getType()));
}
Document.Builder builder = Document.newBuilder().setId(id);
for (com.google.appengine.api.search.Field f : getAllFieldsForDocument(DEFAULT_FIELD_NAME_PREFIX, obj,
classOfObj)) {
if (f != null) {
builder.addField(f);
}
}
for (Facet facet : getAllFacetsForDocument(obj, classOfObj)) {
builder.addFacet(facet);
}
return builder.build();
}
示例3: createIndex
import com.google.appengine.api.search.Document; //导入方法依赖的package包/类
private Index createIndex(String indexName, String docId) {
Index index = searchService.getIndex(IndexSpec.newBuilder()
.setName(indexName)
.build());
Field field = Field.newBuilder().setName("subject").setText("put(Document.Builder)").build();
Document.Builder docBuilder = Document.newBuilder()
.setId(docId + "1")
.addField(field);
index.put(docBuilder);
field = Field.newBuilder().setName("subject").setText("put(Document)").build();
Document document = Document.newBuilder()
.setId(docId + "2")
.addField(field).build();
index.put(document);
return index;
}
示例4: buildDocument
import com.google.appengine.api.search.Document; //导入方法依赖的package包/类
static Document buildDocument(
String placeId, String placeName, String placeAddress, GeoPt location) {
GeoPoint geoPoint = new GeoPoint(location.getLatitude(), location.getLongitude());
Document.Builder builder = Document.newBuilder()
.addField(Field.newBuilder().setName("id").setText(placeId))
.addField(Field.newBuilder().setName("name").setText(placeName))
.addField(Field.newBuilder().setName("address").setText(placeAddress))
.addField(Field.newBuilder().setName("place_location").setGeoPoint(geoPoint));
// geo-location doesn't work under dev_server, so let's add another
// field to use for retrieving documents
if (environment.value() == Development) {
builder.addField(Field.newBuilder().setName("value").setNumber(1));
}
Document place = builder.build();
return place;
}
开发者ID:googlearchive,项目名称:solutions-mobile-shopping-assistant-backend-java,代码行数:21,代码来源:PlacesHelper.java
示例5: apply
import com.google.appengine.api.search.Document; //导入方法依赖的package包/类
@Override
public Document apply(Object id, Object entity) {
String idValue = conversionService.convert(id, String.class);
Document.Builder builder = createDocument(idValue);
Map<String, SearchFieldMetadata> accessors = searchMetadata.getFields(entity.getClass());
accessors.values().forEach((accessor) -> {
List<Field> searchFields = fieldBuilder.apply(accessor, accessor.getValue(entity));
searchFields.forEach(builder::addField);
});
return builder.build();
}
示例6: toDocument
import com.google.appengine.api.search.Document; //导入方法依赖的package包/类
@Override
public Document toDocument (Page page) {
Document document = null;
if (page != null) {
Document.Builder documentBuilder = Document.newBuilder();
documentBuilder.setId(getName() + page.id.toString())
.addField(Field.newBuilder().setName("owner")
.setAtom(page.owner.username))
.addField(Field.newBuilder().setName("owner")
.setText(UserHelper.name(page.owner)))
.addField(Field.newBuilder().setName("created")
.setDate(page.created))
.addField(Field.newBuilder().setName("title")
.setText(page.title));
if (page.posts != null) {
StringBuilder body = new StringBuilder();
for (Post post : page.posts) {
body.append(post.content.body).append("\n\n");
}
documentBuilder.addField(Field.newBuilder().setName("body")
.setText(body.toString()));
}
document = documentBuilder.build();
}
return document;
}
示例7: addDocument
import com.google.appengine.api.search.Document; //导入方法依赖的package包/类
public void addDocument(Index index, String docid) {
Document.Builder builder = Document.newBuilder();
builder.setId(docid);
builder.setRank(docid.hashCode());
Field.Builder field = Field.newBuilder();
field.setName("title");
field.setText(String.format("Title: title%%<%s>", docid));
builder.addField(field);
field = Field.newBuilder();
field.setName("body");
field.setHTML(String.format("<h3>body of %s, some string</h3>", docid));
builder.addField(field);
field = Field.newBuilder();
field.setName("atom");
field.setAtom(String.format("atom%% <%s>", docid));
builder.addField(field);
field = Field.newBuilder();
field.setName("number");
field.setNumber(docid.hashCode() % 4096);
builder.addField(field);
field = Field.newBuilder();
field.setName("date");
field.setDate(new Date(2011 - 1900, 11 - 1, (docid.hashCode() % 30) + 1));
builder.addField(field);
index.put(builder.build());
}
示例8: testPutDeleteDocs
import com.google.appengine.api.search.Document; //导入方法依赖的package包/类
@Test
public void testPutDeleteDocs() throws InterruptedException {
String indexName = "put-index";
String docId = "testPutDocs";
List<String> docIdList = new ArrayList<>();
Index index = searchService.getIndex(IndexSpec.newBuilder()
.setName(indexName)
.build());
Field field = Field.newBuilder().setName("subject").setText("put(Document.Builder)").build();
Document.Builder docBuilder = Document.newBuilder()
.setId(docId + "1")
.addField(field);
index.put(docBuilder);
docIdList.add(docId + "1");
field = Field.newBuilder().setName("subject").setText("put(Document)").build();
Document document = Document.newBuilder()
.setId(docId + "2")
.addField(field).build();
index.put(document);
docIdList.add(docId + "1");
GetIndexesRequest request = GetIndexesRequest.newBuilder()
.setIndexNamePrefix(indexName)
.build();
GetResponse<Index> response = searchService.getIndexes(request);
List<Index> listIndexes = response.getResults();
for (Index oneIndex : listIndexes) {
Field retField = oneIndex.get(docId + "1").getOnlyField("subject");
assertEquals("put(Document.Builder)", retField.getText());
retField = oneIndex.get(docId + "2").getOnlyField("subject");
assertEquals("put(Document)", retField.getText());
oneIndex.delete(docIdList.get(0));
sync();
assertNull(oneIndex.get(docIdList.get(0)));
}
}
示例9: testPutDeleteAsyncDocsByString
import com.google.appengine.api.search.Document; //导入方法依赖的package包/类
@Test
public void testPutDeleteAsyncDocsByString() throws InterruptedException {
String indexName = "put-index";
String docId = "testPutDocs";
List<String> docIdList = new ArrayList<>();
Index index = searchService.getIndex(IndexSpec.newBuilder()
.setName(indexName)
.build());
Field field = Field.newBuilder().setName("subject").setText("put(Document.Builder)").build();
Document.Builder docBuilder = Document.newBuilder()
.setId(docId + "1")
.addField(field);
index.put(docBuilder);
docIdList.add(docId + "1");
field = Field.newBuilder().setName("subject").setText("put(Document)").build();
Document document = Document.newBuilder()
.setId(docId + "2")
.addField(field).build();
index.put(document);
docIdList.add(docId + "1");
GetIndexesRequest request = GetIndexesRequest.newBuilder()
.setIndexNamePrefix(indexName)
.build();
GetResponse<Index> response = searchService.getIndexes(request);
List<Index> listIndexes = response.getResults();
for (Index oneIndex : listIndexes) {
Field retField = oneIndex.get(docId + "1").getOnlyField("subject");
assertEquals("put(Document.Builder)", retField.getText());
retField = oneIndex.get(docId + "2").getOnlyField("subject");
assertEquals("put(Document)", retField.getText());
oneIndex.deleteAsync(docIdList.get(0));
sync();
assertNull(oneIndex.get(docIdList.get(0)));
}
}
示例10: testPutAsyncBuilder
import com.google.appengine.api.search.Document; //导入方法依赖的package包/类
@Test
public void testPutAsyncBuilder() {
String indexName = "put-index";
String docId = "testPutDocs";
Index index = searchService.getIndex(IndexSpec.newBuilder()
.setName(indexName)
.build());
Field field = Field.newBuilder().setName("subject").setText("put(Document.Builder)").build();
Document.Builder docBuilder = Document.newBuilder()
.setId(docId + "1")
.addField(field);
index.putAsync(docBuilder);
GetIndexesRequest request = GetIndexesRequest.newBuilder()
.setIndexNamePrefix(indexName)
.build();
GetResponse<Index> response = searchService.getIndexes(request);
List<Index> listIndexes = response.getResults();
for (Index oneIndex : listIndexes) {
Field retField = oneIndex.get(docId + "1").getOnlyField("subject");
sync();
assertEquals("put(Document.Builder)", retField.getText());
}
}
示例11: createDocument
import com.google.appengine.api.search.Document; //导入方法依赖的package包/类
private Document.Builder createDocument(String idValue) {
Document.Builder builder = Document.newBuilder();
builder.setId(idValue);
return builder;
}
示例12: index
import com.google.appengine.api.search.Document; //导入方法依赖的package包/类
private void index(ConvFields fields, ParticipantId user, @Nullable Supplement supplement)
throws RetryableFailure, PermanentFailure {
if (!isParticipantValidForIndexing(user)) {
log.warning(fields.slobId + ": Participant not valid for indexing: " + user);
return;
}
boolean isArchived = false;
boolean isFollowed = true;
int unreadBlips = fields.blipCount;
boolean participantsUnread = true;
if (supplement != null) {
isArchived = supplement.isArchived(fields.waveletId, fields.version);
isFollowed = supplement.isFollowed(true);
unreadBlips = fields.conv == null ? 0
: countUnreadBlips(fields.conv, fields.waveletId, fields.version, supplement);
participantsUnread = isParticipantListUnread(fields.version, supplement);
}
log.info("Unread blips: " + unreadBlips + "; participants unread: " + participantsUnread
+ "; has supplement: " + (supplement != null));
Document.Builder builder = Document.newBuilder();
builder.setId(fields.slobId.getId());
builder.addField(Field.newBuilder().setName(ID_FIELD).setAtom(fields.slobId.getId()));
builder.addField(Field.newBuilder().setName(CREATOR_FIELD).setText(fields.creator));
builder.addField(Field.newBuilder().setName(TITLE_FIELD).setText(
shortenTextMaybe(fields.title)));
builder.addField(Field.newBuilder().setName(CONTENT_FIELD).setText(
shortenTextMaybe(fields.indexableText)));
builder.addField(Field.newBuilder().setName(MODIFIED_MINUTES_FIELD).setNumber(
fields.lastModifiedMillis / 1000 / 60));
builder.addField(Field.newBuilder().setName(BLIP_COUNT_FIELD).setNumber(fields.blipCount));
builder.addField(Field.newBuilder().setName(UNREAD_BLIP_COUNT_FIELD).setNumber(unreadBlips));
if (!isArchived) {
builder.addField(Field.newBuilder().setName(IN_FOLDER_FIELD).setText(IN_INBOX_TEXT));
}
builder.addField(Field.newBuilder().setName(IS_FIELD).setAtom(
unreadBlips == 0 && !participantsUnread ? IS_READ_ATOM : IS_UNREAD_ATOM));
if (isArchived) {
builder.addField(Field.newBuilder().setName(IS_FIELD).setAtom(IS_ARCHIVED_ATOM));
}
if (isFollowed) {
builder.addField(Field.newBuilder().setName(IS_FIELD).setAtom(IS_FOLLOWED_ATOM));
}
Document doc = builder.build();
Index idx = getIndex(user);
log.info("Saving index document " + describe(doc));
// TODO(danilatos): Factor out all the error handling?
AddResponse resp;
try {
resp = idx.add(doc);
} catch (AddException e) {
throw new RetryableFailure("Error indexing " + fields.slobId, e);
}
for (OperationResult result : resp) {
if (!result.getCode().equals(StatusCode.OK)) {
throw new RetryableFailure("Error indexing " + fields.slobId + ", " + result.getMessage());
}
}
}
示例13: toDocument
import com.google.appengine.api.search.Document; //导入方法依赖的package包/类
@Override
public Document toDocument (Post post) {
Document document = null;
if (Boolean.TRUE.equals(post.listed) && post.published != null) {
if (post.author == null) {
post.author = UserServiceProvider.provide()
.getUser(keyToId(post.authorKey));
}
Document.Builder documentBuilder = Document.newBuilder();
documentBuilder.setId(getName() + post.id.toString())
.addField(Field.newBuilder().setName("author")
.setAtom(post.author.username))
.addField(Field.newBuilder().setName("author")
.setText(UserHelper.name(post.author)))
.addField(Field.newBuilder().setName("created")
.setDate(post.created))
.addField(Field.newBuilder().setName("published")
.setDate(post.published))
.addField(Field.newBuilder().setName("slug")
.setAtom(post.slug))
.addField(Field.newBuilder().setName("summary")
.setText(post.summary))
.addField(Field.newBuilder().setName("title")
.setText(post.title));
if (post.content != null) {
documentBuilder.addField(Field.newBuilder().setName("body")
.setText(post.content.body));
}
if (post.tags != null) {
for (String tag : post.tags) {
documentBuilder.addField(
Field.newBuilder().setName("tag").setText(tag));
}
}
document = documentBuilder.build();
}
return document;
}
示例14: toDocument
import com.google.appengine.api.search.Document; //导入方法依赖的package包/类
@Override
public Document toDocument (User user) {
Document document = null;
if (user != null) {
Document.Builder documentBuilder = Document.newBuilder();
documentBuilder.setId(getName() + user.id.toString())
.addField(Field.newBuilder().setName("username")
.setAtom(user.username))
.addField(Field.newBuilder().setName("name")
.setText(UserHelper.name(user)))
.addField(Field.newBuilder().setName("forename")
.setText(user.forename))
.addField(Field.newBuilder().setName("surname")
.setText(user.surname))
.addField(Field.newBuilder().setName("email")
.setText(user.email))
.addField(Field.newBuilder().setName("created")
.setDate(user.created))
.addField(Field.newBuilder().setName("group")
.setText(user.group))
.addField(Field.newBuilder().setName("summary")
.setText(user.summary));
if (user.roles != null) {
for (Role role : user.roles) {
documentBuilder.addField(Field.newBuilder().setName("role")
.setText(role.name));
}
}
if (user.permissions != null) {
for (Permission permission : user.permissions) {
documentBuilder.addField(Field.newBuilder()
.setName("permission").setText(permission.name));
}
}
document = documentBuilder.build();
}
return document;
}