rsolrsolrcloudsolr-query-syntaxropensci

Passing a variable in a solr auery


I'm working with solr using r library solrium

After the connection to solr in the variable conn1, I make queries like this:

solr_search(conn1,"collection_name", params = list(q = "price:1000",start = 0, rows = 20000,fl=c('column_name')))
But now, I want to perform a query using a variable:

p = 1000000
d = solr_search(conn1,"collection_name", params = list(q = "price:p", start = 0, rows = 20000,fl=c('column_name' )))

And obviously it doesn't work. I have tried tricks that I found on Internet like "price":p "price:${p}" "price":{p}

But none of these worked.


Solution

  • While I'm not familiar with R or Solrium, it seems like standard string concatenation is performed by using paste("price:", p). This assumes that p is not user supplied - i.e. you can assume that the value is safe to send directly to Solr.