<commit_before><?php

/**
 * An XSearch request, pointed at the /IntraLibrary-XSearch endpoint.
 * 
 * @package IntraLibrary_PHP
 * @author  <NAME>, <<EMAIL>>
 */
class IntraLibraryXSearchRequest extends IntraLibraryRequest
{
	
	private $responseObject;
	
	/**
	 * Create an IntraLibraryXSearchRequest object
	 * 
	 * @param IntraLibrarySRWResponse $responseObject the object used to handle the response
	 */
	public function __construct(IntraLibrarySRWResponse $responseObject)
	{
		parent::__construct('IntraLibrary-XSearch');
		
		$this->responseObject = $responseObject;
	}
	
	/**
	 * Execute an XSearch query
	 * 
	 * @param string  $query    the XSearch query
	 * @param integer $limit    (optional) the maximum number of records to return
	 * @param string  $username (optional) the user to search for. if empty, the configred intralibrary user will be used
	 * @return IntraLibrarySRWResponse
	 */
	public function query($query, $limit = FALSE, $username = NULL)
	{
		$queryParams = array(
			'version' => '1.1',
			'operation' => 'searchRetrieve',
			'recordSchema' => $this->responseObject->getRecordSchema(),
			'username' => $username !== NULL ? $username : $this->getUsername(),
			'query' => $query
		);
		
		if (((int) $limit) != 0)
		{
			$queryParams['maximumRecords'] = (int) $limit;
		}
		
		return $this->get('', $queryParams);
	}
	
	/**
	 * Prepare the response
	 * 
	 * @see IntraLibraryRequest::prepareResponse()
	 * 
	 * @param string $responseData the response data
	 * @return IntraLibrarySRWResponse
	 */
	protected function prepareResponse($responseData)
	{
		$httpCode = $this->getLastResponseCode();
		if ($httpCode < 200 || $httpCode > 399)
		{
			// non-OK http codes for XSearch requests don't return a normal XML response
			$responseData = NULL;
		}
		
		$this->responseObject->load($responseData);
		
		$numRecords 	= count($this->responseObject->getRecords());
		$totalRecords 	= $this->responseObject->getTotalRecords();
		
		if ($numRecords != $totalRecords)
		{
			$requestInfo = $this->getLastRequestInfo();
			error_log("IntraLibrary-PHP: total records ($totalRecords) do not match response count ($numRecords) for $requestInfo");
		}
		
		return $this->responseObject;
	}
}
<commit_msg>adding 'showUnpublished' support for XSearch requests<commit_after><?php

/**
 * An XSearch request, pointed at the /IntraLibrary-XSearch endpoint.
 * 
 * @package IntraLibrary_PHP
 * @author  <NAME>, <<EMAIL>>
 */
class IntraLibraryXSearchRequest extends IntraLibraryRequest
{
	
	private $responseObject;
	
	/**
	 * Create an IntraLibraryXSearchRequest object
	 * 
	 * @param IntraLibrarySRWResponse $responseObject the object used to handle the response
	 */
	public function __construct(IntraLibrarySRWResponse $responseObject)
	{
		parent::__construct('IntraLibrary-XSearch');
		
		$this->responseObject = $responseObject;
	}
	
	/**
	 * Execute an XSearch query
	 * 
	 * @param array $params An array of options. Required: 'query'. Optional: 'limit', 'username', 'showUnpublished'
	 * @return IntraLibrarySRWResponse
	 */
	public function query($params)
	{
		// query parameter is required
		if (empty($params['query']))
		{
			throw new IntraLibraryException('Missing query parameter');
		}
		
		$queryParams = array(
			'version' => '1.1',
			'operation' => 'searchRetrieve',
			'recordSchema' => $this->responseObject->getRecordSchema(),
			'username' => isset($params['username']) ? $params['username'] : $this->getUsername(),
			'query' => $params['query']
		);
		
		if (!empty($params['limit']) && ((int) $params['limit']) != 0)
		{
			$queryParams['maximumRecords'] = (int) $params['limit'];
		}
		
		if (!empty($params['showUnpublished']))
		{
			$queryParams['showUnpublished'] = 'true';
		}
		
		return $this->get('', $queryParams);
	}
	
	/**
	 * Prepare the response
	 * 
	 * @see IntraLibraryRequest::prepareResponse()
	 * 
	 * @param string $responseData the response data
	 * @return IntraLibrarySRWResponse
	 */
	protected function prepareResponse($responseData)
	{
		$httpCode = $this->getLastResponseCode();
		if ($httpCode < 200 || $httpCode > 399)
		{
			// non-OK http codes for XSearch requests don't return a normal XML response
			$responseData = NULL;
		}
		
		$this->responseObject->load($responseData);
		
		$numRecords 	= count($this->responseObject->getRecords());
		$totalRecords 	= $this->responseObject->getTotalRecords();
		
		if ($numRecords != $totalRecords)
		{
			$requestInfo = $this->getLastRequestInfo();
			error_log("IntraLibrary-PHP: total records ($totalRecords) do not match response count ($numRecords) for $requestInfo");
		}
		
		return $this->responseObject;
	}
}

{'fraction_non_alphanumeric': 0.14079655543595263, 'fraction_numerical': 0.0038751345532831, 'mean_word_length': 4.185267857142857, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3090609', 'n_tokens_mistral': 1573, 'n_tokens_neox': 1343, 'n_words': 344}