0

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.

sckott
  • 5,755
  • 2
  • 26
  • 42
Khalid Askia
  • 33
  • 1
  • 8
  • While I'm not familiar with R or Solrium, it seems like [standard string concatenation](https://stackoverflow.com/questions/7201341/how-can-two-strings-be-concatenated) 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. – MatsLindh Jul 28 '18 at 21:23
  • Oh wow it worked! Thank you 1 – Khalid Askia Jul 28 '18 at 21:38

1 Answers1

0

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.

MatsLindh
  • 49,529
  • 4
  • 53
  • 84