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


Java HighlightPage类代码示例

本文整理汇总了Java中org.springframework.data.solr.core.query.result.HighlightPage的典型用法代码示例。如果您正苦于以下问题:Java HighlightPage类的具体用法?Java HighlightPage怎么用?Java HighlightPage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: highlightPagesToList

import org.springframework.data.solr.core.query.result.HighlightPage; //导入依赖的package包/类
public static List<Product> highlightPagesToList(HighlightPage<Product> productPage) {

        List<Product> products = new ArrayList<Product>();
        for (HighlightEntry<Product> highlightedProduct : productPage.getHighlighted()) {

            Product product = new
                    Product(highlightedProduct.getEntity().getId(), highlightedProduct.getEntity().getName());
            products.add(product);

            for (HighlightEntry.Highlight highlight : highlightedProduct.getHighlights()) {
                for (String snippet : highlight.getSnipplets()) {
                    if (highlight.getField().getName().equals(IProduct.NAME_FIELD)) {
                        product.setName(snippet);
                    }
                }
            }
        }
        return products;
    }
 
开发者ID:mintster,项目名称:nixmash-blog,代码行数:20,代码来源:SolrUtils.java

示例2: testQueryWithHighlight

import org.springframework.data.solr.core.query.result.HighlightPage; //导入依赖的package包/类
@Test
public void testQueryWithHighlight() {
	HighlightPage<ProductBean> page = repo.findByNameHighlightAll("na", new PageRequest(0, 10));
	Assert.assertEquals(3, page.getNumberOfElements());

	for (ProductBean product : page) {
		List<Highlight> highlights = page.getHighlights(product);
		Assert.assertThat(highlights, IsNot.not(IsEmptyCollection.empty()));
		for (Highlight highlight : highlights) {
			Assert.assertEquals("name", highlight.getField().getName());
			Assert.assertThat(highlight.getSnipplets(), IsNot.not(IsEmptyCollection.empty()));
			for (String s : highlight.getSnipplets()) {
				Assert.assertTrue("expected to find <em>name</em> but was \"" + s + "\"", s.contains("<em>name</em>"));
			}
		}
	}
}
 
开发者ID:ramaava,项目名称:spring-data-solr,代码行数:18,代码来源:ITestSolrRepositoryOperations.java

示例3: testHighlightWithPrefixPostfix

import org.springframework.data.solr.core.query.result.HighlightPage; //导入依赖的package包/类
@Test
public void testHighlightWithPrefixPostfix() {
	HighlightPage<ProductBean> page = repo.findByNameHighlightAllWithPreAndPostfix("na", new PageRequest(0, 10));
	Assert.assertEquals(3, page.getNumberOfElements());

	for (ProductBean product : page) {
		List<Highlight> highlights = page.getHighlights(product);
		Assert.assertThat(highlights, IsNot.not(IsEmptyCollection.empty()));
		for (Highlight highlight : highlights) {
			Assert.assertEquals("name", highlight.getField().getName());
			Assert.assertThat(highlight.getSnipplets(), IsNot.not(IsEmptyCollection.empty()));
			for (String s : highlight.getSnipplets()) {
				Assert.assertTrue("expected to find <b>name</b> but was \"" + s + "\"", s.contains("<b>name</b>"));
			}
		}
	}
}
 
开发者ID:ramaava,项目名称:spring-data-solr,代码行数:18,代码来源:ITestSolrRepositoryOperations.java

示例4: testHighlightWithFields

