addTag('node_access') ->fields('n', array('nid', 'title')) ->fields('p', array('model', 'unique_hash')) ->condition('p.unique_hash', '', '<>') ->condition(db_or() ->condition('n.title', $string . '%', 'LIKE') ->condition('p.model', $string . '%', 'LIKE')) ->range(0, 10); $n = $query->leftJoin('node', 'n', 'n.nid = p.nid'); $result = $query->execute(); foreach ($result as $node) { $matches[$node->nid] = t('@title [@sku]', array('@title' => $node->title, '@sku' => $node->model)); } } drupal_json_output($matches); }