com.google.appengine.api.search.IndexSpec Java Examples

The following examples show how to use com.google.appengine.api.search.IndexSpec. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SearchServiceTest.java    From appengine-tck with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #2
Source File: IndexTest.java    From appengine-tck with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #3
Source File: Utils.java    From java-docs-samples with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
  }
}
 
Example #4
Source File: UtilsTest.java    From java-docs-samples with Apache License 2.0 6 votes vote down vote up
@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);
  assertWithMessage("A value of the fetched document")
      .that(fetched.getOnlyField("f").getText())
      .isEqualTo("v");
}
 
Example #5
Source File: IndexTest.java    From appengine-tck with Apache License 2.0 5 votes vote down vote up
@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());
    }
}
 
Example #6
Source File: IndexTest.java    From appengine-tck with Apache License 2.0 5 votes vote down vote up
@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)));
    }
}
 
Example #7
Source File: IndexTest.java    From appengine-tck with Apache License 2.0 5 votes vote down vote up
@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)));
    }
}
 
Example #8
Source File: IndexTest.java    From appengine-tck with Apache License 2.0 5 votes vote down vote up
public void testNamespace() throws InterruptedException, ParseException {
    String ns = "ns-indextest";
    String indexName = "ns-index";
    int docCount = 5;
    NamespaceManager.set(ns);
    Index index = searchService.getIndex(IndexSpec.newBuilder()
            .setName(indexName)
            .build());
    delDocs(index);
    addDocs(index, docCount);

    GetIndexesRequest request = GetIndexesRequest.newBuilder()
        .setIndexNamePrefix(indexName)
        .setOffset(0)
        .setNamespace(ns)
        .setLimit(10)
        .build();
    assertEquals(ns, request.getNamespace());
    GetResponse<Index> response = searchService.getIndexes(request);
    List<Index> listIndexes = response.getResults();
    for (Index oneIndex : listIndexes) {
        assertEquals(ns, listIndexes.get(0).getNamespace());
        assertEquals(indexName, listIndexes.get(0).getName());
        verifyDocCount(oneIndex, docCount);
    }
    assertEquals(ns, searchService.getNamespace());
    NamespaceManager.set("");
}
 
Example #9
Source File: IndexTest.java    From appengine-tck with Apache License 2.0 5 votes vote down vote up
@Test
public void testNamespaceWithBug() throws InterruptedException, ParseException {
    String ns = "ns-indextest";
    String indexName = "ns-index";
    int docCount = 5;
    NamespaceManager.set(ns);
    SearchService searchService2 = SearchServiceFactory.getSearchService();
    Index index = searchService2.getIndex(IndexSpec.newBuilder()
            .setName(indexName)
            .build());
    delDocs(index);
    addDocs(index, docCount);

    GetIndexesRequest request = GetIndexesRequest.newBuilder()
        .setIndexNamePrefix(indexName)
        .setOffset(0)
        .setNamespace(ns)
        .setLimit(10)
        .build();
    assertEquals(ns, request.getNamespace());
    GetResponse<Index> response = searchService2.getIndexes(request);
    List<Index> listIndexes = response.getResults();
    for (Index oneIndex : listIndexes) {
        assertEquals(ns, listIndexes.get(0).getNamespace());
        assertEquals(indexName, listIndexes.get(0).getName());
        verifyDocCount(oneIndex, docCount);
    }
    assertEquals(ns, searchService2.getNamespace());
    NamespaceManager.set("");
}
 
Example #10
Source File: IndexTest.java    From appengine-tck with Apache License 2.0 5 votes vote down vote up
@Test
public void testPutAsyncDocument() {
    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)").build();
    Document document = Document.newBuilder()
            .setId(docId + "1")
            .addField(field).build();

    Future<PutResponse> resp = index.putAsync(document);

    while (!resp.isDone()) {
        if (resp.isCancelled()) {
            break;
        }
    }

    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)", retField.getText());
    }
}
 
Example #11
Source File: DocumentTest.java    From appengine-tck with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example #12
Source File: SearchServlet.java    From appengine-java-vm-runtime with Apache License 2.0 5 votes vote down vote up
public void initIndexes() {
  SearchService search = SearchServiceFactory.getSearchService();
  IndexSpec.Builder spec = IndexSpec.newBuilder();

  for (int i = 0; i < 25; i++) {
    String name = String.format("index%s", i);
    spec.setName(name);
    addDocuments(search.getIndex(spec), name, i == 0 ? 25 : 1);
  }
  search = SearchServiceFactory.getSearchService("ns");
  spec.setName("<b>");
  addDocuments(search.getIndex(spec), "other", 1);
}
 
