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


Java Results类代码示例

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


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

示例1: doGet

import com.google.appengine.api.search.Results; //导入依赖的package包/类
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp)
    throws IOException {
  // Put one document to avoid an error
  Document document = Document.newBuilder()
      .setId("theOnlyCoffeeRoaster")
      .addField(Field.newBuilder().setName("price").setNumber(200))
      .addField(Field.newBuilder().setName("model").setText("TZ4000"))
      .addField(Field.newBuilder().setName("brand").setText("MyBrand"))
      .addField(Field.newBuilder().setName("product").setText("coffee roaster"))
      .addField(Field.newBuilder()
          .setName("description").setText("A coffee bean roaster at home"))
      .build();
  try {
    Utils.indexADocument(SEARCH_INDEX, document);
  } catch (InterruptedException e) {
    // ignore
  }
  PrintWriter out = resp.getWriter();
  Results<ScoredDocument> result = doSearch();
  for (ScoredDocument doc : result.getResults()) {
    out.println(doc.toString());
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:25,代码来源:SearchOptionServlet.java

示例2: doGet

import com.google.appengine.api.search.Results; //导入依赖的package包/类
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
  // Put one document to avoid an error
  Document document =
      Document.newBuilder()
          .setId("theOnlyCoffeeRoaster")
          .addField(Field.newBuilder().setName("price").setNumber(200))
          .addField(Field.newBuilder().setName("model").setText("TZ4000"))
          .addField(Field.newBuilder().setName("brand").setText("MyBrand"))
          .addField(Field.newBuilder().setName("product").setText("coffee roaster"))
          .addField(
              Field.newBuilder().setName("description").setText("A coffee bean roaster at home"))
          .build();
  try {
    Utils.indexADocument(SEARCH_INDEX, document);
  } catch (InterruptedException e) {
    // ignore
  }
  PrintWriter out = resp.getWriter();
  Results<ScoredDocument> result = doSearch();
  for (ScoredDocument doc : result.getResults()) {
    out.println(doc.toString());
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:25,代码来源:SearchOptionServlet.java

示例3: prepareSearchResults

import com.google.appengine.api.search.Results; //导入依赖的package包/类
protected List<SearchResult> prepareSearchResults(
		Results<ScoredDocument> docs) {
	List<SearchResult> results = new ArrayList<>();
	for (ScoredDocument doc : docs) {
		SearchResult result = new SearchResult();
		result.setId(doc.getOnlyField("id").getNumber().longValue());
		result.setTitle(doc.getOnlyField("title").getText());
		result.setSanitizedTitle(doc.getOnlyField("sanitizedTitle")
				.getText());
		result.setDescription(doc.getOnlyField("description").getText());
		result.setKeywords(doc.getOnlyField("keywords").getText());
		result.setContent(doc.getOnlyField("content").getHTML());
		result.setPublicationDate(doc.getOnlyField("publicationDate")
				.getDate());
		results.add(result);
	}
	return results;
}
 
开发者ID:santiagolizardo,项目名称:jerba,代码行数:19,代码来源:SearchManager.java

示例4: search

import com.google.appengine.api.search.Results; //导入依赖的package包/类
@Override
public List<Post> search (String query, Integer start, Integer count,
		String sortBy, SortDirectionType direction) {
	Results<ScoredDocument> matches = SearchHelper.getIndex().search(query);
	List<Post> posts = new ArrayList<Post>();
	String id;
	Post post;
	int limit = SearchHelper.SHORT_SEARCH_LIMIT;
	final String postServiceName = getName();
	for (ScoredDocument scoredDocument : matches) {
		if (limit == 0) {
			break;
		}

		if ((id = scoredDocument.getId()).startsWith(postServiceName)) {
			post = getPost(Long.valueOf(id.replace(postServiceName, "")));
			if (post != null) {
				posts.add(post);
			}
		}

		limit--;
	}

	return posts;
}
 
开发者ID:billy1380,项目名称:blogwt,代码行数:27,代码来源:PostService.java

示例5: search

import com.google.appengine.api.search.Results; //导入依赖的package包/类
@Override
public List<User> search (String query, Integer start, Integer count,
		String sortBy, SortDirectionType direction) {
	Results<ScoredDocument> matches = SearchHelper.getIndex().search(query);
	List<User> users = new ArrayList<User>();
	String id;
	User user;
	int limit = count;
	final String userServiceName = getName();
	for (ScoredDocument scoredDocument : matches) {
		if (limit == 0) {
			break;
		}

		if ((id = scoredDocument.getId()).startsWith(userServiceName)) {
			user = getUser(Long.valueOf(id.replace(userServiceName, "")));
			if (user != null) {
				users.add(user);
			}
		}

		limit--;
	}

	return users;
}
 
开发者ID:billy1380,项目名称:blogwt,代码行数:27,代码来源:UserService.java

示例6: search

import com.google.appengine.api.search.Results; //导入依赖的package包/类
@Override
public List<Page> search (String query, Integer start, Integer count,
		String sortBy, SortDirectionType direction) {
	Results<ScoredDocument> matches = SearchHelper.getIndex().search(query);
	List<Page> pages = new ArrayList<Page>();
	String id;
	Page page;
	int limit = count;
	final String pageServiceName = getName();
	for (ScoredDocument scoredDocument : matches) {
		if (limit == 0) {
			break;
		}

		if ((id = scoredDocument.getId()).startsWith(getName())) {
			page = getPage(Long.valueOf(id.replace(pageServiceName, "")));
			if (page != null) {
				pages.add(page);
			}
		}

		limit--;
	}

	return pages;
}
 
开发者ID:billy1380,项目名称:blogwt,代码行数:27,代码来源:PageService.java

示例7: fromResults

import com.google.appengine.api.search.Results; //导入依赖的package包/类
/**
 * Produces a {@link StudentSearchResultBundle} from the {@code Results<ScoredDocument>} collection.
 * The list of {@link InstructorAttributes} is used to filter out the search result.
 *
 * <p>This method should be used by admin only since the searching does not restrict the
 * visibility according to the logged-in user's google ID.
 */
public static StudentSearchResultBundle fromResults(Results<ScoredDocument> results) {
    StudentSearchResultBundle bundle = new StudentSearchResultBundle();
    if (results == null) {
        return bundle;
    }

    for (ScoredDocument doc : results) {
        StudentAttributes student = JsonUtils.fromJson(
                doc.getOnlyField(Const.SearchDocumentField.STUDENT_ATTRIBUTE).getText(),
                StudentAttributes.class);
        if (student.key == null
                || studentsDb.getStudentForRegistrationKey(StringHelper.encrypt(student.key)) == null) {
            studentsDb.deleteDocument(student);
            continue;
        }

        bundle.studentList.add(student);
        bundle.numberOfResults++;
    }

    sortStudentResultList(bundle.studentList);

    return bundle;
}
 
开发者ID:TEAMMATES,项目名称:teammates,代码行数:32,代码来源:StudentSearchDocument.java

示例8: filterOutCourseId

import com.google.appengine.api.search.Results; //导入依赖的package包/类
/**
 * This method must be called to filter out the search result for course Id.
 */
protected static List<ScoredDocument> filterOutCourseId(Results<ScoredDocument> results,
                                                        List<InstructorAttributes> instructors) {
    Set<String> courseIdSet = new HashSet<>();
    for (InstructorAttributes ins : instructors) {
        courseIdSet.add(ins.courseId);
    }

    List<ScoredDocument> filteredResults = new ArrayList<>();
    for (ScoredDocument document : results) {
        String resultCourseId = document.getOnlyField(Const.SearchDocumentField.COURSE_ID).getText();
        if (courseIdSet.contains(resultCourseId)) {
            filteredResults.add(document);
        }
    }
    return filteredResults;
}
 
开发者ID:TEAMMATES,项目名称:teammates,代码行数:20,代码来源:SearchDocument.java

示例9: fromResults

import com.google.appengine.api.search.Results; //导入依赖的package包/类
/**
 * Produces an {@link InstructorSearchResultBundle} from the {@code Results<ScoredDocument>} collection.
 *
 * <p>This method should be used by admin only since the searching does not restrict the
 * visibility according to the logged-in user's google ID.
 */
public static InstructorSearchResultBundle fromResults(Results<ScoredDocument> results) {
    InstructorSearchResultBundle bundle = new InstructorSearchResultBundle();
    if (results == null) {
        return bundle;
    }

    for (ScoredDocument doc : results) {
        InstructorAttributes instructor = JsonUtils.fromJson(
                doc.getOnlyField(Const.SearchDocumentField.INSTRUCTOR_ATTRIBUTE).getText(),
                InstructorAttributes.class);

        if (instructorsDb.getInstructorForRegistrationKey(StringHelper.encrypt(instructor.key)) == null) {
            instructorsDb.deleteDocument(instructor);
            continue;
        }

        bundle.instructorList.add(instructor);
        bundle.numberOfResults++;
    }

    sortInstructorResultList(bundle.instructorList);

    return bundle;
}
 
开发者ID:TEAMMATES,项目名称:teammates,代码行数:31,代码来源:InstructorSearchDocument.java

示例10: testGetField

import com.google.appengine.api.search.Results; //导入依赖的package包/类
@Test
public void  testGetField() {
    String namelist = "geofield; textfield; numfield; atomfield; datefield; htmlfield; mixfield";
    Results<ScoredDocument> result = searchDocs(index, "", 0);
    for (ScoredDocument doc : result) {
        assertEquals(2, doc.getFieldCount("textfield"));
        String id = doc.getId();
        assertNotNull(id);
        if (id.endsWith("0")) {
            assertEquals(new Locale("cn"), doc.getLocale());
        } else {
            assertEquals(new Locale("en"), doc.getLocale());
        }

        for (String name : doc.getFieldNames()) {
            assertTrue(namelist.contains(name));
        }

        Iterator<Field> fields = doc.getFields().iterator();
        int count = 0;
        for ( ; fields.hasNext() ; ++count ) {
            fields.next();
        }
        assertEquals(9, count);
    }
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:27,代码来源:SearchServiceTest.java

示例11: testLocale

import com.google.appengine.api.search.Results; //导入依赖的package包/类
@Test
public void testLocale() {
    Results<ScoredDocument> result = searchDocs(index, "", 0);
    for (ScoredDocument doc : result) {
        String id = doc.getId();
        if (id.endsWith("0")) {
            assertEquals(new Locale("cn"), doc.getLocale());
        } else {
            assertEquals(new Locale("en"), doc.getLocale());
        }

        boolean found = false;
        for (Field textField : doc.getFields("textfield")) {
            Locale locale = textField.getLocale();
            if ((locale != null) && locale.equals(Locale.FRENCH)) {
                found = true;
            }
        }
        assertTrue(found);
    }
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:22,代码来源:SearchServiceTest.java

示例12: testSearchAsyncQuery

import com.google.appengine.api.search.Results; //导入依赖的package包/类
@Test
public void testSearchAsyncQuery() throws ExecutionException, 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) {
        QueryOptions.Builder optionBuilder = QueryOptions.newBuilder();
        optionBuilder.setLimit(10);
        Query.Builder queryBuilder = Query.newBuilder().setOptions(optionBuilder.build());
        Future<Results<ScoredDocument>> Fres = oneIndex.searchAsync(queryBuilder.build(""));

        Iterator<ScoredDocument> it = Fres.get().iterator();
        assertEquals(docId + "1", it.next().getId());
        assertEquals(docId + "2", it.next().getId());
        sync();
    }
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:25,代码来源:SearchServiceTest.java

示例13: testGetIndexesAsyncBuilder

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

    GetIndexesRequest.Builder builder = GetIndexesRequest.newBuilder()
            .setIndexNamePrefix(indexName);

    Future<GetResponse<Index>> response = searchService.getIndexesAsync(builder);
    List<Index> listIndexes = response.get().getResults();

    for (Index oneIndex : listIndexes) {
        Future<Results<ScoredDocument>> Fres = oneIndex.searchAsync("");

        Iterator<ScoredDocument> it = Fres.get().iterator();
        assertEquals(docId + "1", it.next().getId());
        assertEquals(docId + "2", it.next().getId());
        sync();
    }
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:22,代码来源:SearchServiceTest.java

示例14: testGetIndexesAsyncRequest

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

    GetIndexesRequest request = GetIndexesRequest.newBuilder()
            .setIndexNamePrefix(indexName)
            .build();

    Future<GetResponse<Index>> response = searchService.getIndexesAsync(request);
    List<Index> listIndexes = response.get().getResults();

    for (Index oneIndex : listIndexes) {
        Future<Results<ScoredDocument>> Fres = oneIndex.searchAsync("");

        Iterator<ScoredDocument> it = Fres.get().iterator();
        assertEquals(docId + "1", it.next().getId());
        assertEquals(docId + "2", it.next().getId());
        sync();
    }
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:23,代码来源:SearchServiceTest.java

示例15: testSearchAsyncString

import com.google.appengine.api.search.Results; //导入依赖的package包/类
@Test
public void testSearchAsyncString() throws ExecutionException, 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) {
        Future<Results<ScoredDocument>> rRes = oneIndex.searchAsync("");

        Iterator<ScoredDocument> it = rRes.get().iterator();
        assertEquals(docId + "1", it.next().getId());
        assertEquals(docId + "2", it.next().getId());
        sync();
    }
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:22,代码来源:SearchServiceTest.java


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