Search in sources :

Example 1 with Index

use of com.google.appengine.api.search.Index 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 Index

use of com.google.appengine.api.search.Index 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 Index

use of com.google.appengine.api.search.Index 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 Index

use of com.google.appengine.api.search.Index 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 Index

use of com.google.appengine.api.search.Index 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)13 IndexSpec (com.google.appengine.api.search.IndexSpec)9 Document (com.google.appengine.api.search.Document)5 PrintWriter (java.io.PrintWriter)4 PutException (com.google.appengine.api.search.PutException)3 ScoredDocument (com.google.appengine.api.search.ScoredDocument)3 OperationResult (com.google.appengine.api.search.OperationResult)2 PutResponse (com.google.appengine.api.search.PutResponse)2 SearchException (com.google.appengine.api.search.SearchException)2 MemcacheService (com.google.appengine.api.memcache.MemcacheService)1 FieldType (com.google.appengine.api.search.Field.FieldType)1 Query (com.google.appengine.api.search.Query)1 QueryOptions (com.google.appengine.api.search.QueryOptions)1 Schema (com.google.appengine.api.search.Schema)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 StatusCode (com.google.appengine.api.search.StatusCode)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1