bz19823: Another fix for this one.

We need to keep a transaction open before we call calc_max_id and
calc_item_count().  Otherwise if the backend removes an item between
when we calculate them and when we select the item data, the item
data won't be there.
bz19897: changes for spliting search terms

The new algorithm is to just find alphanumeric chars and ignore the
rest.  This fixes the issue with the "-" character acting funny.