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


Java Field类代码示例

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


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

示例1: buildDocument

import com.google.appengine.api.search.Field; //导入依赖的package包/类
protected Document buildDocument(K id, Map<String, Object> fields) {
    String stringId = convert(id, String.class);
    Builder documentBuilder = Document.newBuilder();
    documentBuilder.setId(stringId);
    for (Map.Entry<String, Object> fieldData : fields.entrySet()) {
        Object value = fieldData.getValue();
        String fieldName = fieldData.getKey();
        for (Object object : getCollectionValues(value)) {
            try {
                Field field = buildField(metadata, fieldName, object);
                documentBuilder.addField(field);
            } catch (Exception e) {
                throw new SearchException(e, "Failed to add field '%s' with value '%s' to document with id '%s': %s", fieldName, value.toString(), id, e.getMessage());
            }
        }
    }

    return documentBuilder.build();
}
 
开发者ID:monPlan,项目名称:springboot-spwa-gae-demo,代码行数:20,代码来源:BaseGaeSearchService.java

示例2: getMutator

import com.google.appengine.api.search.Field; //导入依赖的package包/类
private BiConsumer<Field.Builder, Object> getMutator(IndexType indexType) {
    switch (indexType) {
        case IDENTIFIER:
            return this::setAtom;
        case NUMBER:
            return this::setNumber;
        case HTML:
            return this::setHtml;
        case DATE:
            return this::setDate;
        case GEOPOINT:
            return this::setGeopoint;
        default:
            return this::setText;
    }
}
 
开发者ID:n15g,项目名称:spring-boot-gae,代码行数:17,代码来源:FieldBuilder.java

示例3: indexApp

import com.google.appengine.api.search.Field; //导入依赖的package包/类
/**
 * index gallery app into search index
 * @param app galleryapp
 */
public void indexApp (GalleryApp app) {
  // take the title, description, and the user name and index it
  // need to build up a string with all meta data
  String indexWords = app.getTitle()+" "+app.getDescription() + " " + app.getDeveloperName();
  // now create the doc
  Document doc = Document.newBuilder()
    .setId(String.valueOf(app.getGalleryAppId()))
    .addField(Field.newBuilder().setName("content").setText(indexWords))
    .build();

  Index index = getIndex();

  try {
    index.put(doc);
  } catch (PutException e) {
    if (StatusCode.TRANSIENT_ERROR.equals(e.getOperationResult().getCode())) {
        // retry putting the document
    }
  }
}
 
开发者ID:mit-cml,项目名称:appinventor-extensions,代码行数:25,代码来源:GallerySearchIndex.java

示例4: buildDocument

import com.google.appengine.api.search.Field; //导入依赖的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();
}
 
开发者ID:googlearchive,项目名称:MobileShoppingAssistant-sample,代码行数:32,代码来源:PlacesHelper.java

示例5: doGet

import com.google.appengine.api.search.Field; //导入依赖的package包/类
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
  PrintWriter out = resp.getWriter();
  Document document = Document.newBuilder()
      .setId("AZ125")
      .addField(Field.newBuilder().setName("myField").setText("myValue")).build();
  try {
    Utils.indexADocument(INDEX, document);
  } catch (InterruptedException e) {
    out.println("Interrupted");
    return;
  }
  out.println("Indexed a new document.");
  // [START get_document]
  IndexSpec indexSpec = IndexSpec.newBuilder().setName(INDEX).build();
  Index index = SearchServiceFactory.getSearchService().getIndex(indexSpec);

  // Fetch a single document by its  doc_id
  Document doc = index.get("AZ125");

  // Fetch a range of documents by their doc_ids
  GetResponse<Document> docs = index.getRange(
      GetRequest.newBuilder().setStartId("AZ125").setLimit(100).build());
  // [END get_document]
  out.println("myField: " + docs.getResults().get(0).getOnlyField("myField").getText());
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:27,代码来源:IndexServlet.java

示例6: createDocument

import com.google.appengine.api.search.Field; //导入依赖的package包/类
/**
 * Code snippet for creating a Document.
 * @return Document Created document.
 */