import org.springframework.data.solr.core.query.result.HighlightPage; //导入依赖的package包/类
@Test
public void testHighlightWithFields() {
	ProductBean beanWithText = createProductBean("withName", 5, true);
	beanWithText.setDescription("some text with name in it");
	repo.save(beanWithText);

	HighlightPage<ProductBean> page = repo.findByNameHighlightAllLimitToFields("na", new PageRequest(0, 10));
	Assert.assertEquals(4, page.getNumberOfElements());

	for (ProductBean product : page) {
		List<Highlight> highlights = page.getHighlights(product);
		if (!product.getId().equals(beanWithText.getId())) {
			Assert.assertThat(highlights, IsEmptyCollection.empty());
		} else {
			Assert.assertThat(highlights, IsNot.not(IsEmptyCollection.empty()));
			for (Highlight highlight : highlights) {
				Assert.assertEquals("description", highlight.getField().getName());
				Assert.assertThat(highlight.getSnipplets(), IsNot.not(IsEmptyCollection.empty()));
				for (String s : highlight.getSnipplets()) {
					Assert.assertTrue("expected to find <em>name</em> but was \"" + s + "\"", s.contains("<em>name</em>"));
				}
			}
		}
	}
}
 
开发者ID:ramaava,项目名称:spring-data-solr,代码行数:26,代码来源:ITestSolrRepositoryOperations.java

示例5: testHighlightWithQueryOverride

import org.springframework.data.solr.core.query.result.HighlightPage; //导入依赖的package包/类
@Test
public void testHighlightWithQueryOverride() {
	ProductBean beanWithText = createProductBean("withName", 5, true);
	beanWithText.setDescription("some text with name in it");
	repo.save(beanWithText);

	HighlightPage<ProductBean> page = repo.findByNameHighlightWihtQueryOverride("na", "some", new PageRequest(0, 10));
	Assert.assertEquals(4, page.getNumberOfElements());

	for (ProductBean product : page) {
		List<Highlight> highlights = page.getHighlights(product);
		for (Highlight highlight : highlights) {
			Assert.assertEquals("description", highlight.getField().getName());
			for (String s : highlight.getSnipplets()) {
				Assert.assertTrue("expected to find <em>some</em> but was \"" + s + "\"", s.contains("<em>some</em>"));
			}
		}
	}
}
 
开发者ID:ramaava,项目名称:spring-data-solr,代码行数:20,代码来源:ITestSolrRepositoryOperations.java

示例6: testQueryWithHighlights

import org.springframework.data.solr.core.query.result.HighlightPage; //导入依赖的package包/类
@Test
public void testQueryWithHighlights() {
	ExampleSolrBean belkin = new ExampleSolrBean("GB18030TEST", "Test with some GB18030TEST", null);
	ExampleSolrBean apple = new ExampleSolrBean("UTF8TEST", "Test with some UTF8TEST", null);

	solrTemplate.saveBeans(Arrays.asList(belkin, apple));
	solrTemplate.commit();

	SimpleHighlightQuery query = new SimpleHighlightQuery(new SimpleStringCriteria("name:with"));
	query.setHighlightOptions(new HighlightOptions());

	HighlightPage<ExampleSolrBean> page = solrTemplate.queryForHighlightPage(query, ExampleSolrBean.class);
	Assert.assertEquals(2, page.getHighlighted().size());

	Assert.assertEquals("name", page.getHighlighted().get(0).getHighlights().get(0).getField().getName());
	Assert.assertEquals("Test <em>with</em> some GB18030TEST", page.getHighlighted().get(0).getHighlights().get(0)
			.getSnipplets().get(0));
}
 
开发者ID:ramaava,项目名称:spring-data-solr,代码行数:19,代码来源:ITestSolrTemplate.java

示例7: annotationBasedHighlighting

import org.springframework.data.solr.core.query.result.HighlightPage; //导入依赖的package包/类
/**
 * {@link HighlightPage} holds next to the entities found also information about where a match was found within the
 * document. This allows to fine grained display snipplets of data containing the matching term in context.
 */
@Test
public void annotationBasedHighlighting() {

	HighlightPage<Product> products = repository.findByDescriptionStartingWith("play", new PageRequest(0, 10));

	products.getHighlighted().forEach(entry -> entry.getHighlights().forEach(highligh -> System.out
			.println(entry.getEntity().getId() + " | " + highligh.getField() + ":\t" + highligh.getSnipplets())));
}
 
开发者ID:Just-Fun,项目名称:spring-data-examples,代码行数:13,代码来源:AdvancedSolrRepositoryTests.java

