0

Sorry for long prehistory. I have very common case (on my mind). Lets imaging that in my schema I have:

<field name="id" type="string" indexed="true" stored="true" required="true" multiValued="false" /> 
<field name="title" type="text_general" indexed="true" stored="true" multiValued="false"/>
<field name="description" type="text_general" indexed="true" stored="false" multiValued="false"/>
.....
<field name="search_field" type="text_general" indexed="true" stored="false" multiValued="true"/>

<copyField source="title" dest="search_field"/>
<copyField source="..." dest="search_field"/>
<copyField source="description" dest="search_field"/>

Generally I would like to make search on only in search_field field. But I didn't send this field to/from client from/to server.

I know how to made this with SolrJ, but currently I want to receive all benefits from using Spring Data Solr.

So I declarate class like :

public class Product {
  @Field private String id;

  @Field private String title;

  @Field private String description;
}

Simple Repository like :

public interface SolrRepository extends SolrCrudRepository<Product, String> {
    Page<Product> findByTitle(String title, Pageable page);
}

works quite well. BUT. I want to write method:

Page<Product> findBySearchField(String text, Pageable page);

But this doesn't work of course.

I think this should works:

@Query(value = "search_field:?0")
FacetPage<Product> findByPopularityFacetOnName(String text, Pageable page);

But, are there another options(and better options) to do this ?

sorry for my English, any corrections - welcome!

iMysak
  • 2,170
  • 1
  • 22
  • 35

1 Answers1

0

From my point of view that is the way to go. search_field is not mapped, but it exists, so the way to access it is by given a specific query to be executed.

Beside that, your method needs to be annotated as follow to have its result based on search_field search and facet on name:

@Facet(fields = "name")
@Query(value = "search_field:?0")
FacetPage<Product> findByPopularityFacetOnName(String text, Pageable page);
Francisco Spaeth
  • 23,493
  • 7
  • 67
  • 106