public Document createDocument() {
  // [START create_document]
  User currentUser = UserServiceFactory.getUserService().getCurrentUser();
  String userEmail = currentUser == null ? "" : currentUser.getEmail();
  String userDomain = currentUser == null ? "" : currentUser.getAuthDomain();
  String myDocId = "PA6-5000";
  Document doc = Document.newBuilder()
      // Setting the document identifer is optional.
      // If omitted, the search service will create an identifier.
      .setId(myDocId)
      .addField(Field.newBuilder().setName("content").setText("the rain in spain"))
      .addField(Field.newBuilder().setName("email").setText(userEmail))
      .addField(Field.newBuilder().setName("domain").setAtom(userDomain))
      .addField(Field.newBuilder().setName("published").setDate(new Date()))
      .build();
  // [END create_document]
  return doc;
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:23,代码来源:DocumentServlet.java

示例7: doGet

import com.google.appengine.api.search.Field; //导入依赖的package包/类
@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());
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:22,代码来源:DocumentServlet.java

示例8: doGet

import com.google.appengine.api.search.Field; //导入依赖的package包/类
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp)
    throws IOException {
  // Put one document to avoid an error
  Document document = Document.newBuilder()
      .setId("theOnlyCoffeeRoaster")
      .addField(Field.newBuilder().setName("price").setNumber(200))
      .addField(Field.newBuilder().setName("model").setText("TZ4000"))
      .addField(Field.newBuilder().setName("brand").setText("MyBrand"))
      .addField(Field.newBuilder().setName("product").setText("coffee roaster"))
      .addField(Field.newBuilder()
          .setName("description").setText("A coffee bean roaster at home"))
      .build();
  try {
    Utils.indexADocument(SEARCH_INDEX, document);
  } catch (InterruptedException e) {
    // ignore
  }
  PrintWriter out = resp.getWriter();
  Results<ScoredDocument> result = doSearch();
  for (ScoredDocument doc : result.getResults()) {
    out.println(doc.toString());
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:25,代码来源:SearchOptionServlet.java

示例9: indexADocument_successfullyInvoked

import com.google.appengine.api.search.Field; //导入依赖的package包/类
@Test
public void indexADocument_successfullyInvoked() throws Exception {
  String id = "test";
  Document doc = Document.newBuilder()
      .setId(id)
      .addField(Field.newBuilder().setName("f").setText("v"))
      .build();
  Utils.indexADocument(INDEX, doc);
  // get the document by id
  IndexSpec indexSpec = IndexSpec.newBuilder().setName(INDEX).build();
  Index index = SearchServiceFactory.getSearchService().getIndex(indexSpec);
  Document fetched = index.get(id);
  assertThat(fetched.getOnlyField("f").getText())
      .named("A value of the fetched document")
      .isEqualTo("v");
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:17,代码来源:UtilsTest.java

示例10: createDocument

import com.google.appengine.api.search.Field; //导入依赖的package包/类
/**
 * Code snippet for creating a Document.
 *
 * @return Document Created document.
 */
public Document createDocument() {
  // [START create_document]
  User currentUser = UserServiceFactory.getUserService().getCurrentUser();
  String userEmail = currentUser == null ? "" : currentUser.getEmail();
  String userDomain = currentUser == null ? "" : currentUser.getAuthDomain();
  String myDocId = "PA6-5000";
  Document doc =
      Document.newBuilder()
          // Setting the document identifer is optional.
          // If omitted, the search service will create an identifier.
          .setId(myDocId)
          .addField(Field.newBuilder().setName("content").setText("the rain in spain"))
          .addField(Field.newBuilder().setName("email").setText(userEmail))
          .addField(Field.newBuilder().setName("domain").setAtom(userDomain))
          .addField(Field.newBuilder().setName("published").setDate(new Date()))
          .build();
  // [END create_document]
  return doc;
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:25,代码来源:DocumentServlet.java

示例11: doGet

import com.google.appengine.api.search.Field; //导入依赖的package包/类
@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());
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:22,代码来源:DocumentServlet.java

示例12: doGet

import com.google.appengine.api.search.Field; //导入依赖的package包/类
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
  // Put one document to avoid an error
  Document document =
      Document.newBuilder()
          .setId("theOnlyCoffeeRoaster")
          .addField(Field.newBuilder().setName("price").setNumber(200))
          .addField(Field.newBuilder().setName("model").setText("TZ4000"))
          .addField(Field.newBuilder().setName("brand").setText("MyBrand"))
          .addField(Field.newBuilder().setName("product").setText("coffee roaster"))
          .addField(
              Field.newBuilder().setName("description").setText("A coffee bean roaster at home"))
          .build();
  try {
    Utils.indexADocument(SEARCH_INDEX, document);
  } catch (InterruptedException e) {
    // ignore
  }
  PrintWriter out = resp.getWriter();
  Results<ScoredDocument> result = doSearch();
  for (ScoredDocument doc : result.getResults()) {
    out.println(doc.toString());
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:25,代码来源:SearchOptionServlet.java

示例13: indexADocument_successfullyInvoked

import com.google.appengine.api.search.Field; //导入依赖的package包/类
@Test
public void indexADocument_successfullyInvoked() throws Exception {
  String id = "test";
  Document doc =
      Document.newBuilder()
          .setId(id)
          .addField(Field.newBuilder().setName("f").setText("v"))
          .build();
  Utils.indexADocument(INDEX, doc);
  // get the document by id
  IndexSpec indexSpec = IndexSpec.newBuilder().setName(INDEX).build();
  Index index = SearchServiceFactory.getSearchService().getIndex(indexSpec);
  Document fetched = index.get(id);
  assertThat(fetched.getOnlyField("f").getText())
      .named("A value of the fetched document")
      .isEqualTo("v");
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:18,代码来源:UtilsTest.java

示例14: addToIndex

import com.google.appengine.api.search.Field; //导入依赖的package包/类
private void addToIndex(GeneralItem gi) throws PutException {
		System.out.println(gi);
//		JSONObject giObject = JSONParser.parseStrict(gi.toString()).isObject();
		String richText ="";
		try {
			JSONObject giObject = new JSONObject(gi.toString());
			if (giObject.has("richText")){
				richText = giObject.getString("richText");
			}
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		Document doc = Document.newBuilder()
				.setId("gi:" + generalItemId)
				.addField(Field.newBuilder().setName("gameId").setNumber(getGameId()))
				.addField(Field.newBuilder().setName("generalItemId").setNumber(getGeneralItemId()))
				.addField(Field.newBuilder().setName("title").setText(getGeneralItemTitle()))
				.addField(Field.newBuilder().setName("richText").setText(richText))
				.build();
		getIndex().put(doc);
	}
 
开发者ID:WELTEN,项目名称:dojo-ibl,代码行数:24,代码来源:GeneralItemSearchIndex.java

示例15: getAllSearchFieldsByType

import com.google.appengine.api.search.Field; //导入依赖的package包/类
/**
 * Obtains a list of {@link com.google.appengine.api.search.Field} from {@link FieldType}.
 * 
 * @param obj
 *            the object base
 * @param classOfObj
 *            the class of object
 * @return a list of {@link com.google.appengine.api.search.Field}
 * @throws IllegalArgumentException
 * @throws IllegalAccessException
 */
List<com.google.appengine.api.search.Field> getAllSearchFieldsByType(String fieldNamePrefix, Object obj,
    Class<?> classOfObj, FieldType fieldType) throws IllegalArgumentException, IllegalAccessException {

    List<com.google.appengine.api.search.Field> fields = new ArrayList<Field>(0);

    for (java.lang.reflect.Field f : getAllDocumentField(classOfObj)) {

        // TODO: validate field (declaration of annotation)
        DocumentField annotation = ObjectParser.getDocumentFieldAnnotation(f);

        if (annotation.type().equals(fieldType)) {
            String name = ObjectParser.getFieldNameValue(f, annotation);
            String fullName = Strings.isNullOrEmpty(fieldNamePrefix) ? name : fieldNamePrefix + "_" + name;
            com.google.appengine.api.search.Field field = getSearchFieldByFieldType(fullName, f, obj, fieldType);
            if (field != null) {
                fields.add(field);
            }
        }
    }

    return fields;
}
 
开发者ID:marcosvidolin,项目名称:doco,代码行数:34,代码来源:DocumentParser.java


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