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


Java Index类代码示例

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


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

示例1: removeAll

import com.google.appengine.api.search.Index; //导入依赖的package包/类
protected int removeAll() {
    int count = 0;
    Index index = getIndex();
    GetRequest request = GetRequest.newBuilder().setReturningIdsOnly(true).setLimit(200).build();
    GetResponse<Document> response = index.getRange(request);

    // can only deleteUnit documents in blocks of 200 so we need to iterate until they're all gone
    while (!response.getResults().isEmpty()) {
        List<String> ids = new ArrayList<>();
        for (Document document : response) {
            ids.add(document.getId());
        }
        index.delete(ids);
        count += ids.size();
        response = index.getRange(request);
    }
    return count;
}
 
开发者ID:monPlan,项目名称:springboot-spwa-gae-demo,代码行数:19,代码来源:BaseGaeSearchService.java

示例2: indexAsync

import com.google.appengine.api.search.Index; //导入依赖的package包/类
@Nonnull
@Override
public <E> Runnable indexAsync(Map<String, E> entities) {
    if (entities.isEmpty()) {
        return doNothing();
    }

    Class<?> entityClass = entities.values().toArray()[0].getClass();
    if (!searchMetadata.hasIndexedFields(entityClass)) {
        return doNothing();
    }

    List<Document> documents = entities.entrySet().stream()
            .map(entry -> documentBuilder.apply(entry.getKey(), entry.getValue()))
            .collect(Collectors.toList());

    Index index = getIndex(entityClass);
    return new IndexOperation(
            index.putAsync(documents)
    );
}
 
开发者ID:n15g,项目名称:spring-boot-gae,代码行数:22,代码来源:SearchServiceImpl.java

示例3: clear

import com.google.appengine.api.search.Index; //导入依赖的package包/类
@Override
public <E> int clear(Class<E> entityClass) {
    Index index = getIndex(entityClass);

    GetRequest request = GetRequest.newBuilder()
            .setReturningIdsOnly(true)
            .setLimit(200) //Delete only allows 200 records at a time.
            .build();

    int count = 0;
    for (List<Document> documents = getDocumentIds(index, request); !documents.isEmpty(); documents = getDocumentIds(index, request)) {
        count += documents.size();
        unindex(entityClass, documents.stream().map(Document::getId));
    }
    return count;
}
 
开发者ID:n15g,项目名称:spring-boot-gae,代码行数:17,代码来源:SearchServiceImpl.java

示例4: 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

示例5: removeAllDocumentsFromIndex

import com.google.appengine.api.search.Index; //导入依赖的package包/类
/**
 * Cleans the index of places from all entries.
 */
private void removeAllDocumentsFromIndex() {
    Index index = PlacesHelper.getIndex();
    // As the request will only return up to 1000 documents,
    // we need to loop until there are no more documents in the index.
    // We batch delete 1000 documents per iteration.
    final int numberOfDocuments = 1000;
    while (true) {
        GetRequest request = GetRequest.newBuilder()
                .setReturningIdsOnly(true)
                .build();

        ArrayList<String> documentIds = new ArrayList<>(numberOfDocuments);
        GetResponse<Document> response = index.getRange(request);
        for (Document document : response.getResults()) {
            documentIds.add(document.getId());
        }

        if (documentIds.size() == 0) {
            break;
        }

        index.delete(documentIds);
    }
}
 
开发者ID:googlearchive,项目名称:MobileShoppingAssistant-sample,代码行数:28,代码来源:MaintenanceTasksServlet.java

示例6: doGet

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

示例7: 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

示例8: indexADocument_successfullyInvoked

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

示例9: 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

示例10: indexADocument_successfullyInvoked

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

示例11: 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

示例12: testGetIndexes

import com.google.appengine.api.search.Index; //导入依赖的package包/类
@Test
public void testGetIndexes() throws InterruptedException, ParseException {
    String indexName = "indextest";
    addData(indexName);
    GetIndexesRequest request = GetIndexesRequest.newBuilder()
        .setIndexNamePrefix(indexName)
        .setOffset(0)
        .setLimit(10)
        .build();
    GetResponse<Index> response = searchService.getIndexes(request);
    List<Index> listIndexes = response.getResults();
    assertEquals(2, listIndexes.size());

    for (Index oneIndex : listIndexes) {
        String name = oneIndex.getName();
        assertTrue(name.startsWith(indexName));
        verifyDocCount(oneIndex, -1);
    }
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:20,代码来源:IndexTest.java

示例13: testPutGetRangeGetRequest

import com.google.appengine.api.search.Index; //导入依赖的package包/类
@Test
public void testPutGetRangeGetRequest() throws InterruptedException {
    String indexName = "put-index";
    String docId = "testPutDocs";
    Index index = createIndex(indexName, docId);

    GetIndexesRequest request = GetIndexesRequest.newBuilder()
            .setIndexNamePrefix(indexName)
            .build();
    GetResponse<Index> response = searchService.getIndexes(request);
    List<Index> listIndexes = response.getResults();

    for (Index oneIndex : listIndexes) {
        GetResponse<Document> docs = oneIndex.getRange(GetRequest.newBuilder().setStartId(docId + "1").setLimit(10).build());
        sync();
        assertEquals(docs.getResults().size(), 2);
    }
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:19,代码来源:IndexTest.java

示例14: testPutGetRangeBuilder

import com.google.appengine.api.search.Index; //导入依赖的package包/类
@Test
public void testPutGetRangeBuilder() throws InterruptedException {
    String indexName = "put-index";
    String docId = "testPutDocs";
    Index index = createIndex(indexName, docId);

    GetIndexesRequest request = GetIndexesRequest.newBuilder()
            .setIndexNamePrefix(indexName)
            .build();
    GetResponse<Index> response = searchService.getIndexes(request);
    List<Index> listIndexes = response.getResults();

    for (Index oneIndex : listIndexes) {
        GetResponse<Document> docs = oneIndex.getRange(GetRequest.newBuilder().setStartId(docId + "1").setLimit(10));
        sync();
        assertEquals(docs.getResults().size(), 2);
    }
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:19,代码来源:IndexTest.java

示例15: testPutGetRangeAsyncGetResponse

import com.google.appengine.api.search.Index; //导入依赖的package包/类
@Test
public void testPutGetRangeAsyncGetResponse() throws InterruptedException, ExecutionException {
    String indexName = "put-index";
    String docId = "testPutDocs";
    Index index = createIndex(indexName, docId);

    GetIndexesRequest request = GetIndexesRequest.newBuilder()
            .setIndexNamePrefix(indexName)
            .build();
    GetResponse<Index> response = searchService.getIndexes(request);
    List<Index> listIndexes = response.getResults();

    for (Index oneIndex : listIndexes) {
        Future<GetResponse<Document>> futurDocs = oneIndex.getRangeAsync(GetRequest.newBuilder().setStartId(docId + "1").setLimit(10).build());
        sync();
        assertEquals(futurDocs.get().getResults().size(), 2);
    }
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:19,代码来源:IndexTest.java


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