Java Code Examples for com.google.appengine.api.search.SearchServiceFactory#getSearchService()
The following examples show how to use
com.google.appengine.api.search.SearchServiceFactory#getSearchService() .
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 |
@Test public void testSearchServiceConfig() throws ExecutionException, InterruptedException { String indexName = "put-index"; String docId = "testPutDocs"; searchService = SearchServiceFactory.getSearchService(SearchServiceConfig.newBuilder().setDeadline(10.).build()); 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) { Results<ScoredDocument> res = oneIndex.search(""); Iterator<ScoredDocument> it = res.iterator(); assertEquals(docId + "1", it.next().getId()); assertEquals(docId + "2", it.next().getId()); sync(); } }
Example 2
Source File: SearchServlet.java From appengine-java-vm-runtime with Apache License 2.0 | 5 votes |
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 3
Source File: IndexTest.java From appengine-tck with Apache License 2.0 | 5 votes |
@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 4
Source File: MultitenancyServlet.java From java-docs-samples with Apache License 2.0 | 4 votes |
@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 5
Source File: SearchTestBase.java From appengine-tck with Apache License 2.0 | 4 votes |
@Before public void setUp() { searchService = SearchServiceFactory.getSearchService(); }