分面搜索/分层导航、结果过滤

Faceted search / Layered navigation, result filtering

我正在使用 SOLR 获取我的方面,一切正常,甚至过滤器查询都是正确的。

我正在努力处理过滤器显示的 php 部分。

带有活动滤镜的切面看起来像这样。但是我想实现这些链接...

Manufacturers
-------------
[] BMW (/page?q=cars&manufacturer=Audi&manufacturer=Mercedes&manufacturer=BMW&model=BMW - X5&model=Mercedes - C)
[x] Audi (/page?q=cars&manufacturer=Mercedes&model=BMW - X5&model=Mercedes - C)
[x] Mercedes(/page?q=cars&manufacturer=Audi&manufacturer=Mercedes&model=BMW - X5&model=Mercedes - C)
[] Seat(/page?q=cars&manufacturer=Audi&manufacturer=Mercedes&manufacturer=Seat&model=BMW - X5&model=Mercedes - C)
[] Skoda (/page?q=cars&manufacturer=Audi&manufacturer=Mercedes&manufacturer=Skoda&model=BMW - X5&model=Mercedes - C)    

Model
-------------
[] BMW - E49 (/page?q=cars&manufacturer=Audi&manufacturer=Mercedes&model=BMW - X5&model=Mercedes - Cmodel=BMW - E49)
[] BMW - X3 (/page?q=cars&manufacturer=Audi&manufacturer=Mercedes&model=BMW - X5&model=Mercedes - C&model=BMW - X3)
[x] BMW - X5 (/page?q=cars&manufacturer=Audi&manufacturer=Mercedes&model=Mercedes - C)
[] Mercedes - A (/page?q=cars&manufacturer=Audi&manufacturer=Mercedes&model=Mercedes - C&model=BMW - X5&model=Mercedes - A)
[] Mercedes - B (/page?q=cars&manufacturer=Audi&manufacturer=Mercedes&model=Mercedes - C&model=BMW - X5&model=Mercedes - B)
[x] Mercedes - C (/page?q=cars&manufacturer=Audi&manufacturer=Mercedes&model=BMW - X5)
[] Mercedes - E (/page?q=cars&manufacturer=Audi&manufacturer=Mercedes&model=Mercedes - C&model=BMW - X5&model=Mercedes - E)
[] Mercedes - S (/page?q=cars&manufacturer=Audi&manufacturer=Mercedes&model=Mercedes - C&model=BMW - X5&model=Mercedes - S)

我很难获得当前的活动选择,当我单击已选择的项目时,将其从 url 字符串中删除。

我用来获取查询字符串的函数。

function getFilter() {
    $query  = explode('&', $_SERVER['QUERY_STRING']);
    $params = array();

    foreach( $query as $param) {
      list($name, $value) = explode('=', $param);
      $params[urldecode($name)][] = urldecode($value);
    }

    return $params;
}

上面的函数给了我这样的东西:

(
    [q] => Array
        (
            [0] => cars
        )

    [manufacturer] => Array
        (
            [0] => Audi
            [1] => Mercedes
        )

    [model] => Array
        (
            [0] => BMW - X5
            [1] => Mercedes - C
        )

)

之后,我将尝试获取所选项目并在 facet 循环中的值等于一个方面时将其删除,但我无法绕过它。

foreach($newFacetArray as $val => $count) {
    if(strlen($val) != 0) {
        if(isset($activeFilters[$value])) {
            if(in_array($val,$activeFilters[$value])) {
                foreach($activeFilters[$value] as $af) {
                    if($af == $val) {
                        $as = array_search($val,$activeFilters[$value]);
                        unset($activeFilters[$value][$as]);
                    } else {
                        if($af != $val) {
                            $activeFilters[$value][] = $val;
                        }
                    }
                }
            }
        }

        $url = http_build_query($activeFilters);
        #$url = $_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING'].'&'.(($value == 'manufacturerName')?$value.'[]':$value).'='.$val;

        echo '<li class="list-group-item"><a class="attribute-loader" href="'.$url.'"><input type="checkbox" name="'.$value.'" '.$facetSearch->verifyIfChecked($_GET,$val).'/> ' . $val . ' <span class="pull-right">'.$count.'</span></a></li>';
    }
}

解决了,有点困难,但我已经设法让它适用于任何动态方面。