I want to write a function tensorReplace[input] that takes a tensor polynomial in $r_i$ such as $r_i r_j r_k+r_i q_j q_k +q_i q_j q_k$ , and replaces each monomial with a function f[{idx}] using the rule $r_i\rightarrow f(\{i\})$, $r_i r_j\rightarrow f(\{i,j\})$, etc. leaving the $q$'s and another other symbols untouched.
So for in the example above, if my input is $$r_i r_j r_k+r_i q_j q_k +q_i q_j q_k\,,$$ I am shooting for an output
$$f(\{i,j,k\})+f(\{i\})q_i q_j+q_i q_j q_k\,.$$
I also need to allow the possibility where a vector with same index is squared (repeated in a monomial) given the obvious $r_i^2\rightarrow f(\{i,i\})$.
I don't know how to even begin, because my input could be an arbitrarily high order polynomial in $r$, with many terms.
