#php #database #laravel #exception #solr
#php #База данных #laravel #исключение #solr
Вопрос:
Я получаю сообщение об ошибке, пока Solr работает нормально. Я проверил, используя IP и порт, и открывается HTML. Поскольку я новичок в Laravel и Solr, я не могу понять, что происходит. Я только что перенес WebApp с одной виртуальной машины на другую. И я начинаю сталкиваться с этой проблемой. Приложение, использующее Laravel 5.2 и работающее на CentOS7.2
ErrorException: попытка получить свойство не-объекта в /srv/websites/webapp.com/app/webapp/Solr/Solr.php:248
Вот полная ошибка из журналов Laravel.
[2016-10-15 00:33:57] production.ERROR: ErrorException: Trying to get property of non-object in /srv/websites/webapp.com/app/webapp/Solr/Solr.php:248
Stack trace:
#0 /srv/websites/webapp.com/app/webapp/Solr/Solr.php(248): IlluminateFoundationBootstrapHandleExceptions->handleError(8, 'Trying to get p...', '/srv/websites/r...', 248, Array)
#1 /srv/websites/webapp.com/app/Http/Controllers/SearchController.php(39): AppwebappSolrSolr->search(Array)
#2 [internal function]: AppHttpControllersSearchController->getSearchResponse()
#3 /srv/websites/webapp.com/bootstrap/cache/compiled.php(9424): call_user_func_array(Array, Array)
#4 /srv/websites/webapp.com/bootstrap/cache/compiled.php(9486): IlluminateRoutingController->callAction('getSearchRespon...', Array)
#5 /srv/websites/webapp.com/bootstrap/cache/compiled.php(9466): IlluminateRoutingControllerDispatcher->call(Object(AppHttpControllersSearchController), Object(IlluminateRoutingRoute), 'getSearchRespon...')
#6 [internal function]: IlluminateRoutingControllerDispatcher->IlluminateRouting{closure}(Object(IlluminateHttpRequest))
#7 /srv/websites/webapp.com/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(52): call_user_func(Object(Closure), Object(IlluminateHttpRequest))
#8 [internal function]: IlluminateRoutingPipeline->IlluminateRouting{closure}(Object(IlluminateHttpRequest))
#9 /srv/websites/webapp.com/bootstrap/cache/compiled.php(9948): call_user_func(Object(Closure), Object(IlluminateHttpRequest))
#10 /srv/websites/webapp.com/bootstrap/cache/compiled.php(9467): IlluminatePipelinePipeline->then(Object(Closure))
#11 /srv/websites/webapp.com/bootstrap/cache/compiled.php(9454): IlluminateRoutingControllerDispatcher->callWithinStack(Object(AppHttpControllersSearchController), Object(IlluminateRoutingRoute), Object(IlluminateHttpRequest), 'getSearchRespon...')
#12 /srv/websites/webapp.com/bootstrap/cache/compiled.php(8524): IlluminateRoutingControllerDispatcher->dispatch(Object(IlluminateRoutingRoute), Object(IlluminateHttpRequest), 'App\Http\Contro...', 'getSearchRespon...')
#13 /srv/websites/webapp.com/bootstrap/cache/compiled.php(8511): IlluminateRoutingRoute->runController(Object(IlluminateHttpRequest))
#14 /srv/websites/webapp.com/bootstrap/cache/compiled.php(8225): IlluminateRoutingRoute->run(Object(IlluminateHttpRequest))
#15 [internal function]: IlluminateRoutingRouter->IlluminateRouting{closure}(Object(IlluminateHttpRequest))
#16 /srv/websites/webapp.com/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(52): call_user_func(Object(Closure), Object(IlluminateHttpRequest))
#17 [internal function]: IlluminateRoutingPipeline->IlluminateRouting{closure}(Object(IlluminateHttpRequest))
#18 /srv/websites/webapp.com/bootstrap/cache/compiled.php(9948): call_user_func(Object(Closure), Object(IlluminateHttpRequest))
#19 /srv/websites/webapp.com/bootstrap/cache/compiled.php(8226): IlluminatePipelinePipeline->then(Object(Closure))
#20 /srv/websites/webapp.com/bootstrap/cache/compiled.php(8217): IlluminateRoutingRouter->runRouteWithinStack(Object(IlluminateRoutingRoute), Object(IlluminateHttpRequest))
#21 /srv/websites/webapp.com/bootstrap/cache/compiled.php(8207): IlluminateRoutingRouter->dispatchToRoute(Object(IlluminateHttpRequest))
#22 /srv/websites/webapp.com/bootstrap/cache/compiled.php(2419): IlluminateRoutingRouter->dispatch(Object(IlluminateHttpRequest))
#23 [internal function]: IlluminateFoundationHttpKernel->IlluminateFoundationHttp{closure}(Object(IlluminateHttpRequest))
#24 /srv/websites/webapp.com/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(52): call_user_func(Object(Closure), Object(IlluminateHttpRequest))
#25 /srv/websites/webapp.com/app/Http/Middleware/Wizard.php(14): IlluminateRoutingPipeline->IlluminateRouting{closure}(Object(IlluminateHttpRequest))
#26 [internal function]: AppHttpMiddlewareWizard->handle(Object(IlluminateHttpRequest), Object(Closure))
#27 /srv/websites/webapp.com/bootstrap/cache/compiled.php(9963): call_user_func_array(Array, Array)
#28 [internal function]: IlluminatePipelinePipeline->IlluminatePipeline{closure}(Object(IlluminateHttpRequest))
#29 /srv/websites/webapp.com/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): call_user_func(Object(Closure), Object(IlluminateHttpRequest))
#30 /srv/websites/webapp.com/app/Http/Middleware/LoginRedirect.php(15): IlluminateRoutingPipeline->IlluminateRouting{closure}(Object(IlluminateHttpRequest))
#31 [internal function]: AppHttpMiddlewareLoginRedirect->handle(Object(IlluminateHttpRequest), Object(Closure))
#32 /srv/websites/webapp.com/bootstrap/cache/compiled.php(9963): call_user_func_array(Array, Array)
#33 [internal function]: IlluminatePipelinePipeline->IlluminatePipeline{closure}(Object(IlluminateHttpRequest))
#34 /srv/websites/webapp.com/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): call_user_func(Object(Closure), Object(IlluminateHttpRequest))
#35 /srv/websites/webapp.com/app/Http/Middleware/Analytics.php(20): IlluminateRoutingPipeline->IlluminateRouting{closure}(Object(IlluminateHttpRequest))
#36 [internal function]: AppHttpMiddlewareAnalytics->handle(Object(IlluminateHttpRequest), Object(Closure))
#37 /srv/websites/webapp.com/bootstrap/cache/compiled.php(9963): call_user_func_array(Array, Array)
#38 [internal function]: IlluminatePipelinePipeline->IlluminatePipeline{closure}(Object(IlluminateHttpRequest))
#39 /srv/websites/webapp.com/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): call_user_func(Object(Closure), Object(IlluminateHttpRequest))
#40 /srv/websites/webapp.com/app/Http/Middleware/ClientInit.php(23): IlluminateRoutingPipeline->IlluminateRouting{closure}(Object(IlluminateHttpRequest))
#41 [internal function]: AppHttpMiddlewareClientInit->handle(Object(IlluminateHttpRequest), Object(Closure))
#42 /srv/websites/webapp.com/bootstrap/cache/compiled.php(9963): call_user_func_array(Array, Array)
#43 [internal function]: IlluminatePipelinePipeline->IlluminatePipeline{closure}(Object(IlluminateHttpRequest))
#44 /srv/websites/webapp.com/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): call_user_func(Object(Closure), Object(IlluminateHttpRequest))
#45 /srv/websites/webapp.com/bootstrap/cache/compiled.php(13474): IlluminateRoutingPipeline->IlluminateRouting{closure}(Object(IlluminateHttpRequest))
#46 [internal function]: IlluminateViewMiddlewareShareErrorsFromSession->handle(Object(IlluminateHttpRequest), Object(Closure))
#47 /srv/websites/webapp.com/bootstrap/cache/compiled.php(9963): call_user_func_array(Array, Array)
#48 [internal function]: IlluminatePipelinePipeline->IlluminatePipeline{closure}(Object(IlluminateHttpRequest))
#49 /srv/websites/webapp.com/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): call_user_func(Object(Closure), Object(IlluminateHttpRequest))
#50 /srv/websites/webapp.com/bootstrap/cache/compiled.php(11964): IlluminateRoutingPipeline->IlluminateRouting{closure}(Object(IlluminateHttpRequest))
#51 [internal function]: IlluminateSessionMiddlewareStartSession->handle(Object(IlluminateHttpRequest), Object(Closure))
#52 /srv/websites/webapp.com/bootstrap/cache/compiled.php(9963): call_user_func_array(Array, Array)
#53 [internal function]: IlluminatePipelinePipeline->IlluminatePipeline{closure}(Object(IlluminateHttpRequest))
#54 /srv/websites/webapp.com/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): call_user_func(Object(Closure), Object(IlluminateHttpRequest))
#55 /srv/websites/webapp.com/bootstrap/cache/compiled.php(13213): IlluminateRoutingPipeline->IlluminateRouting{closure}(Object(IlluminateHttpRequest))
#56 [internal function]: IlluminateCookieMiddlewareAddQueuedCookiesToResponse->handle(Object(IlluminateHttpRequest), Object(Closure))
#57 /srv/websites/webapp.com/bootstrap/cache/compiled.php(9963): call_user_func_array(Array, Array)
#58 [internal function]: IlluminatePipelinePipeline->IlluminatePipeline{closure}(Object(IlluminateHttpRequest))
#59 /srv/websites/webapp.com/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): call_user_func(Object(Closure), Object(IlluminateHttpRequest))
#60 /srv/websites/webapp.com/bootstrap/cache/compiled.php(13150): IlluminateRoutingPipeline->IlluminateRouting{closure}(Object(IlluminateHttpRequest))
#61 [internal function]: IlluminateCookieMiddlewareEncryptCookies->handle(Object(IlluminateHttpRequest), Object(Closure))
#62 /srv/websites/webapp.com/bootstrap/cache/compiled.php(9963): call_user_func_array(Array, Array)
#63 [internal function]: IlluminatePipelinePipeline->IlluminatePipeline{closure}(Object(IlluminateHttpRequest))
#64 /srv/websites/webapp.com/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): call_user_func(Object(Closure), Object(IlluminateHttpRequest))
#65 /srv/websites/webapp.com/app/Http/Middleware/Debug.php(19): IlluminateRoutingPipeline->IlluminateRouting{closure}(Object(IlluminateHttpRequest))
#66 [internal function]: AppHttpMiddlewareDebug->handle(Object(IlluminateHttpRequest), Object(Closure))
#67 /srv/websites/webapp.com/bootstrap/cache/compiled.php(9963): call_user_func_array(Array, Array)
#68 [internal function]: IlluminatePipelinePipeline->IlluminatePipeline{closure}(Object(IlluminateHttpRequest))
#69 /srv/websites/webapp.com/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): call_user_func(Object(Closure), Object(IlluminateHttpRequest))
#70 [internal function]: IlluminateRoutingPipeline->IlluminateRouting{closure}(Object(IlluminateHttpRequest))
#71 /srv/websites/webapp.com/bootstrap/cache/compiled.php(9948): call_user_func(Object(Closure), Object(IlluminateHttpRequest))
#72 /srv/websites/webapp.com/bootstrap/cache/compiled.php(2366): IlluminatePipelinePipeline->then(Object(Closure))
#73 /srv/websites/webapp.com/bootstrap/cache/compiled.php(2350): IlluminateFoundationHttpKernel->sendRequestThroughRouter(Object(IlluminateHttpRequest))
#74 /srv/websites/webapp.com/public/index.php(53): IlluminateFoundationHttpKernel->handle(Object(IlluminateHttpRequest))
#75 {main}
Вот Solr.php файл содержит
<?php
namespace AppwebappSolr;
use Config;
class Solr
{
public static $ROWS_PER_PAGE = 8;
private $curl;
private $collection;
private $first = false;
public function __construct()
{
$host = config('solr.host').':'.config('solr.port', 3000);
$this->curl = Curl::create($host);
$this->curl->addQuery('wt', 'json');
$this->collection = config('solr.collection');
}
public function select()
{
return new self();
}
public function analysis($id)
{
$this->curl->addQuery('q', "id:Analysis-$id");
return $this;
}
public function piece()
{
$this->curl->addQuery('q', 'type_primary:research or type_primary:outlook or type_primary:media');
return $this;
}
public function event($id)
{
$this->curl->addQuery('q', "id:CMS-Events-$id");
return $this;
}
public function citation($id)
{
$this->curl->addQuery('q', "id:CMS-Citation-$id");
return $this;
}
public function thought($id)
{
$this->curl->addQuery('q', "id:CMS-Thought-$id");
return $this;
}
public function keyword($keyword)
{
$this->curl->addQuery('fq', "keywords:"$keyword"");
return $this;
}
public function fq($fq)
{
$this->curl->addQuery('fq', $fq);
return $this;
}
public function first()
{
$this->first = true;
return $this;
}
public function order($order)
{
$this->curl->addQuery('sort', $order);
return $this;
}
public function skip($rows)
{
$this->curl->addQuery('start', $rows);
return $this;
}
public function take($rows)
{
$this->curl->addQuery('rows', $rows);
return $this;
}
public function retrieve()
{
$this->curl->addQuery('fl', implode(',', func_get_args()));
return $this;
}
public function search($params, $debug = false)
{
# Loose query search using edismax query builder.
$q = (isset($params['q']) amp;amp; !empty($params['q'])) ? $params['q'] : '*:*';
# If page is set
$p = (isset($params['p']) amp;amp; !empty($params['p'])) ? intval(abs($params['p'])) : 0;
# Query filter weights for edismax
$qf = [
'authors^40',
'keyword_primary^30',
'keywords^20',
'fulltext^10',
]; # = 100 Weight Total, Perfect Score
# Boost Query
$bq = [];
if (isset($params['regions-geographic']) amp;amp; is_array($params['regions-geographic'])) {
foreach ($params['regions-geographic'] as $k => $v) {
$bq[] = "keyword_primary:"{$v}"";
}
}
if (isset($params['regions-economic']) amp;amp; is_array($params['regions-economic'])) {
foreach ($params['regions-economic'] as $k => $v) {
$bq[] = "keyword_primary:"{$v}"";
}
}
if (isset($params['topics']) amp;amp; is_array($params['topics'])) {
foreach ($params['topics'] as $k => $v) {
$bq[] = "keyword_primary:"{$v}"";
}
}
if (isset($params['authors']) amp;amp; is_array($params['authors'])) {
foreach ($params['authors'] as $k => $v) {
$bq[] = "authors:"{$v}"";
}
}
if (!empty($params['primary-keyword'])) {
$bq[] = "(keyword_primary:"{$params['primary-keyword']}" OR authors:"{$params['primary-keyword']}")";
}
# Filter Query
$fq1 = [];
if (isset($params['regions-geographic']) amp;amp; is_array($params['regions-geographic'])) {
foreach ($params['regions-geographic'] as $k => $v) {
$fq1[] = "keywords:"{$v}"";
}
}
if (isset($params['regions-economic']) amp;amp; is_array($params['regions-economic'])) {
foreach ($params['regions-economic'] as $k => $v) {
$fq1[] = "keywords:"{$v}"";
}
}
if (isset($params['topics']) amp;amp; is_array($params['topics'])) {
foreach ($params['topics'] as $k => $v) {
$fq1[] = "keywords:"{$v}"";
}
}
if (isset($params['authors']) amp;amp; is_array($params['authors'])) {
foreach ($params['authors'] as $k => $v) {
$fq1[] = "authors:"{$v}"";
}
}
if (!empty($params['primary-keyword'])) {
$fq1[] = "(keywords:"{$params['primary-keyword']}" OR authors:"{$params['primary-keyword']}")";
}
$fq2 = [];
if (isset($params['content']) amp;amp; is_array($params['content'])) {
foreach ($params['content'] as $k => $v) {
$fq2[] = "type_secondary:"{$v}"";
}
}
# Content Template Filter
$fq = '';
if (!empty($fq1)):
$fq .= '('.implode(' AND ', $fq1).')';
if (!empty($fq2)) {
$fq .= ' AND ';
}
endif;
if (!empty($fq2)):
$fq .= '('.implode(' OR ', $fq2).')';
endif;
# Minimum match required for return.
$mm = 3;
# Sort by score and then date created.
//$sort="score desc, date_created desc";
$sort = 'date_created desc';
# List Filter for Objects
$fl = 'page_title, url_absolute, date_created, date_unix_created, authors_primary, keyword_primary, keywords, type_primary, type_secondary';
$this->curl->addQuery('defType', 'edismax');
$this->curl->addQuery('q', $q);
$this->curl->addQuery('qf', implode(' ', $qf));
if (!empty($bq)) {
$this->curl->addQuery('bq', implode(' OR ', $bq));
}
if (!empty($fq)) {
$this->curl->addQuery('fq', $fq);
}
$this->curl->addQuery('mm', $mm);
$this->curl->addQuery('sort', $sort);
$this->curl->addQuery('start', $p * self::$ROWS_PER_PAGE);
$this->curl->addQuery('rows', self::$ROWS_PER_PAGE);
$this->curl->addQuery('fl', $fl);
if ($debug) {
echo "<pre style='word-wrap: break-word;'>";
echo "Params:n";
var_dump($params);
echo "Q:n";
var_dump($q);
echo "QF:n";
var_dump($qf);
echo "FQ:n";
var_dump($fq);
echo "SORT:n";
var_dump($sort);
echo "FL:n";
var_dump($fl);
echo "Response:n";
var_dump($this->get(true, true));
echo '</pre>';
exit();
}
$response = $this->get(false, true);
$r = [];
$r['total'] = $response->response->numFound;
$r['pages'] = ceil($response->response->numFound / self::$ROWS_PER_PAGE);
$r['page'] = intval(abs($p));
$r['rows'] = self::$ROWS_PER_PAGE;
$r['docs'] = (isset($response->response->docs) amp;amp; !empty($response->response->docs)) ? $response->response->docs : [];
return $r;
}
public function get($debug = false, $raw = false)
{
$this->curl->setUri('solr', $this->collection, 'select');
$response = $this->curl->get(array(
'dataType' => AppwebappCurlCurl::TYPE_JSON,
));
if ($debug) {
echo "n<strong>".urldecode($this->curl->lastUrl())."</strong>n";
}
if (!isset($response->response)) {
return [];
}
$this->convertDatesToCarbon($response);
if ($raw) {
return $response;
}
return $this->first ? reset($response->response->docs) : $response->response->docs;
}
private function convertDatesToCarbon(amp;$response)
{
foreach ($response->response->docs as $doc) {
if (isset($doc->created)) {
$doc->created = new CarbonCarbon($doc->created);
}
if (isset($doc->modified)) {
$doc->modified = new CarbonCarbon($doc->modified);
}
}
}
}
Комментарии:
1. Строка 248….
2. Если вы откроете фактический URL-адрес, который запрашивает curl — каков ответ? Показывает ли журнал в Solr что-нибудь полезное (например, ошибку или показывает, что запрос выполняется)?
3. Строка 248 — это $r[‘total’] = $response->response->numFound; @Devon
4. Как открыть фактический URL-адрес, который запрашивает. Можете ли вы рассказать мне больше об этом? Я установил на виртуальную машину, но не настроил ее. @MatsLindh
5. @vikaskumawat80 Таким образом, ошибка означает
$response->response
, что это не объект. Выгрузите$response
и посмотрите, что это такое, затем отладьте.
Ответ №1:
Возможно, проблема только в
$response->response->numFound
Тест с
$response->numFound
И вы можете добавить это для предотвращения ошибки: «Попытка получить свойство не-объекта в »
$r['total'] = (property_exists($response), 'numFound') ? $response->numFound : null;