Skip to content

Commit

Permalink
Added support for "sow" parameter (Split On Whitespace) (#586)
Browse files Browse the repository at this point in the history
Added support for "sow" parameter (Split On Whitespace) to select queries
  • Loading branch information
thomascorthals authored and Markus Kalkbrenner committed Apr 20, 2018
1 parent 55a25a9 commit 734e441
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,21 @@ Options

The options below can be set as query option values, but also by using the set/get methods. See the API docs for all available methods.

| Name | Type | Default value | Description |
|----------------------|------------------|-------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| handler | string | select | Name of the Solr request handler to use, without leading or trailing slashes |
| resultclass | string | Solarium\_Result\_Select | Classname for result. If you set a custom classname make sure the class is readily available (or through autoloading) |
| documentclass | string | Solarium\_Document\_ReadWrite | Classname for documents in the resultset. If you set a custom classname make sure the class is readily available (or through autoloading) |
| query | string | \*:\* | Query to execute |
| start | int | 0 | Start position (offset) in the complete Solr query resultset, to paginate big resultsets. |
| rows | integer | 10 | Number of rows to fetch, starting from the 'start' (offset) position. It's a limit, you might get less. |
| fields | string | - ,score | Comma separated list of fields to fetch from Solr. There are two special values: '\*' meaning 'all fields' and 'score' to also fetch the Solr document score value. |
| sort | array | empty array | Array with sort field as key and sort order as values. Multiple entries possible, they are used in the order of the array. Example: array('price' => 'asc') |
| querydefaultoperator | string | null | With a null value the default of your Solr config will be used. If you want to override this supply 'AND' or 'OR' as the value. |
| querydefaultfield | string | null | With a null value the default of your Solr config will be used. If you want to override this supply a field name as the value. |
| responsewriter | string | json | You can set this to 'phps' for improved response parsing performance, at the cost of a (possible) security risk. Only use 'phps' for trusted Solr instances. |
| tag | array of strings | null | You can supply one or multiple tags for the main query string, to allow for exclusion of the main query in facets |
| Name | Type | Default value | Description |
|----------------------|------------------|-------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| handler | string | select | Name of the Solr request handler to use, without leading or trailing slashes |
| resultclass | string | Solarium\_Result\_Select | Classname for result. If you set a custom classname make sure the class is readily available (or through autoloading) |
| documentclass | string | Solarium\_Document\_ReadWrite | Classname for documents in the resultset. If you set a custom classname make sure the class is readily available (or through autoloading) |
| query | string | \*:\* | Query to execute |
| start | int | 0 | Start position (offset) in the complete Solr query resultset, to paginate big resultsets. |
| rows | integer | 10 | Number of rows to fetch, starting from the 'start' (offset) position. It's a limit, you might get less. |
| fields | string | - ,score | Comma separated list of fields to fetch from Solr. There are two special values: '\*' meaning 'all fields' and 'score' to also fetch the Solr document score value. |
| sort | array | empty array | Array with sort field as key and sort order as values. Multiple entries possible, they are used in the order of the array. Example: array('price' => 'asc') |
| querydefaultoperator | string | null | With a null value the default of your Solr config will be used. If you want to override this supply 'AND' or 'OR' as the value. |
| querydefaultfield | string | null | With a null value the default of your Solr config will be used. If you want to override this supply a field name as the value. |
| responsewriter | string | json | You can set this to 'phps' for improved response parsing performance, at the cost of a (possible) security risk. Only use 'phps' for trusted Solr instances. |
| tag | array of strings | null | You can supply one or multiple tags for the main query string, to allow for exclusion of the main query in facets |
| splitonwhitespace | bool | null | Specifies whether the query parser splits the query text on whitespace before it's sent to be analyzed. Available for 'lucene' and 'edismax' query parsers since Solr 6.5. |
||

Examples
Expand Down
27 changes: 27 additions & 0 deletions src/QueryType/Select/Query/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,33 @@ public function clearCursormark()
return $this->setOption('cursormark', null);
}

/**
* Set SplitOnWhitespace option.
*
* Specifies whether the query parser splits the query text on whitespace before it's sent to be analyzed.
*
* The default is to split on whitespace, equivalent to &sow=true.
* The sow parameter was introduced in Solr 6.5.
*
* @param bool $splitOnWhitespace
*
* @return self Provides fluent interface
*/
public function setSplitOnWhitespace($splitOnWhitespace)
{
return $this->setOption('splitonwhitespace', $splitOnWhitespace);
}

/**
* Get SplitOnWhitespace option.
*
* @return bool|null
*/
public function getSplitOnWhitespace()
{
return $this->getOption('splitonwhitespace');
}

/**
* Initialize options.
*
Expand Down
1 change: 1 addition & 0 deletions src/QueryType/Select/RequestBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public function build(QueryInterface $query)
$request->addParam('q.op', $query->getQueryDefaultOperator());
$request->addParam('df', $query->getQueryDefaultField());
$request->addParam('cursorMark', $query->getCursormark());
$request->addParam('sow', $query->getSplitOnWhitespace());

// add sort fields to request
$sort = [];
Expand Down
6 changes: 6 additions & 0 deletions tests/QueryType/Select/Query/AbstractQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,12 @@ public function testSetTags()
$this->assertSame(['t3', 't4'], $this->query->getTags());
}

public function testSetAndGetSplitOnWhitespace()
{
$this->query->setSplitOnWhitespace(false);
$this->assertFalse($this->query->getSplitOnWhitespace());
}

public function testGetSpatial()
{
$spatial = $this->query->getSpatial();
Expand Down
8 changes: 8 additions & 0 deletions tests/QueryType/Select/RequestBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,14 @@ public function testWithTags()

$this->assertSame('{!tag=t1,t2}cat:1', $request->getParam('q'));
}

public function testWithSplitOnWhitespace()
{
$this->query->setSplitOnWhitespace(false);
$request = $this->builder->build($this->query);

$this->assertSame('false', $request->getParam('sow'));
}
}

class TestDummyComponent extends AbstractComponent
Expand Down

0 comments on commit 734e441

Please sign in to comment.