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


Java Index.put方法代码示例

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


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

示例1: indexApp

import com.google.appengine.api.search.Index; //导入方法依赖的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

示例2: indexADocument

import com.google.appengine.api.search.Index; //导入方法依赖的package包/类
/**
 * Put a given document into an index with the given indexName.
 * @param indexName The name of the index.
 * @param document A document to add.
 * @throws InterruptedException When Thread.sleep is interrupted.
 */
// [START putting_document_with_retry]
public static void indexADocument(String indexName, Document document)
    throws InterruptedException {
  IndexSpec indexSpec = IndexSpec.newBuilder().setName(indexName).build();
  Index index = SearchServiceFactory.getSearchService().getIndex(indexSpec);

  final int maxRetry = 3;
  int attempts = 0;
  int delay = 2;
  while (true) {
    try {
      index.put(document);
    } catch (PutException e) {
      if (StatusCode.TRANSIENT_ERROR.equals(e.getOperationResult().getCode())
          && ++attempts < maxRetry) { // retrying
        Thread.sleep(delay * 1000);
        delay *= 2; // easy exponential backoff
        continue;
      } else {
        throw e; // otherwise throw
      }
    }
    break;
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:32,代码来源:Utils.java

示例3: indexADocument

import com.google.appengine.api.search.Index; //导入方法依赖的package包/类
/**
 * Put a given document into an index with the given indexName.
 *
 * @param indexName The name of the index.
 * @param document A document to add.
 * @throws InterruptedException When Thread.sleep is interrupted.
 */
// [START putting_document_with_retry]
public static void indexADocument(String indexName, Document document)
    throws InterruptedException {
  IndexSpec indexSpec = IndexSpec.newBuilder().setName(indexName).build();
  Index index = SearchServiceFactory.getSearchService().getIndex(indexSpec);

  final int maxRetry = 3;
  int attempts = 0;
  int delay = 2;
  while (true) {
    try {
      index.put(document);
    } catch (PutException e) {
      if (StatusCode.TRANSIENT_ERROR.equals(e.getOperationResult().getCode())
          && ++attempts < maxRetry) { // retrying
        Thread.sleep(delay * 1000);
        delay *= 2; // easy exponential backoff
        continue;
      } else {
        throw e; // otherwise throw
      }
    }
    break;
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:33,代码来源:Utils.java

示例4: savePackage

import com.google.appengine.api.search.Index; //导入方法依赖的package包/类
/**
 * Saves a package. The package can be new or an already existing one. The
 * total number of packages and the index will be automatically updated.
 *
 * @param ofy Objectify
 * @param old old version of the package object or null
 * @param p package
 * @param changeLastModifiedAt change the last modification time
 */
public static void savePackage(Objectify ofy, Package old, Package p,
        boolean changeLastModifiedAt) {
    if (ofy.find(p.createKey()) == null) {
        NWUtils.increasePackageNumber();
    }
    if (changeLastModifiedAt) {
        p.lastModifiedAt = NWUtils.newDate();
        p.lastModifiedBy = UserServiceFactory.getUserService().
                getCurrentUser();
    }

    ofy.put(p);
    NWUtils.incDataVersion();
    Index index = NWUtils.getIndex();
    index.put(p.createDocument());
}
 
开发者ID:tim-lebedkov,项目名称:npackd-gae-web,代码行数:26,代码来源:NWUtils.java

示例5: createIndex

import com.google.appengine.api.search.Index; //导入方法依赖的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;
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:19,代码来源:IndexTest.java

示例6: recreateIndex

import com.google.appengine.api.search.Index; //导入方法依赖的package包/类
/**
 * Re-creates the index for packages
 */
public static void recreateIndex() {
    Objectify ofy = DefaultServlet.getObjectify();
    Query<Package> q = ofy.query(Package.class);
    Index index = getIndex();
    for (Package p : q) {
        index.put(p.createDocument());
    }
}
 
开发者ID:tim-lebedkov,项目名称:npackd-gae-web,代码行数:12,代码来源:NWUtils.java

示例7: doGet

import com.google.appengine.api.search.Index; //导入方法依赖的package包/类
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
		throws ServletException, IOException {

	SearchManager searchManager = SearchManager.getInstance();

	PersistenceManager pm = PMF.get().getPersistenceManager();
	List<Article> articles = new ArticleManager(pm).findAll();
	Index index = searchManager.getIndex();
	for (Article article : articles) {
		Document doc = searchManager.createDocument(article);
		index.put(doc);
	}
	pm.close();
}
 
开发者ID:santiagolizardo,项目名称:jerba,代码行数:16,代码来源:SearchIndexUpdateServlet.java

示例8: addDocument

import com.google.appengine.api.search.Index; //导入方法依赖的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());
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-java-vm-runtime,代码行数:33,代码来源:SearchServlet.java

示例9: addDocs

import com.google.appengine.api.search.Index; //导入方法依赖的package包/类
protected void addDocs(Index index, int docCount) throws ParseException, InterruptedException {
    if (searchDocs(index, "", 0).getNumberFound() == 0) {
        List<Document> documents = new ArrayList<>();
        Calendar cal = Calendar.getInstance();
        DateFormat dfDate = new SimpleDateFormat("yyyy,M,d");
        for (int i = 0; i < docCount; i++) {
            Builder docBuilder = Document.newBuilder();
            // two text field with different locale
            docBuilder.addField(Field.newBuilder().setName("textfield").setText("text with num " + i));
            Field field = Field.newBuilder().setName("textfield").setText("C'est la vie " + i).setLocale(Locale.FRENCH).build();
            docBuilder.addField(field);
            docBuilder.addField(Field.newBuilder().setName("numfield").setNumber(i));
            String dateVal = "" + cal.get(Calendar.YEAR) + ",";
            dateVal += cal.get(Calendar.MONTH) + ",";
            int day = cal.get(Calendar.DATE) + i;
            dateVal += day;
            docBuilder.addField(Field.newBuilder().setName("datefield").setDate(dfDate.parse(dateVal)));
            docBuilder.addField(Field.newBuilder().setName("htmlfield").setHTML("<B>html</B> " + i));
            docBuilder.addField(Field.newBuilder().setName("atomfield").setAtom("atom" + i + ".com"));
            GeoPoint geoPoint = new GeoPoint((double) i, (double) (100 + i));
            docBuilder.addField(Field.newBuilder().setName("geofield").setGeoPoint(geoPoint));
            // two field in same name and with different field type
            docBuilder.addField(Field.newBuilder().setName("mixfield").setText("text and number mix field"));
            docBuilder.addField(Field.newBuilder().setName("mixfield").setNumber(987));
            docBuilder.setId("selfid" + i);
            // only doc(id="selfid0") has "cn" locale, others have "en" locale
            if (i == 0) {
                docBuilder.setLocale(new Locale("cn"));
            } else {
                docBuilder.setLocale(new Locale("en"));
            }
            documents.add(docBuilder.build());
        }
        index.put(documents);
        sync();
    }
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:38,代码来源:SearchTestBase.java

示例10: testCreateDocument

import com.google.appengine.api.search.Index; //导入方法依赖的package包/类
@Test
public void testCreateDocument() throws Exception {
    String indexName = "test-doc";
    Index index = searchService.getIndex(IndexSpec.newBuilder().setName(indexName));
    delDocs(index);
    Builder docBuilder = Document.newBuilder().setId("tck").setLocale(Locale.FRENCH).setRank(8);
    docBuilder.addField(Field.newBuilder().setName("field1").setText("text field"));
    docBuilder.addField(Field.newBuilder().setName("field1").setNumber(987));
    docBuilder.addField(Field.newBuilder().setName("field2").setNumber(123));
    docBuilder.addField(Field.newBuilder().setName("field3").setDate(new Date()));
    index.put(docBuilder.build());
    sync();

    Results<ScoredDocument> result = searchDocs(index, "", 0);
    assertEquals(1, result.getNumberReturned());
    ScoredDocument retDoc = result.iterator().next();
    assertEquals("tck", retDoc.getId());
    assertEquals(Locale.FRENCH, retDoc.getLocale());
    assertEquals(8, retDoc.getRank());
    assertEquals(2, retDoc.getFieldCount("field1"));
    assertEquals(1, retDoc.getFieldCount("field3"));
    assertEquals(3, retDoc.getFieldNames().size());

    Iterator<Field> fields = retDoc.getFields().iterator();
    int count = 0;
    for ( ; fields.hasNext() ; ++count ) {
        fields.next();
    }
    assertEquals(4, count);

    fields = retDoc.getFields("field1").iterator();
    count = 0;
    for ( ; fields.hasNext() ; ++count ) {
        fields.next();
    }
    assertEquals(2, count);

    Field field = retDoc.getOnlyField("field2");
    assertEquals(FieldType.NUMBER, field.getType());
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:41,代码来源:DocumentTest.java

示例11: testPutDeleteDocs

import com.google.appengine.api.search.Index; //导入方法依赖的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)));
    }
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:39,代码来源:IndexTest.java

示例12: testPutDeleteAsyncDocsByString

import com.google.appengine.api.search.Index; //导入方法依赖的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)));
    }
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:39,代码来源:IndexTest.java

示例13: testDocFields

import com.google.appengine.api.search.Index; //导入方法依赖的package包/类
@Test
public void testDocFields() throws Exception {
    String indexName = "test-doc-fields";
    Index index = searchService.getIndex(IndexSpec.newBuilder().setName(indexName));
    delDocs(index);

    Builder docBuilder = Document.newBuilder();
    Field field = Field.newBuilder().setName("textfield").setText("text field").build();
    docBuilder.addField(field);
    field = Field.newBuilder().setName("numberfield").setNumber(123).build();
    docBuilder.addField(field);
    Date now = new Date();
    field = Field.newBuilder().setName("datefield").setDate(now).build();
    docBuilder.addField(field);
    field = Field.newBuilder().setName("htmlfield").setHTML("<html>html field</html>").build();
    docBuilder.addField(field);
    User currentUser = new User("[email protected]", "appenginetest.com");
    field = Field.newBuilder().setName("atomfield").setAtom(currentUser.getAuthDomain()).build();
    docBuilder.addField(field);
    GeoPoint geoPoint = new GeoPoint((double) -10, 10.000001);
    field = Field.newBuilder().setName("geofield").setGeoPoint(geoPoint).build();
    docBuilder.addField(field);
    index.put(docBuilder);
    sync();

    Results<ScoredDocument> result = searchDocs(index, "", 0);
    assertEquals(1, result.getNumberReturned());
    ScoredDocument doc = result.iterator().next();
    Field retField = doc.getOnlyField("textfield");
    assertEquals(FieldType.TEXT, retField.getType());
    assertEquals("textfield", retField.getName());
    assertEquals("text field", retField.getText());

    retField = doc.getOnlyField("numberfield");
    assertEquals(FieldType.NUMBER, retField.getType());
    assertEquals(new Double("123"), retField.getNumber());

    retField = doc.getOnlyField("datefield");
    assertEquals(FieldType.DATE, retField.getType());
    assertEquals(now, retField.getDate());

    retField = doc.getOnlyField("htmlfield");
    assertEquals(FieldType.HTML, retField.getType());
    assertEquals("<html>html field</html>", retField.getHTML());

    retField = doc.getOnlyField("atomfield");
    assertEquals(FieldType.ATOM, retField.getType());
    assertEquals(currentUser.getAuthDomain(), retField.getAtom());

    retField = doc.getOnlyField("geofield");
    assertEquals(FieldType.GEO_POINT, retField.getType());
    assertEquals(-10, retField.getGeoPoint().getLatitude(), 0);
    assertEquals(10.000001, retField.getGeoPoint().getLongitude(), 0.000000);
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:55,代码来源:FieldTest.java


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