Jump to content

Recommended Posts

Hi,

 

Need some help to get Sphinx Search working - framework being used is CakePHP.

Here's the error when clicking the search form on page (I'll post the class code following the error info debugged from CakePHP

----------------------------

Notice (: Undefined index: Job [APP/Controller/JobsController.php, line 79]
Code Context

$search = object(SphinxClient) {
	_host => 'localhost'
	_port => (int) 9312
	_offset => (int) 0
	_limit => (int) 20
	_mode => (int) 6
	_weights => array()
	_sort => (int) 0
	_sortby => ''
	_min_id => (int) 0
	_max_id => (int) 0
	_filters => array()
	_groupby => ''
	_groupfunc => (int) 0
	_groupsort => '@group desc'
	_groupdistinct => ''
	_maxmatches => (int) 1000
	_cutoff => (int) 0
	_retrycount => (int) 0
	_retrydelay => (int) 0
	_anchor => array()
	_indexweights => array()
	_ranker => (int) 0
	_rankexpr => ''
	_maxquerytime => (int) 0
	_fieldweights => array()
	_overrides => array()
	_select => '*'
	_error => ''
	_warning => ''
	_connerror => false
	_reqs => array()
	_mbenc => ''
	_arrayresult => false
	_timeout => (int) 0
	_path => false
	_socket => false
}

JobsController::search() - APP/Controller/JobsController.php, line 79
ReflectionMethod::invokeArgs() - [internal], line ??
Controller::invokeAction() - CORE/Cake/Controller/Controller.php, line 486
Dispatcher::_invoke() - CORE/Cake/Routing/Dispatcher.php, line 187
Dispatcher::dispatch() - CORE/Cake/Routing/Dispatcher.php, line 162
[main] - APP/webroot/index.php, line 109

And here's the snippet of code from 'JobsController.php

Q: I see the error stating, 'ReflectionMethod::invokeArgs() - [internal], line ??' but need some guidance on how to isolate the fault and resolve.

To add, I have found some syntax issues as well - I'm fixing those but need some guidance on getting Sphinx query up and running based on stated criteria.

 

FYI: (Line 79 starts w/this line of code: $results = $search->query($this->request->data['Job']['keywords'], 'src2');

<?php

require('Component/SphinxComponent.php');
App::uses('AppController', 'Controller');

/**
 * Jobs Controller
 *
 * @property Job $Job
 */
class JobsController extends AppController {

/**
 * Uses
 *
 * @var array
 */
	// JobTypeType is *not* a typo below
	public $uses = array('User', 'Resume', 'JobType', 'FieldType', 'Job', 'JobTypeType', 'JobFieldType', 'UserField', 'UserFieldType', 'EducationLevel', 'CandidateView', 'EmployerProfile');
	
/**
 * Helpers
 *
 * @var array
 */
	public $helpers = array('Text', 'Js', 'Time', 'Number', 'Func');

/**
 * Components
 *
 * @var array
 */
	public $components = array('Email');

/**
 * beforeFilter callback
 *
 * @return void
 */
	public function beforeFilter() {
		parent::beforeFilter();
		//echo $this->request->here;
		$this->Auth->allow('recent', 'daily', 'industries', 'search', 'limited', 'view');
	}

/**
 * isAuthorized callback
 *
 * @return void
 */
	public function isAuthorized($user) {
		if ($user['Role']['role_name'] == 'Employer') {
			return true;
		} else {
			if ($user['Role']['role_name'] == 'Candidate') {
				if (in_array($this->action, array('search','togglefavorite'))) {
					return true;
				}
			} 
			if (in_array($this->action, array('view'))) {
				return true;
			}
		}
		return true;
	}

/**
 * search method
 * 
 * Takes full-text Sphinx search results and then filters & paginates
 *
 * @return void
 */
	public function search() {
		if ($this->request->is('post')) {
			$search = new SphinxClient();
			$search->setMatchMode(SPH_MATCH_EXTENDED2);
			$results = $search->query($this->request->data['Job']['keywords'], 'src2');
			if (isset($results['matches'])) {
				$conditions['Job.id'] = array_keys($results['matches']);
			}
			
			if (isset($this->request->data['Job']['field_types_id'])) {
				foreach ($this->request->data['Job']['field_types_id'] as $field_type_id) {
// 					$conditions[]['Job.job_field_types LIKE'] = '|%' . $field_type_id . '%|';
					$field_type_conditions[]['Job.job_field_types LIKE'] = '%|' . $field_type_id . '|%';
				}
			}
			if (isset($this->request->data['Job']['job_types_id'])) {
				foreach ($this->request->data['Job']['job_types_id'] as $job_type_id) {
// 					$conditions[]['Job.job_type_types LIKE'] = '|%' . $job_type_id . '%|';
					$job_type_conditions[]['Job.job_type_types LIKE'] = '%|' . $job_type_id . '|%';
				}
			}
			if (is_numeric($this->request->data['Job']['job_salary_type']) 
				&& 
			    is_numeric($this->request->data['Job']['minimum_salary']) 
				&& 
			    is_numeric($this->request->data['Job']['maximum_salary'])) 
			{
				$conditions['Job.job_salary_type'] = $this->request->data['Job']['job_salary_type'];
				$conditions['Job.job_salary BETWEEN ? AND ?'] = array(
					$this->request->data['Job']['minimum_salary'],
					$this->request->data['Job']['maximum_salary']
				);
			}
			if (is_numeric($this->request->data['Job']['minimum_experience'])) {
				$conditions['Job.minimum_experience >='] = $this->request->data['Job']['minimum_experience']; 
			}
			if (isset($this->request->data['Job']['education_levels_id'])) {	
				foreach ($this->request->data['Job']['education_levels_id'] as $education_levels_id) {
					$conditions['OR'][]['Job.education_levels_id'] = $education_levels_id;
				}	
			}
			if (isset($this->request->data['Job']['date_posted'])) {
				switch ($this->request->data['Job']['date_posted']) {
					// Posted Today
					case 'today':
						$conditions['Job.modified BETWEEN ? AND ?'] = array(
							date('Y-m-d').' 00:00:00',
							date('Y-m-d').' 23:59:59',
						);
					break;
					// Posted This Week
					case 'week':
						$monday = intval(date('d')) - intval(date('N')) + 1;
						$conditions['Job.modified BETWEEN ? AND ?'] = array(
							date('Y-m-').$monday.' 00:00:00',
							date('Y-m-d H:i:s')							
						);
					break;
					// Posted This Month 
					case 'month':
						$conditions['Job.modified BETWEEN ? AND ?'] = array(
							date('Y-m-1').' 00:00:00',
							date('Y-m-d H:i:s')							
						);
					break;
					// Posted Any
					case '':
						$conditions['Job.modified NOT'] = null;
					break;
					
				}
			}
			$conditions[]['Job.deleted'] = null;
		} else {
			$conditions[]['Job.deleted'] = null;
		}
		if (isset($field_type_conditions)) {
			if (isset($job_type_conditions)) {
				$final_conditions = array(
						'AND' => array(
								array('OR' => $field_type_conditions),
								array('OR' => $job_type_conditions),
								array('AND'=>$conditions)
						)
				);
			} else {
				$final_conditions = array(
						'AND' => array(
								array('OR' => $field_type_conditions),
								array('AND'=>$conditions)
						)
				);
			}
		} else {
			if (isset($job_type_conditions)) {
				$final_conditions = array(
						'AND' => array(
								array('OR' => $job_type_conditions),
								array('AND'=>$conditions)
						)
				);
			} else {
				$final_conditions = array(
						'AND' => array(
								array('AND'=>$conditions)
						)
				);
			}
		}
		
		$this->Job->recursive = 0;
		$this->paginate = array(
			'limit'=>10,
			'conditions' => $final_conditions,
			'order' => array('Job.modified DESC')
		);
		$jobs = $this->paginate('Job');
		$fieldTypes = $this->FieldType->find('list');
		$jobTypes = $this->JobType->find('list');
		$empRaw = $this->EmployerProfile->find('all', ['fields'=>['users_id','company_name']]);
		foreach ($empRaw as $emp) {
			$empList[$emp['EmployerProfile']['users_id']] = $emp['EmployerProfile']['company_name']; 
		}
		$educationLevels = $this->EducationLevel->find('list');
		foreach ($jobs as &$job) {
		}
		$this->set('jobs', $jobs);
		$this->set(compact('fieldTypes', 'jobTypes', 'educationLevels', 'empList', 'final_conditions'));
	}


Link to comment
https://forums.phpfreaks.com/topic/279724-sphinx-search-issues-with-cakephp/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.