Fixing Shards in eZ Find

I am way overdue on my promise to show you how to make shards work. As I said before, shards in eZ Find do not work out of the box. In the code the $shardQuery is built properly but the variable is never actually used after it is created. What I did to make this work is a simple if/else block inside the $queryHandler switch. I am not submitting this as a pull request to eZ Find at the moment just because I do not like the way I made this work, I feel like there is a better way to do it. Nevertheless here is my code to make Shards work, I hope you enjoy and moreover I hope you suggest a better way to make the code work ;)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php

\\ezfezpsolrquerybuilder.php

switch ( $queryHandler )
{
    case 'standard':
        // @todo: this is more complicated
        // build the query against all "text" like fields
        // should take into account all the filter fields and class filters to shorten the query
        // need to build: Solr q
        if ( array_key_exists( 'fields', $boostFunctions ) )
        {
            if (false != $shardQuery) {
            $handlerParameters = array ( 'q' => $this->buildMultiFieldQuery( $searchText, array_merge( $queryFields, $extraFieldsToSearch ), $boostFunctions['fields'] ),
                                     'qt' => 'standard',
                                     'shards' => $shardQuery);
            }
            else {
            $handlerParameters = array ( 'q' => $this->buildMultiFieldQuery( $searchText, array_merge( $queryFields, $extraFieldsToSearch ), $boostFunctions['fields'] ),
                                     'qt' => 'standard', );
            }

        }
        else
        {
            if (false != $shardQuery) {
            $handlerParameters = array ( 'q' => $this->buildMultiFieldQuery( $searchText, array_merge( $queryFields, $extraFieldsToSearch ) ),
                                     'qt' => 'standard',
                                     'shards' => $shardQuery);
            }
            else{
                $handlerParameters = array ( 'q' => $this->buildMultiFieldQuery( $searchText, array_merge( $queryFields, $extraFieldsToSearch ) ),
                                     'qt' => 'standard' );
            }
        }
        break;

    case 'simplestandard':
        // not to do much, searching is against the default aggregated field
        // only highlightfields
        $highLightFields = array ( 'ezf_df_text' );
        $handlerParameters = array ( 'q' => $searchText,
                                     'qt' => 'standard',
                                     'hl.usePhraseHighlighter' => 'true',
                                     'hl.highlightMultiTerm' => 'true' );
        break;
    case 'ezpublish':
        // the dismax based handler, just keywordss input, most useful for ordinary queries by users
        // need to build: Solr q, qf, dismax specific parameters

    default:
        // ezpublish of course, this to not break BC and is the most "general"
        // if another value is specified, it is supposed to be a dismax like handler
        // with possible other tuning variables then the stock provided 'ezpublish' in solrconfi.xml
        // remark it should be lowercase in solrconfig.xml!
        if (false != $shardQuery) {
            $handlerParameters = array ( 'q' => $searchText,
                                         'qf' => implode( ' ', array_merge( $queryFields, $extraFieldsToSearch ) ),
                                         'qt' => $queryHandler,
                                         'shards' => $shardQuery );
        } else {
            $handlerParameters = array ( 'q' => $searchText,
                                         'qf' => implode( ' ', array_merge( $queryFields, $extraFieldsToSearch ) ),
                                         'qt' => $queryHandler );

        }

}

Related Articles