Skip to content

Commit

Permalink
Merge pull request #180 from peterkeung/autocomplete-filters
Browse files Browse the repository at this point in the history
Fix EZP-23617: Add subtree and class filters on eZ Find autocomplete
  • Loading branch information
yannickroger committed Jan 13, 2015
2 parents f30cd2e + 436e169 commit 305823f
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
37 changes: 37 additions & 0 deletions classes/ezfindservercallfunctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,43 @@ public static function autocomplete( $args )
$params['fq'] = 'meta_language_code_ms:(' . implode( ' OR ', $validLanguages ) . ')';
}

//build the query part for the subtree limitation
if ( isset( $args[2] ) && (int)$args[2] )
{
if ( isset( $params['fq'] ) && $params['fq'] )
{
$params['fq'] .= ' AND ';
}
$params['fq'] .= eZSolr::getMetaFieldName( 'path' ) . ':' . (int)$args[2];
}

//build the query part for the class limitation
if ( isset( $args[3] ) && $args[3] )
{
if ( isset( $params['fq'] ) && $params['fq'] )
{
$params['fq'] .= ' AND ';
}
$classes = explode( ',', $args[3] );
$classQueryParts = array();
foreach( $classes as $class )
{
if ( is_string( $class ) )
{
if ( $class = eZContentClass::fetchByIdentifier( $class ) )
{
$classQueryParts[] = eZSolr::getMetaFieldName( 'contentclass_id' ) . ':' . $class->attribute( 'id' );
}
}
else
{
$classQueryParts[] = eZSolr::getMetaFieldName( 'contentclass_id' ) . ':' . $class;
}
}
$classQueryParts = implode( ' OR ', $classQueryParts );
$params['fq'] .= '(' . $classQueryParts . ')';
}

$solrBase = new eZSolrBase( $fullSolrURI );
$result = $solrBase->rawSolrRequest( '/select', $params, 'json' );

Expand Down
13 changes: 12 additions & 1 deletion design/standard/javascript/ezajax_autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ YUI.add('ezfindautocomplete', function (Y) {
source: conf.url
});

// Build Ajax request URL string, passed to AutoComplete as the requestTemplate
var urlString = "::{query}::" + conf.resultLimit + "::";
if( typeof conf.subtree !== 'undefined' ) {
urlString += conf.subtree;
}
urlString += "::";
if( typeof conf.classes !== 'undefined' ) {
urlString += conf.classes;
}
urlString += "?ContentType=json";

Y.one(conf.inputSelector).plug(Y.Plugin.AutoComplete, {
maxResults: conf.resultLimit,
minQueryLength: conf.minQueryLength,
Expand All @@ -29,7 +40,7 @@ YUI.add('ezfindautocomplete', function (Y) {
},
source: ds,
// This will be appended to the URL that was supplied to the DataSource's "source" config above.
requestTemplate: "::{query}::" + conf.resultLimit + "?ContentType=json",
requestTemplate: urlString,
// Custom result list locator to parse the results out of the response.
resultListLocator: function (response) {
if (response && response[0] && response[0].responseText){
Expand Down

0 comments on commit 305823f

Please sign in to comment.