Skip to content

Commit

Permalink
Look ma! I'm writing docs!
Browse files Browse the repository at this point in the history
  • Loading branch information
Firesphere committed Sep 9, 2019
1 parent b42d070 commit 83712cb
Show file tree
Hide file tree
Showing 14 changed files with 196 additions and 18 deletions.
9 changes: 9 additions & 0 deletions src/Factories/QueryComponentFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,25 @@ class QueryComponentFactory
'Spellcheck',
];
/**
* BaseQuery that needs to be executed
* @var BaseQuery
*/
protected $query;
/**
* Helper to escape the query terms properly
*
* @var Helper
*/
protected $helper;
/**
* Resulting querie parts as an array
*
* @var array
*/
protected $queryArray = [];
/**
* Index to query
*
* @var BaseIndex
*/
protected $index;
Expand Down Expand Up @@ -156,6 +163,8 @@ public function getClientQuery(): Query
}

/**
* Set a custom Client Query object
*
* @param Query $clientQuery
* @return self
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Helpers/DataResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function __construct($component, $columns = [])
*/
public static function identify($obj, $columns = [])
{
/** @var @see {self::$objTypes} $type */
/** @var {@link self::$objTypes} $type */
foreach (self::$objTypes as $type => $method) {
if ($obj instanceof $type) {
$method = 'resolve' . $method;
Expand Down
5 changes: 4 additions & 1 deletion src/Helpers/SolrLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@
*
* Log information from Solr to the CMS for reference
*
* @todo implement {@link LoggerInterface}
* @package Firesphere\SolrSearch\Helpers
*/
class SolrLogger
{
/**
* Guzzle base client to communicate with Solr
*
* @var Client
*/
protected $client;
Expand Down Expand Up @@ -54,7 +57,7 @@ public function __construct($handler = null)
* @throws GuzzleException
* @throws ValidationException
*/
public static function logMessage($type, $message, $index)
public static function logMessage($type, $message, $index): void
{
$solrLogger = new self();
$solrLogger->saveSolrLog($type);
Expand Down
20 changes: 19 additions & 1 deletion src/Indexes/BaseIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,20 @@ abstract class BaseIndex
'StoredFields',
];
/**
* @var \Solarium\Core\Query\Result\Result
* The raw query result
*
* @var Result
*/
protected $rawQuery;
/**
* {@link SchemaService}
*
* @var SchemaService
*/
protected $schemaService;
/**
* {@link QueryComponentFactory}
*
* @var QueryComponentFactory
*/
protected $queryFactory;
Expand All @@ -87,6 +93,8 @@ abstract class BaseIndex
*/
protected $queryTerms = [];
/**
* Should a retry occur if nothing was found and there are suggestions to follow
*
* @var bool
*/
private $retry = false;
Expand Down Expand Up @@ -224,6 +232,8 @@ public function doSearch(BaseQuery $query)
}

/**
* From the given BaseQuery, generate a Solarium ClientQuery object
*
* @param BaseQuery $query
* @return Query
*/
Expand All @@ -242,6 +252,8 @@ public function buildSolrQuery(BaseQuery $query): Query
}

/**
* Build a factory to use in the SolrQuery building. {@link static::buildSolrQuery()}
*
* @param BaseQuery $query
* @param Query $clientQuery
* @return QueryComponentFactory|mixed
Expand Down Expand Up @@ -304,6 +316,8 @@ protected function spellcheckRetry(BaseQuery $query, SearchResult $searchResult)
}

/**
* Get all fields that are required for indexing in a unique way
*
* @return array
*/
public function getFieldsForIndexing(): array
Expand Down Expand Up @@ -381,6 +395,8 @@ public function getSynonyms($defaults = true): string
}

/**
* Get the final, generated terms
*
* @return array
*/
public function getQueryTerms(): array
Expand All @@ -389,6 +405,8 @@ public function getQueryTerms(): array
}

/**
* Get the QueryComponentFactory. {@link QueryComponentFactory}
*
* @return QueryComponentFactory
*/
public function getQueryFactory(): QueryComponentFactory
Expand Down
2 changes: 2 additions & 0 deletions src/Jobs/SolrConfigureJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class SolrConfigureJob extends AbstractQueuedJob
{

/**
* My name
*
* @return string
*/
public function getTitle(): string
Expand Down
20 changes: 18 additions & 2 deletions src/Jobs/SolrIndexJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
use Symbiote\QueuedJobs\Services\QueuedJobService;

/**
* Class SolrIndexJob
* Class SolrIndexJob is a queued job to index all existing indexes and their classes.
*
* It always runs on all indexes, to make sure all indexes are up to date.
*
* @package Firesphere\SolrSearch\Jobs
*/
Expand All @@ -42,6 +44,8 @@ class SolrIndexJob extends AbstractQueuedJob
protected $indexes;

/**
* My name
*
* @return string
*/
public function getTitle()
Expand All @@ -50,7 +54,7 @@ public function getTitle()
}

/**
* Do some processing yourself!
* Process this job
*
* @return self
* @throws Exception
Expand Down Expand Up @@ -89,6 +93,8 @@ public function process()
}

/**
* Configure the run for the valid indexes
*
* @param stdClass|null $data
* @throws ReflectionException
*/
Expand Down Expand Up @@ -130,6 +136,8 @@ public function afterComplete()
}