示例8: processFindForm

import org.springframework.data.solr.core.query.result.HighlightPage; //导入依赖的package包/类
@RequestMapping(value = "/products/list", method = RequestMethod.GET)
public String processFindForm(UserQuery userQuery, BindingResult result, Model model, HttpServletRequest request) {
	List<Product> results = null;

	Boolean isSimpleTermQuery = userQuery.getQuery().matches("[a-zA-Z_0-9 ]*");

	if (StringUtils.isEmpty(userQuery.getQuery())) {
		return "redirect:/products/search";
	} else
		try {
			if (isSimpleTermQuery) {
				HighlightPage<Product> highlightedResults = productService
						.findByHighlightedNameCriteria(userQuery.getQuery());
				results = SolrUtils.highlightPagesToList(highlightedResults);
			} else {
				results = productService.getProductsWithUserQuery(userQuery.getQuery());
			}
		} catch (UncategorizedSolrException ex) {
			logger.info(MessageFormat.format("Bad Query: {0}", userQuery.getQuery()));
			result.rejectValue("query", "product.search.error", new Object[] { userQuery.getQuery() }, "not found");
			return PRODUCT_SEARCH_VIEW;
		}

	if (results.size() < 1) {
		result.rejectValue("query", "product.search.noresults", new Object[] { userQuery.getQuery() }, "not found");
		return PRODUCT_SEARCH_VIEW;
	}

	if (results.size() > 1) {
		PagedListHolder<Product> pagedListHolder = new PagedListHolder<Product>(results);
		pagedListHolder.setPageSize(PRODUCT_LIST_PAGE_SIZE);
		request.getSession().setAttribute(SESSION_ATTRIBUTE_PRODUCTLIST, pagedListHolder);
		return "redirect:/products/page/1";
	} else {
		Product product = results.iterator().next();
		return "redirect:/products/" + product.getId();
	}
}
 
开发者ID:mintster,项目名称:nixmash-blog,代码行数:39,代码来源:SolrController.java

示例9: processHighlights

import org.springframework.data.solr.core.query.result.HighlightPage; //导入依赖的package包/类
public static HighlightPage<Product> processHighlights(HighlightPage<Product> productPage) {
    int i = 0;
    for (HighlightEntry<Product> product : productPage.getHighlighted()) {
        for (HighlightEntry.Highlight highlight : product.getHighlights()) {
            for (String snippet : highlight.getSnipplets()) {
                if (highlight.getField().getName().equals(IProduct.NAME_FIELD)) {
                    productPage.getContent().get(i).setName(snippet);
                }
            }
        }
        i++;
    }
    return productPage;
}
 
开发者ID:mintster,项目名称:nixmash-blog,代码行数:15,代码来源:SolrUtils.java

示例10: searchProductsWithHighlights

import org.springframework.data.solr.core.query.result.HighlightPage; //导入依赖的package包/类
@Override
public HighlightPage<Product> searchProductsWithHighlights(String searchTerm) {
	SimpleHighlightQuery query = new SimpleHighlightQuery();
	String[] words = searchTerm.split(" ");
	Criteria conditions = createHighlightedNameConditions(words);
	query.addCriteria(conditions);

	HighlightOptions hlOptions = new HighlightOptions();
	hlOptions.addField("name");
	hlOptions.setSimplePrefix("<b>");
	hlOptions.setSimplePostfix("</b>");
	query.setHighlightOptions(hlOptions);

	return solrTemplate.queryForHighlightPage(query, Product.class);
}
 
开发者ID:mintster,项目名称:nixmash-blog,代码行数:16,代码来源:CustomProductRepositoryImpl.java

示例11: highlightedResultsShouldContainTermsInBold

import org.springframework.data.solr.core.query.result.HighlightPage; //导入依赖的package包/类
@Test
public void highlightedResultsShouldContainTermsInBold() {
	List<Product> baseList = SolrTestUtils.createProductList(10);
	repo.save(baseList);

	HighlightPage<Product> highlightProductPage = 
			productService.findByHighlightedName("product", new PageRequest(0, 20));
	assertTrue(containsSnipplet(highlightProductPage, "<b>product</b>"));
}
 
