diff --git a/lib/RoadizCoreBundle/src/SearchEngine/AbstractSearchHandler.php b/lib/RoadizCoreBundle/src/SearchEngine/AbstractSearchHandler.php index b81fa233..072c0a71 100644 --- a/lib/RoadizCoreBundle/src/SearchEngine/AbstractSearchHandler.php +++ b/lib/RoadizCoreBundle/src/SearchEngine/AbstractSearchHandler.php @@ -229,24 +229,14 @@ public function escapeQuery(string $input): string } /** - * Default Solr query builder. - * - * Extends this method to customize your Solr queries. Eg. to boost custom fields. - * * @param string $q - * @param array $args - * @param bool $searchTags * @param int $proximity - * @return string + * @return array [$exactQuery, $fuzzyQuery, $wildcardQuery] */ - protected function buildQuery(string $q, array &$args, bool $searchTags = false, int $proximity = 1): string + protected function getFormattedQuery(string $q, int $proximity = 1): array { $q = trim($q); $singleWord = $this->isQuerySingleWord($q); - $titleField = $this->getTitleField($args); - $collectionField = $this->getCollectionField($args); - $tagsField = $this->getTagsField($args); - /** * Generate a fuzzy query by appending proximity to each word * @see https://lucene.apache.org/solr/guide/6_6/the-standard-query-parser.html#TheStandardQueryParser-FuzzySearches @@ -272,6 +262,31 @@ protected function buildQuery(string $q, array &$args, bool $searchTags = false, */ $exactQuery = '"' . $exactQuery . '"'; } + /* + * Wildcard search for allowing autocomplete + */ + $wildcardQuery = $this->escapeQuery($q) . '*~' . $proximity; + + return [$exactQuery, $fuzzyiedQuery, $wildcardQuery]; + } + + /** + * Default Solr query builder. + * + * Extends this method to customize your Solr queries. Eg. to boost custom fields. + * + * @param string $q + * @param array $args + * @param bool $searchTags + * @param int $proximity + * @return string + */ + protected function buildQuery(string $q, array &$args, bool $searchTags = false, int $proximity = 1): string + { + $titleField = $this->getTitleField($args); + $collectionField = $this->getCollectionField($args); + $tagsField = $this->getTagsField($args); + [$exactQuery, $fuzzyiedQuery, $wildcardQuery] = $this->getFormattedQuery($q, $proximity); /* * Search in node-sources tags nameā€¦ @@ -279,9 +294,10 @@ protected function buildQuery(string $q, array &$args, bool $searchTags = false, if ($searchTags) { // Need to use Fuzzy search AND Exact search return sprintf( - '(' . $titleField . ':%s)^10 (' . $titleField . ':%s) (' . $collectionField . ':%s)^2 (' . $collectionField . ':%s) (' . $tagsField . ':%s) (' . $tagsField . ':%s)', + '(' . $titleField . ':%s)^10 (' . $titleField . ':%s) (' . $titleField . ':%s) (' . $collectionField . ':%s)^2 (' . $collectionField . ':%s) (' . $tagsField . ':%s) (' . $tagsField . ':%s)', $exactQuery, $fuzzyiedQuery, + $wildcardQuery, $exactQuery, $fuzzyiedQuery, $exactQuery, @@ -289,9 +305,10 @@ protected function buildQuery(string $q, array &$args, bool $searchTags = false, ); } else { return sprintf( - '(' . $titleField . ':%s)^10 (' . $titleField . ':%s) (' . $collectionField . ':%s)^2 (' . $collectionField . ':%s)', + '(' . $titleField . ':%s)^10 (' . $titleField . ':%s) (' . $titleField . ':%s) (' . $collectionField . ':%s)^2 (' . $collectionField . ':%s)', $exactQuery, $fuzzyiedQuery, + $wildcardQuery, $exactQuery, $fuzzyiedQuery ); diff --git a/lib/Rozier/src/AjaxControllers/AjaxNodesExplorerController.php b/lib/Rozier/src/AjaxControllers/AjaxNodesExplorerController.php index 2ca632f2..834fc240 100644 --- a/lib/Rozier/src/AjaxControllers/AjaxNodesExplorerController.php +++ b/lib/Rozier/src/AjaxControllers/AjaxNodesExplorerController.php @@ -5,6 +5,7 @@ namespace Themes\Rozier\AjaxControllers; use Doctrine\ORM\EntityManager; +use Doctrine\ORM\Exception\NotSupported; use JMS\Serializer\SerializationContext; use JMS\Serializer\SerializerInterface; use RZ\Roadiz\CoreBundle\Entity\Node; @@ -190,7 +191,7 @@ protected function getSolrSearchResults( $arrayFilter, $this->getItemPerPage(), true, - 10000000, + 2, (int) $currentPage ); $pageCount = ceil($results->getResultCount() / $this->getItemPerPage()); @@ -216,6 +217,7 @@ protected function getSolrSearchResults( * * @param Request $request * @return JsonResponse + * @throws NotSupported */ public function listAction(Request $request): JsonResponse {