Query/Query.php
protected function buildResultQuery(EntityManager $em, Request $request, $page)
	{
		$searchWords = preg_split('/[^[:alnum:]]+/', $request->getSearchText());
		$offset = $request->getLimit() * ($page - 1);
		$limit = $request->getLimit();

		$selects = array();
		foreach($this->databaseMapping as $key => $tableMapping)
		{
			$tableMapping['columns'][$this->scorePos] = $this->buildScoreColumn($tableMapping['columns'], count($searchWords));
			//For constructor parameter order of searchitem
			ksort($tableMapping['columns']);
			$hitExpressions = $this->buildHitExpressions($tableMapping['columns']);
			$joinsExpressions = $this->buildJoinExpressions($tableMapping['joins']);


			$selects[] = 'SELECT * FROM (SELECT ' . implode($hitExpressions, ', ') . ' '
					. 'FROM ' . $tableMapping['table'] . ' ' . $tableMapping['tableAlias'] . ' '
					. implode(' ', $joinsExpressions) . ' '
					. 'ORDER BY c' . $this->scorePos . ' DESC '
					. 'LIMIT ' . ($offset + $limit) . ') AS DT' . $key . ' '
					. 'WHERE c' . $this->scorePos . '<>0 '
			;
		}

		$bigSelect = '' . implode($selects, ' UNION ') . ' '
				. 'ORDER BY c' . $this->scorePos . ' DESC '
				. 'LIMIT ' . $limit . ' '
				. 'OFFSET ' . $offset
		;

		$query = $em->createNativeQuery($bigSelect, $this->rsm);
		foreach($searchWords as $key => $searchWord)
		{
			$query->setParameter('p' . $key, $searchWord);
		}

		return $query;
	}
protected function buildResultQuery(EntityManager $em, Request $request, $page)
	{
		$searchWords = preg_split('/[^[:alnum:]]+/', $request->getSearchText());
		$offset = $request->getLimit() * ($page - 1);
		$limit = $request->getLimit();

		$selects = array();
		foreach($this->databaseMapping as $key => $tableMapping)
		{
			$tableMapping['columns'][$this->scorePos] = $this->buildScoreColumn($tableMapping['columns'], count($searchWords));
			//For constructor parameter order of searchitem
			ksort($tableMapping['columns']);
			$hitExpressions = $this->buildHitExpressions($tableMapping['columns']);
			$joinsExpressions = $this->buildJoinExpressions($tableMapping['joins']);


			$selects[] = 'SELECT * FROM (SELECT ' . implode($hitExpressions, ', ') . ' '
					. 'FROM ' . $tableMapping['table'] . ' ' . $tableMapping['tableAlias'] . ' '
					. implode(' ', $joinsExpressions) . ' '
					. 'ORDER BY c' . $this->scorePos . ' DESC '
					. 'LIMIT ' . ($offset + $limit) . ') AS DT' . $key . ' '
					. 'WHERE c' . $this->scorePos . '<>0 '
			;
		}

		$bigSelect = '' . implode($selects, ' UNION ') . ' '
				. 'ORDER BY c' . $this->scorePos . ' DESC '
				. 'LIMIT ' . $limit . ' '
				. 'OFFSET ' . $offset
		;

		$query = $em->createNativeQuery($bigSelect, $this->rsm);
		foreach($searchWords as $key => $searchWord)
		{
			$query->setParameter('p' . $key, $searchWord);
		}

		return $query;
	}
protected function buildResultQuery ( EntityManager $ em , Request $ request , $ page ) { $ searchWords = preg_split ( '/[^[:alnum:]]+/' , $ request -> getSearchText ( ) ) ; $ offset = $ request -> getLimit ( ) * ( $ page - 1 ) ; $ limit = $ request -> getLimit ( ) ; $ selects = array ( ) ; foreach ( $ this -> databaseMapping as $ key => $ tableMapping ) { $ tableMapping [ 'columns' ] [ $ this -> scorePos ] = $ this -> buildScoreColumn ( $ tableMapping [ 'columns' ] , count ( $ searchWords ) ) ; //For constructor parameter order of searchitem ksort ( $ tableMapping [ 'columns' ] ) ; $ hitExpressions = $ this -> buildHitExpressions ( $ tableMapping [ 'columns' ] ) ; $ joinsExpressions = $ this -> buildJoinExpressions ( $ tableMapping [ 'joins' ] ) ; $ selects [ ] = 'SELECT * FROM (SELECT ' . implode ( $ hitExpressions , ', ' ) . ' ' . 'FROM ' . $ tableMapping [ 'table' ] . ' ' . $ tableMapping [ 'tableAlias' ] . ' ' . implode ( ' ' , $ joinsExpressions ) . ' ' . 'ORDER BY c' . $ this -> scorePos . ' DESC ' . 'LIMIT ' . ( $ offset + $ limit ) . ') AS DT' . $ key . ' ' . 'WHERE c' . $ this -> scorePos . '<>0 ' ; } $ bigSelect = '' . implode ( $ selects , ' UNION ' ) . ' ' . 'ORDER BY c' . $ this -> scorePos . ' DESC ' . 'LIMIT ' . $ limit . ' ' . 'OFFSET ' . $ offset ; $ query = $ em -> createNativeQuery ( $ bigSelect , $ this -> rsm ) ; foreach ( $ searchWords as $ key => $ searchWord ) { $ query -> setParameter ( 'p' . $ key , $ searchWord ) ; } return $ query ; }
Build result query

@param EntityManager $em
@param Request $request
@param int $page
@return \Doctrine\ORM\NativeQuery
Build result query