开发者ID:mintster,项目名称:nixmash-blog,代码行数:10,代码来源:SolrProductTests.java

示例12: containsSnipplet

import org.springframework.data.solr.core.query.result.HighlightPage; //导入依赖的package包/类
private boolean containsSnipplet(HighlightPage<Product> productsHighlightPage, 
		String snippletToCheck) {
	for (HighlightEntry<Product> he : productsHighlightPage.getHighlighted()) {
		for (Highlight highlight : he.getHighlights()) {
			for (String snipplet : highlight.getSnipplets()) {
				if (snipplet.contains(snippletToCheck)) {
					return true;
				}
			}
		}
	}
	return false;
}
 
开发者ID:mintster,项目名称:nixmash-blog,代码行数:14,代码来源:SolrProductTests.java

示例13: home

import org.springframework.data.solr.core.query.result.HighlightPage; //导入依赖的package包/类
@RequestMapping("${lookupURL}")
    @ResponseBody
    List<Match> home(
            @RequestParam(value="query", required=false, defaultValue="solr") String query
    ){

        List<Match> results = new LinkedList<>();

        //remove any characters that are not alphanumerics, spaces, underscores, dollars, or fullstops
        query = query.replaceAll("[^a-zA-Z0-9 _$.]", " ");
        query = query.replaceAll(" +", " "); //replace multiple spaces with one
        if (query.length()<1) {
            return null;
        }

        HighlightPage<Match> searchResults = matchRepository.find(query, new PageRequest(0, 10));
        Map<String, String> overrides = new TreeMap<>();
        for (HighlightEntry<Match> hightlightEntity : searchResults.getHighlighted()) {
            Match match = hightlightEntity.getEntity();
            overrides.clear();
            hightlightEntity.getHighlights().forEach(hl -> overrides.put(hl.getField().getName(), hl.getSnipplets().get(0))); //ignore multiple snippets for now
            match.createHTMLDescription(overrides);
//            match.lockTheURL("http://localhost:8983/javadoc");
//            match.lockTheURL("/javadoc");
            match.lockTheURL(baseURL);
            results.add(match);
        }

        return results;
    }
 
开发者ID:arafalov,项目名称:Solr-Javadoc,代码行数:31,代码来源:AutoCompleteServer.java

示例14: queryForHighlightPage

import org.springframework.data.solr.core.query.result.HighlightPage; //导入依赖的package包/类
@Override
public <T> HighlightPage<T> queryForHighlightPage(HighlightQuery query, Class<T> clazz) {
	Assert.notNull(query, "Query must not be 'null'.");
	Assert.notNull(clazz, "Target class must not be 'null'.");

	QueryResponse response = query(query);

	List<T> beans = convertQueryResponseToBeans(response, clazz);
	SolrDocumentList results = response.getResults();
	SolrResultPage<T> page = new SolrResultPage<T>(beans, query.getPageRequest(), results.getNumFound(),
			results.getMaxScore());
	ResultHelper.convertAndAddHighlightQueryResponseToResultPage(response, page);

	return page;
}
 
开发者ID:ramaava,项目名称:spring-data-solr,代码行数:16,代码来源:SolrTemplate.java

示例15: findByDescription

import org.springframework.data.solr.core.query.result.HighlightPage; //导入依赖的package包/类
@Test
public void findByDescription() {
	HighlightPage<Book> booksHighlightPage = bookRepository.findByDescription("cookies", new PageRequest(0, 10));
	booksHighlightPage.getContent();
	assertTrue(containsSnipplet(booksHighlightPage, "How to handle <highlight>cookies</highlight> in web applications"));
	assertTrue(containsSnipplet(booksHighlightPage, "Bake your own <highlight>cookies</highlight>, on a secret island!"));
}
 
开发者ID:mscharhag,项目名称:Spring-data-solr-example,代码行数:8,代码来源:BookRepositoryTests.java


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