/**
* Get the next step to execute
*
* @return array
*/
protected function getNextSteps(): array
Expand All @@ -155,6 +163,8 @@ protected function getNextSteps(): array
}

/**
* Which Indexes should I index
*
* @return array
*/
public function getClassToIndex(): array
Expand All @@ -163,6 +173,8 @@ public function getClassToIndex(): array
}

/**
* Which classes should I index
*
* @param array $classToIndex
* @return SolrIndexJob
*/
Expand All @@ -174,6 +186,8 @@ public function setClassToIndex($classToIndex)
}

/**
* Get the indexes
*
* @return array
*/
public function getIndexes(): array
Expand All @@ -182,6 +196,8 @@ public function getIndexes(): array
}

/**
* Set the indexes if needed
*
* @param array $indexes
* @return SolrIndexJob
*/
Expand Down
42 changes: 38 additions & 4 deletions src/Results/SearchResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Firesphere\SolrSearch\Traits\SearchResultSetTrait;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\ORM\ArrayList;
use SilverStripe\ORM\DataList;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\FieldType\DBField;
use SilverStripe\ORM\PaginatedList;
Expand All @@ -20,9 +21,13 @@
use Solarium\Component\Result\Spellcheck\Result as SpellcheckResult;
use Solarium\QueryType\Select\Result\Document;
use Solarium\QueryType\Select\Result\Result;
use stdClass;

/**
* Class SearchResult
* Class SearchResult is the combined result in a SilverStripe readable way
*
* Each of the requested features of a BaseQuery are generated to be easily accessible in the controller.
* In the controller, each required item can be accessed through the resulting method in this class.
*
* @package Firesphere\SolrSearch\Results
*/
Expand All @@ -31,17 +36,23 @@ class SearchResult
use SearchResultGetTrait;
use SearchResultSetTrait;
/**
* Query that has been executed
*
* @var BaseQuery
*/
protected $query;

/**
* Index the query has run on
*
* @var BaseIndex
*/
protected $index;

/**
* @var ArrayList
* Resulting matches from the query on the index
*
* @var stdClass|ArrayList|DataList|DataObject
*/
protected $matches;

Expand Down Expand Up @@ -69,6 +80,8 @@ public function __construct(Result $result, BaseQuery $query, BaseIndex $index)
}

/**
* Set the facets to build
*
* @param FacetSet|null $facets
* @return $this
*/
Expand Down Expand Up @@ -101,6 +114,8 @@ protected function buildFacets($facets): ArrayData
}

/**
* Create facets from each faceted class
*
* @param FacetSet $facets
* @param array $options
* @param string $class
Expand All @@ -125,6 +140,8 @@ protected function createFacet($facets, $options, $class, array $facetArray): ar
}

/**
* Get the facets for each class and their count
*
* @param $class
* @param array $values
* @param ArrayList $results
Expand All @@ -142,6 +159,8 @@ protected function getClassFacets($class, array $values, &$results): void
}

/**
* Set the collated spellcheck string
*
* @param mixed $collatedSpellcheck
* @return $this
*/
Expand All @@ -156,6 +175,8 @@ public function setCollatedSpellcheck($collatedSpellcheck): self
}

/**
* Set the spellcheck list as an ArrayList
*
* @param SpellcheckResult|null $spellcheck
* @return SearchResult
*/
Expand All @@ -175,6 +196,8 @@ public function setSpellcheck($spellcheck): self
}

/**
* Get the matches as a Paginated List
*
* @param HTTPRequest $request
* @return PaginatedList
*/
Expand All @@ -197,6 +220,9 @@ public function getPaginatedMatches(HTTPRequest $request): PaginatedList
}

/**
* Get the matches as an ArrayList and add an excerpt if possible.
* {@link static::createExcerpt()}
*
* @return ArrayList
*/
public function getMatches(): ArrayList
Expand All @@ -219,6 +245,8 @@ public function getMatches(): ArrayList
}

/**
* Set the matches from Solarium as an ArrayList
*
* @param array $result
* @return $this
*/
Expand All @@ -237,6 +265,8 @@ protected function setMatches($result): self
}

/**
* Check if the match is a DataObject and exists
*
* @param $match
* @param string $classIDField
* @return DataObject|bool
Expand All @@ -253,6 +283,8 @@ protected function isDataObject($match, string $classIDField)
}

/**
* Generate an excerpt for a DataObject
*
* @param string $idField
* @param $match
* @param DataObject $item
Expand All @@ -270,6 +302,8 @@ protected function createExcerpt(string $idField, $match, DataObject $item): voi
}

/**
* Get the highlight for a specific document
*
* @param $docID
* @return string
*/
Expand All @@ -287,9 +321,9 @@ public function getHighlightByID($docID): string
}

/**
* Allow overriding of matches with a custom result
* Allow overriding of matches with a custom result. Accepts anything you like, mostly
*
* @param $matches
* @param stdClass|ArrayList|DataList|DataObject $matches
* @return mixed
*/
public function setCustomisedMatches($matches)
Expand Down
Loading

0 comments on commit 83712cb

Please sign in to comment.