  Let $P$ be a set of $n$ points in $\R^d$. We present a linear-size data
structure for answering range queries on $P$ with constant-complexity
semialgebraic sets as ranges, in time close to $O(n^{1-1/d})$. It essentially
matches the performance of similar structures for simplex range searching, and,
for $d\ge 5$, significantly improves earlier solutions by the first two authors
obtained in~1994. This almost settles a long-standing open problem in range
searching.
  The data structure is based on the polynomial-partitioning technique of Guth
and Katz [arXiv:1011.4105], which shows that for a parameter $r$, $1 < r \le
n$, there exists a $d$-variate polynomial $f$ of degree $O(r^{1/d})$ such that
each connected component of $\R^d\setminus Z(f)$ contains at most $n/r$ points
of $P$, where $Z(f)$ is the zero set of $f$. We present an efficient randomized
algorithm for computing such a polynomial partition, which is of independent
interest and is likely to have additional applications.
