org.springframework.data.solr.core.query.result.HighlightPage Java Examples

The following examples show how to use org.springframework.data.solr.core.query.result.HighlightPage. 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: AdvancedSolrRepositoryTests.java    From spring-data-examples with Apache License 2.0 5 votes vote down vote up
/**
 * {@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", PageRequest.of(0, 10));

	products.getHighlighted().forEach(entry -> entry.getHighlights().forEach(highligh -> System.out
			.println(entry.getEntity().getId() + " | " + highligh.getField() + ":\t" + highligh.getSnipplets())));
}
 
Example #2
Source File: BookRepositoryTests.java    From Spring-data-solr-example with Apache License 2.0 5 votes vote down vote up
@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!"));
}
 
Example #3
Source File: BookRepositoryTests.java    From Spring-data-solr-example with Apache License 2.0 5 votes vote down vote up
private boolean containsSnipplet(HighlightPage<Book> booksHighlightPage, String snippletToCheck) {
	for (HighlightEntry<Book> he : booksHighlightPage.getHighlighted()) {
		// A HighlightEntry belongs to an Entity (Book) and may have multiple highlighted fields (description)
		for (Highlight highlight : he.getHighlights()) {
			for (String snipplet : highlight.getSnipplets()) {
				
				if (snipplet.equals(snippletToCheck)) {
					return true;
				}
			}
		}
	}
	return false;
}
 
Example #4
Source File: BookRepository.java    From Spring-data-solr-example with Apache License 2.0 4 votes vote down vote up
@Highlight(prefix = "<highlight>", postfix = "</highlight>")
HighlightPage<Book> findByDescription(String description, Pageable pageable);
 
Example #5
Source File: ProductRepository.java    From spring-data-solr-showcase with Apache License 2.0 4 votes vote down vote up
@Highlight(prefix = "<b>", postfix = "</b>")
@Query(fields = { SearchableProductDefinition.ID_FIELD_NAME, SearchableProductDefinition.NAME_FIELD_NAME,
		SearchableProductDefinition.PRICE_FIELD_NAME, SearchableProductDefinition.FEATURES_FIELD_NAME,
		SearchableProductDefinition.AVAILABLE_FIELD_NAME }, defaultOperator = Operator.AND)
HighlightPage<Product> findByNameIn(Collection<String> names, Pageable page);
 
Example #6
Source File: ProductRepository.java    From spring-data-examples with Apache License 2.0 2 votes vote down vote up
/**
 * Find documents with matching description, highlighting context within a 20 char range around the hit.
 *
 * @param description
 * @param page
 * @return
 */
@Highlight(fragsize = 20, snipplets = 3)
HighlightPage<Product> findByDescriptionStartingWith(String description, Pageable page);