Solr query with a list?

Viewed 332

How can a list be entered into a solr query?

I'm trying to perform a solr query which matches a list.

For example, I have a data structure similar to the one below where someList is a list which may contain any number of string items.

{
 someKey:someValue,
 someList: [
  "item1",
  "item2"
 ]
}

I want to return all records with specific values in someList. So if my query is q=someKey:* AND someList:items, I should receive only those records whose list someList matches the list, items, in my query.

I attempted something similar to the below method, but the query behaves as if "*" is being passed to someList in the query annotation. That, the query is being generated incorrectly as q=someKey:someValue AND someList:* rather than as q=someKey:someValue AND someList:items.

@Query("someKey:?0* AND someList:?1*")
public Page<Results> queryMethod(
        String someValue,
        List<String> items,
        Pageable pageable);

This method is in an interface which extends the SolrCrudRepository.

How can a list be entered into a solr query?

1 Answers

Instead of passing the List<String> items just pass Space seperated values as:

someList:(item1 item2)

Change your method :

@Query("someKey:?0* AND someList:?1*")
public Page<Results> queryMethod(
        String someValue,
        String items, <<<----
        Pageable pageable);

For detailed info for querying in SOLR you can refer here

Related