You are viewing a plain text version of this content. The canonical link for it is here.
Posted to zeta-dev@incubator.apache.org by Piotrek Karas <p....@mediaself.pl> on 2010/07/09 05:09:52 UTC

[zeta-dev] Search component and fecets

Hello guys,

First off all, where should we discuss problems with the components? 
Should that be sent to zeta-users or zeta-dev? Does anyone read zeta-users?

Now down to the case. I'm trying to build a search interface with an 
ezcSearch engine using solr handler. It seems to work fine, but I've got 
some problems with facets. As long as I add any one facet field to my 
find query, it seems to work fine, the search result has the facet 
information in place and calculated correctly. As soon as I add any 
combination of two or more fields, the facet information in the search 
result disappears (empty array). Now, I've tested every field from the 
combination separately, each time they produce correct faceting 
information individually.

Now, maybe there's something I don't understand about how to apply 
faceting information. Unfortunately, there's very little on this subject 
in the doc:
http://ezcomponents.org/docs/tutorials/Search
# // add a facet on url (not very useful)
# $q->facet( 'url' );

Has anyone succeeded in using the search component for multi-facet 
search? If so, will you be willing to share any examples? Or maybe you 
know what I could be doing wrong here?

Thanks in advance,
Cheers,
Piotrek

Re: [zeta-dev] Search component and fecets

Posted by Piotrek Karas <p....@mediaself.pl>.
W dniu 2010-07-09 11:26, Piotrek Karas pisze:
> echo '<textarea style="width:1200px; height:100px;">' . $queryPart .
> '</textarea>';

Of course this line doesn't have to be here... ;)

Cheers,
Piotrek

Re: [zeta-dev] Search component and fecets

Posted by Piotrek Karas <p....@mediaself.pl>.
W dniu 2010-07-09 07:09, Piotrek Karas pisze:
> Hello guys,
>
> First off all, where should we discuss problems with the components?
> Should that be sent to zeta-users or zeta-dev? Does anyone read zeta-users?
>
> Now down to the case. I'm trying to build a search interface with an
> ezcSearch engine using solr handler. It seems to work fine, but I've got
> some problems with facets. As long as I add any one facet field to my
> find query, it seems to work fine, the search result has the facet
> information in place and calculated correctly. As soon as I add any
> combination of two or more fields, the facet information in the search
> result disappears (empty array). Now, I've tested every field from the
> combination separately, each time they produce correct faceting
> information individually.
>
> Now, maybe there's something I don't understand about how to apply
> faceting information. Unfortunately, there's very little on this subject
> in the doc:
> http://ezcomponents.org/docs/tutorials/Search
> # // add a facet on url (not very useful)
> # $q->facet( 'url' );
>
> Has anyone succeeded in using the search component for multi-facet
> search? If so, will you be willing to share any examples? Or maybe you
> know what I could be doing wrong here?
>
> Thanks in advance,
> Cheers,
> Piotrek
>

OK, I think I've solved the problem, seems like a bug or maybe version 
compliance with older versions of solr, don't know.

When applying multiple facets, ezc solr handler builds the facet query 
part like this:
&facet.field=field1+field2+...

However, solr doesn't seem to expect or understand that, but it accepts 
something like this:
&facet.field=field1&facet.field=field2&...

This syntax is impossible to achieve with eZC solr handler since it uses 
http_build_query function which takes an associative array of params and 
so it is impossible to pass two variables sharing the same key.

Therefore the way I used to fix this was to create a post-query-build 
fix (around line 160 in ezcSearchSolrHandler):

...
...
...
public static function fixQueryStringFacetField( &$queryString )
{
$matches = array();
preg_match( '/\&facet.field=([^&]*)\&/', $queryString, $matches );
if ( isset( $matches[1] ) )
{
	$facetFields = explode( '+', $matches[1] );
	$facetFieldsString = '&facet.field=' . implode( '&facet.field=', 
$facetFields ) . '&';
	$queryString = preg_replace( '/\&facet.field=[^&]*\&/', 
$facetFieldsString, $queryString );
}
}

/**
* Sends the raw command $type to Solr
*
* @param string $type
* @param array(string=>string) $queryString
* @return string
* @access private
*/
public function sendRawGetCommand( $type, $queryString = array() )
{
$statusCode = 0;
$queryPart = '';
if ( count( $queryString ) )
{
     $queryPart = '/?'. http_build_query( $queryString );
}
self::fixQueryStringFacetField( $queryPart ); // <---- NEW LINE HERE
echo '<textarea style="width:1200px; height:100px;">' . $queryPart . 
'</textarea>';
$cmd =  "GET {$this->location}/{$type}{$queryPart} HTTP/1.1\n";
$cmd .= "Host: {$this->host}:{$this->port}\n";
$cmd .= "User-Agent: eZ Components Search\n";
$cmd .= "Content-Type: text/xml; charset=utf-8\n";
$cmd .= "\n";
...
...
...

I would have submitted this as a bug, but didn't know which was the 
proper place to do so now.

Cheers,
Piotrek.