Example #13
Source File: SearchManager.java    From teammates with GNU General Public License v2.0 5 votes vote down vote up
private static Index getIndex(String indexName) {
    Map<String, Index> indicesTable = getIndicesTable();
    Index index = indicesTable.get(indexName);
    if (index == null) {
        IndexSpec indexSpec = IndexSpec.newBuilder().setName(indexName).build();
        index = SearchServiceFactory.getSearchService().getIndex(indexSpec);
        indicesTable.put(indexName, index);
    }
    return index;
}
 
Example #14
Source File: IndexTest.java    From appengine-tck with Apache License 2.0 5 votes vote down vote up
private void addData(String indexName) throws InterruptedException, ParseException {
    Index index;
    index = searchService.getIndex(IndexSpec.newBuilder().setName(indexName + "3"));
    delDocs(index);
    addDocs(index, 3);
    index = searchService.getIndex(IndexSpec.newBuilder().setName(indexName + "7"));
    delDocs(index);
    addDocs(index, 7);
}
 
Example #15
Source File: SearchServiceTest.java    From appengine-tck with Apache License 2.0 5 votes vote down vote up
@Before
public void addData() throws ParseException, InterruptedException {
    super.setUp();
    index = searchService.getIndex(IndexSpec.newBuilder().setName("appenginetck"));
    delDocs(index);
    addDocs(index, 3);
}
 
Example #16
Source File: IndexServlet.java    From java-docs-samples with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example #17
Source File: IndexTest.java    From appengine-tck with Apache License 2.0 4 votes vote down vote up
@Test
public void testPutAsyncIterable() {
    String indexName = "put-index";
    String docId = "testPutDocs";

    Index index = searchService.getIndex(IndexSpec.newBuilder()
            .setName(indexName)
            .build());

    List<Document> documents = new ArrayList<>();
    Field field = Field.newBuilder().setName("subject").setText("put(Document)").build();
    Document document1 = Document.newBuilder()
            .setId(docId + "1")
            .addField(field).build();
    field = Field.newBuilder().setName("subject").setText("put(Document)").build();
    Document document2 = Document.newBuilder()
            .setId(docId + "2")
            .addField(field).build();

    documents.add(document1);
    documents.add(document2);

    Future<PutResponse> resp = index.putAsync(documents);

    while (!resp.isDone()) {
        if (resp.isCancelled()) {
            break;
        }
    }

    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)", retField.getText());
        retField = oneIndex.get(docId + "2").getOnlyField("subject");
        assertEquals("put(Document)", retField.getText());
        sync();
    }
}
 
Example #18
Source File: PlacesHelper.java    From solutions-mobile-shopping-assistant-backend-java with Apache License 2.0 4 votes vote down vote up
static Index getIndex() {
  IndexSpec indexSpec = IndexSpec.newBuilder().setName(INDEX_NAME).build();
  return SearchServiceFactory.getSearchService().getIndex(indexSpec);
}
 
Example #19
Source File: FieldTest.java    From appengine-tck with Apache License 2.0 4 votes vote down vote up
@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);
}
 
Example #20
Source File: GallerySearchIndex.java    From appinventor-extensions with Apache License 2.0 4 votes vote down vote up
/**
 * @return the search index
 */
private Index getIndex() {
  IndexSpec indexSpec = IndexSpec.newBuilder().setName(GALLERYINDEX).build();
  Index index = SearchServiceFactory.getSearchService().getIndex(indexSpec);
  return index;
}
 
Example #21
Source File: SearchOptionServlet.java    From java-docs-samples with Apache License 2.0 4 votes vote down vote up
private Results<ScoredDocument> doSearch() {
  String indexName = SEARCH_INDEX;
  // [START search_with_options]
  try {
    // Build the SortOptions with 2 sort keys
    SortOptions sortOptions =
        SortOptions.newBuilder()
            .addSortExpression(
                SortExpression.newBuilder()
                    .setExpression("price")
                    .setDirection(SortExpression.SortDirection.DESCENDING)
                    .setDefaultValueNumeric(0))
            .addSortExpression(
                SortExpression.newBuilder()
                    .setExpression("brand")
                    .setDirection(SortExpression.SortDirection.DESCENDING)
                    .setDefaultValue(""))
            .setLimit(1000)
            .build();

    // Build the QueryOptions
    QueryOptions options =
        QueryOptions.newBuilder()
            .setLimit(25)
            .setFieldsToReturn("model", "price", "description")
            .setSortOptions(sortOptions)
            .build();

    // A query string
    String queryString = "product: coffee roaster AND price < 500";

    //  Build the Query and run the search
    Query query = Query.newBuilder().setOptions(options).build(queryString);
    IndexSpec indexSpec = IndexSpec.newBuilder().setName(indexName).build();
    Index index = SearchServiceFactory.getSearchService().getIndex(indexSpec);
    Results<ScoredDocument> result = index.search(query);
    return result;
  } catch (SearchException e) {
    // handle exception...
  }
  // [END search_with_options]
  return null;
}
 
