Search in sources :

Example 1 with IndexSpec

use of com.google.appengine.api.search.IndexSpec in project java-docs-samples by GoogleCloudPlatform.

the class DeleteServlet method getIndex.

private Index getIndex() {
    IndexSpec indexSpec = IndexSpec.newBuilder().setName(SEARCH_INDEX).build();
    Index index = SearchServiceFactory.getSearchService().getIndex(indexSpec);
    return index;
}
Also used : IndexSpec(com.google.appengine.api.search.IndexSpec) Index(com.google.appengine.api.search.Index)

Example 2 with IndexSpec

use of com.google.appengine.api.search.IndexSpec in project java-docs-samples by GoogleCloudPlatform.

the class IndexServlet method doGet.

@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());
}
Also used : IndexSpec(com.google.appengine.api.search.IndexSpec) Index(com.google.appengine.api.search.Index) Document(com.google.appengine.api.search.Document) PrintWriter(java.io.PrintWriter)

Example 3 with IndexSpec

use of com.google.appengine.api.search.IndexSpec in project java-docs-samples by GoogleCloudPlatform.

the class SearchOptionServlet method getIndex.

private Index getIndex() {
    IndexSpec indexSpec = IndexSpec.newBuilder().setName(SEARCH_INDEX).build();
    Index index = SearchServiceFactory.getSearchService().getIndex(indexSpec);
    return index;
}
Also used : IndexSpec(com.google.appengine.api.search.IndexSpec) Index(com.google.appengine.api.search.Index)

Example 4 with IndexSpec

use of com.google.appengine.api.search.IndexSpec in project java-docs-samples by GoogleCloudPlatform.

the class SearchServlet method getIndex.

private Index getIndex() {
    IndexSpec indexSpec = IndexSpec.newBuilder().setName(SEARCH_INDEX).build();
    Index index = SearchServiceFactory.getSearchService().getIndex(indexSpec);
    return index;
}
Also used : IndexSpec(com.google.appengine.api.search.IndexSpec) Index(com.google.appengine.api.search.Index)

Example 5 with IndexSpec

use of com.google.appengine.api.search.IndexSpec in project java-docs-samples by GoogleCloudPlatform.

the class UtilsTest method indexADocument_successfullyInvoked.

@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");
}
Also used : IndexSpec(com.google.appengine.api.search.IndexSpec) Index(com.google.appengine.api.search.Index) Document(com.google.appengine.api.search.Document) Test(org.junit.Test)

Aggregations

Index (com.google.appengine.api.search.Index)9 IndexSpec (com.google.appengine.api.search.IndexSpec)9 Document (com.google.appengine.api.search.Document)2 PrintWriter (java.io.PrintWriter)2 MemcacheService (com.google.appengine.api.memcache.MemcacheService)1 PutException (com.google.appengine.api.search.PutException)1 Query (com.google.appengine.api.search.Query)1 QueryOptions (com.google.appengine.api.search.QueryOptions)1 ScoredDocument (com.google.appengine.api.search.ScoredDocument)1 SearchException (com.google.appengine.api.search.SearchException)1 SearchService (com.google.appengine.api.search.SearchService)1 SearchServiceConfig (com.google.appengine.api.search.SearchServiceConfig)1 SortOptions (com.google.appengine.api.search.SortOptions)1 Test (org.junit.Test)1