Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a weighted search #122

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
be3ee4f
#37 Adds a test that searches Solr using the eDisMax query parser (WIP)
extracts Nov 16, 2023
214c501
#37 Fix "call to undefined method" error
extracts Nov 16, 2023
0f387b9
#37 Keep Solr-specific terminology & syntax out of Opus\Search\Query
extracts Nov 17, 2023
105ca56
#37 Completes search test which verifies that a weighted Solr search …
extracts Nov 17, 2023
b0b22a4
#37 Default values for getters that return a boolean value must be tr…
extracts Nov 22, 2023
b290e62
#37 The weighted search test now shows that searching with boosted fi…
extracts Nov 22, 2023
abe0045
#37 Adopt tests to Opus\Search\Query->getUnion() returning either tru…
extracts Nov 22, 2023
527e42c
#37 The weighted search test now also verifies that swapping field we…
extracts Nov 23, 2023
541bc43
#37 Default to the "search.weightedSearch" & "search.simple" configur…
extracts Nov 23, 2023
c78afc7
#37 Now checks the sort order of weighted search results; moves testi…
extracts Nov 23, 2023
66c06a1
#37 Reuse test documents between weighted search tests
extracts Nov 23, 2023
c622821
#37 Fixes a namespace conflict
extracts Nov 23, 2023
42b9eb0
#37 Verify the sort order of weighted search results via the document…
extracts Nov 24, 2023
f6d7469
#37 Implements explicit getters getWeightedSearch() & getWeightedFiel…
extracts Nov 24, 2023
ad067cb
#37 Removes the weightedsearch key from the initial data array so tha…
extracts Nov 29, 2023
e0593c0
#37 Fix missing return statement in setWeightedSearch() which uses a …
extracts Nov 29, 2023
357b053
#37 Adds a weight multiplier to generate a value for the Solr "pf" re…
extracts Dec 1, 2023
54d1760
#37 Adds a test that compares the search behaviour of the standard & …
extracts Dec 1, 2023
a47e997
#37 Fix coding style
extracts Dec 1, 2023
efbba3b
#37 Replaces redundant boiler plate code with separate helper methods
extracts Dec 1, 2023
e635d6f
#37 More (and more granular) tests that test weighted search behavior
extracts Dec 1, 2023
0d51ed8
#37 Removes the catchall fields "text" & "simple" from the Solr schem…
extracts Dec 3, 2023
4577fcf
#37 When searching Solr, matches with a score of 0 are now ignored by…
extracts Dec 4, 2023
9e165b1
#37 Adopts a test that searches the author field so that it uses a we…
extracts Dec 4, 2023
8a08dff
Merge branch '4.8.1' into weightedSearch37
j3nsch May 17, 2024
6066e6a
Merge pull request #130 from OPUS4/weightedSearch37tmp
j3nsch May 17, 2024
cf8cb36
#131 Added test for advanced search
j3nsch May 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 41 additions & 16 deletions src/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@
* @method string[] getFields( array $default = null )
* @method array getSort( array $default = null )
* @method bool getUnion( bool $default = false )
* @method bool getWeightedSearch( bool $default = false )
* @method array getWeightedFields( int[] $default = null )
* @method AbstractFilterBase getFilter(AbstractFilterBase $default = null ) retrieves condition to be met by resulting documents
* @method Set getFacet( Set $default = null )
* @method $this setStart( int $offset )
Expand Down Expand Up @@ -110,7 +108,7 @@ public function reset()
'filter' => null,
'facet' => null,
'subfilters' => null,
'weightedsearch' => null,
'weightedsearch' => null, // first getWeightedSearch() call will set this to true or false
extracts marked this conversation as resolved.
Show resolved Hide resolved
'weightedfields' => null,
];
}
Expand Down Expand Up @@ -193,6 +191,46 @@ protected function normalizeDirection($ascending)
return $ascending;
}

/**
* Returns true if a weighted search shall be used, otherwise returns false.
*
* @return bool
*/
public function getWeightedSearch()
{
if ($this->data['weightedsearch'] === null) {
$config = Config::get();

if (isset($config->search->weightedSearch)) {
$this->data['weightedsearch'] = boolval($config->search->weightedSearch);
} else {
$this->data['weightedsearch'] = false;
}
}

return $this->data['weightedsearch'];
}

/**
* Returns boost factors keyed by field (e.g. [ 'title' => 10, 'abstract' => 0.5 ]).
*
* @return int[]
*/
public function getWeightedFields()
{
if ($this->data['weightedfields'] === null) {
$config = Config::get();

if (isset($config->search->simple)) {
$this->data['weightedfields'] = $config->search->simple->toArray();
} else {
$this->data['weightedfields'] = [];
}
}

return $this->data['weightedfields'];
}

/**
* Retrieves value of selected query parameter.
*
Expand All @@ -204,19 +242,6 @@ public function get($name, $defaultValue = null)
{
$name = $this->isValidParameter($name);

$config = Config::get();

// prefer config options over getter defaults
switch ($name) {
case 'weightedsearch':
$defaultValue = isset($config->search->weightedSearch) ? boolval($config->search->weightedSearch) : $defaultValue;
break;

case 'weightedfields':
$defaultValue = isset($config->search->simple) ? $config->search->simple->toArray() : $defaultValue;
break;
}

return $this->data[$name] ?? $defaultValue;
}

Expand Down