Example #22
Source File: SearchOptionServlet.java    From java-docs-samples with Apache License 2.0 4 votes vote down vote up
private Index getIndex() {
  IndexSpec indexSpec = IndexSpec.newBuilder().setName(SEARCH_INDEX).build();
  Index index = SearchServiceFactory.getSearchService().getIndex(indexSpec);
  return index;
}
 
Example #23
Source File: SearchServlet.java    From java-docs-samples with Apache License 2.0 4 votes vote down vote up
private Index getIndex() {
  IndexSpec indexSpec = IndexSpec.newBuilder().setName(SEARCH_INDEX).build();
  Index index = SearchServiceFactory.getSearchService().getIndex(indexSpec);
  return index;
}
 
Example #24
Source File: DeleteServlet.java    From java-docs-samples with Apache License 2.0 4 votes vote down vote up
private Index getIndex() {
  IndexSpec indexSpec = IndexSpec.newBuilder().setName(SEARCH_INDEX).build();
  Index index = SearchServiceFactory.getSearchService().getIndex(indexSpec);
  return index;
}
 
Example #25
Source File: MultitenancyServlet.java    From java-docs-samples with Apache License 2.0 4 votes vote down vote up
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
  String namespace;

  PrintWriter out = resp.getWriter();
  out.println("Code Snippets -- not yet fully runnable as an app");

  // [START temp_namespace]
  // Set the namepace temporarily to "abc"
  String oldNamespace = NamespaceManager.get();
  NamespaceManager.set("abc");
  try {
    //      ... perform operation using current namespace ...
  } finally {
    NamespaceManager.set(oldNamespace);
  }
  // [END temp_namespace]

  // [START per_user_namespace]
  if (com.google.appengine.api.NamespaceManager.get() == null) {
    // Assuming there is a logged in user.
    namespace = UserServiceFactory.getUserService().getCurrentUser().getUserId();
    NamespaceManager.set(namespace);
  }
  // [END per_user_namespace]
  String value = "something here";

  // [START ns_memcache]
  // Create a MemcacheService that uses the current namespace by
  // calling NamespaceManager.get() for every access.
  MemcacheService current = MemcacheServiceFactory.getMemcacheService();

  // stores value in namespace "abc"
  oldNamespace = NamespaceManager.get();
  NamespaceManager.set("abc");
  try {
    current.put("key", value); // stores value in namespace “abc”
  } finally {
    NamespaceManager.set(oldNamespace);
  }
  // [END ns_memcache]

  // [START specific_memcache]
  // Create a MemcacheService that uses the namespace "abc".
  MemcacheService explicit = MemcacheServiceFactory.getMemcacheService("abc");
  explicit.put("key", value); // stores value in namespace "abc"
  // [END specific_memcache]

  //[START searchns]
  // Set the current namespace to "aSpace"
  NamespaceManager.set("aSpace");
  // Create a SearchService with the namespace "aSpace"
  SearchService searchService = SearchServiceFactory.getSearchService();
  // Create an IndexSpec
  IndexSpec indexSpec = IndexSpec.newBuilder().setName("myIndex").build();
  // Create an Index with the namespace "aSpace"
  Index index = searchService.getIndex(indexSpec);
  // [END searchns]

  // [START searchns_2]
  // Create a SearchServiceConfig, specifying the namespace "anotherSpace"
  SearchServiceConfig config =
      SearchServiceConfig.newBuilder().setNamespace("anotherSpace").build();
  // Create a SearchService with the namespace "anotherSpace"
  searchService = SearchServiceFactory.getSearchService(config);
  // Create an IndexSpec
  indexSpec = IndexSpec.newBuilder().setName("myindex").build();
  // Create an Index with the namespace "anotherSpace"
  index = searchService.getIndex(indexSpec);
  // [END searchns_2]

}
 
Example #26
Source File: PlacesHelper.java    From MobileShoppingAssistant-sample with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the Places index in the datastore.
 * @return The index to use to search places in the datastore.
 */
public static Index getIndex() {
    IndexSpec indexSpec = IndexSpec.newBuilder().setName(INDEX_NAME)
            .build();
    return SearchServiceFactory.getSearchService().getIndex(indexSpec);
}