/**
  * Constructor for class tx_solr_facet_FacetRenderer
  *
  * @param	string	$facetName The name of the facet to render.
  * @param	tx_solr_Template	$template The template to use to render the facet.
  */
 public function __construct($facetName, tx_solr_Template $template)
 {
     $this->search = t3lib_div::makeInstance('tx_solr_Search');
     $this->facetName = $facetName;
     $this->template = $template;
     $this->solrConfiguration = tx_solr_Util::getSolrConfiguration();
     $this->facetConfiguration = $this->solrConfiguration['search.']['faceting.']['facets.'][$facetName . '.'];
     $this->linkTargetPageId = $GLOBALS['TSFE']->id;
 }
 /**
  * Expects a timestamp and converts it to an ISO 8601 date as needed by Solr.
  *
  * Example date output format: 1995-12-31T23:59:59Z
  * The trailing "Z" designates UTC time and is mandatory
  *
  * @param	array	Array of values, an array because of multivalued fields
  * @return	array	Modified array of values
  */
 public function process(array $values)
 {
     $results = array();
     foreach ($values as $timestamp) {
         $isoDate = tx_solr_Util::timestampToIso($timestamp);
         $results[] = $isoDate;
     }
     return $results;
 }
 /**
  * constructor for class tx_solr_viewhelper_Crop
  */
 public function __construct(array $arguments = array())
 {
     $configuration = tx_solr_Util::getSolrConfiguration();
     if (!empty($configuration['viewhelpers.']['crop.']['maxLength'])) {
         $this->maxLength = $configuration['viewhelpers.']['crop.']['maxLength'];
     }
     if (!empty($configuration['viewhelpers.']['crop.']['cropIndicator'])) {
         $this->cropIndicator = $configuration['viewhelpers.']['crop.']['cropIndicator'];
     }
 }
 /**
  * Renders the block of used / applied facets.
  *
  * @see tx_solr_FacetRenderer::render()
  * @return	string	Rendered HTML representing the used facet.
  */
 public function render()
 {
     $solrConfiguration = tx_solr_Util::getSolrConfiguration();
     $facetText = $this->renderOption($this->filterValue);
     $removeFacetText = strtr($solrConfiguration['search.']['faceting.']['removeFacetLinkText'], array('@facetValue' => $this->filterValue, '@facetName' => $this->facetName, '@facetText' => $facetText));
     $removeFacetLink = $this->buildRemoveFacetLink($removeFacetText, $this->filter);
     $removeFacetUrl = $this->buildRemoveFacetUrl($this->filter);
     $facetToRemove = array('link' => $removeFacetLink, 'url' => $removeFacetUrl, 'text' => $removeFacetText, 'name' => $this->filterValue);
     return $facetToRemove;
 }
 /**
  * constructor for class tx_solr_Query
  */
 public function __construct($keywords)
 {
     $this->solrConfiguration = tx_solr_Util::getSolrConfiguration();
     // TODO specify which fields to get exactly
     $this->returnFields = array('*', 'score');
     $this->setKeywords($keywords);
     $this->sorting = '';
     if (!empty($this->solrConfiguration['search.']['query.']['fields'])) {
         $this->setQueryFieldsFromString($this->solrConfiguration['search.']['query.']['fields']);
     }
     $this->linkTargetPageId = $this->solrConfiguration['search.']['targetPage'];
     if (empty($this->linkTargetPageId)) {
         $this->linkTargetPageId = $GLOBALS['TSFE']->id;
     }
     $this->id = ++self::$idCount;
 }
 public function setUp()
 {
     tx_solr_Util::initializeTsfe('1');
     $GLOBALS['TSFE']->tmpl->getFileName_backPath = PATH_site;
     $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_solr.']['search.']['targetPage'] = '0';
     $GLOBALS['TSFE']->tmpl->setup['config.']['tx_realurl_enable'] = '0';
     $facetName = 'TestFacet';
     $facetOptions = array('testoption' => 1);
     $facetConfiguration = array('selectingSelectedFacetOptionRemovesFilter' => 0, 'renderingInstruction');
     $parentPlugin = t3lib_div::makeInstance('tx_solr_pi_results');
     $parentPlugin->cObj = t3lib_div::makeInstance('tslib_cObj');
     $parentPlugin->main('', array());
     $query = t3lib_div::makeInstance('tx_solr_Query', array('test'));
     $this->facetRenderer = t3lib_div::makeInstance('tx_solr_facet_SimpleFacetRenderer', $facetName, $facetOptions, $facetConfiguration, $parentPlugin->getTemplate(), $query);
     $this->facetRenderer->setLinkTargetPageId($parentPlugin->getLinkTargetPageId());
 }
Пример #7
0
$TSFE->initFEuser();
$TSFE->initUserGroups();
$TSFE->sys_page = t3lib_div::makeInstance('t3lib_pageSelect');
$TSFE->rootLine = $TSFE->sys_page->getRootLine($pageId, '');
$TSFE->initTemplate();
$TSFE->getConfigArray();
$TSFE->includeTCA();
$TSFE->sys_language_uid = $languageId;
$solrConfiguration = tx_solr_Util::getSolrConfiguration();
#--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
# Building Suggest Query
$suggestQuery = NULL;
$q = trim(t3lib_div::_GP('term'));
$suggestQuery = t3lib_div::makeInstance('tx_solr_SuggestQuery', $q);
$suggestQuery->setUserAccessGroups(explode(',', $TSFE->gr_list));
$suggestQuery->setSiteHash(tx_solr_Util::getSiteHash($pageId));
$language = 0;
if ($TSFE->sys_language_uid) {
    $language = $TSFE->sys_language_uid;
}
$suggestQuery->addFilter('language:' . $language);
$suggestQuery->setOmitHeader();
$additionalFilters = t3lib_div::_GET('filters');
if (!empty($additionalFilters)) {
    $additionalFilters = json_decode($additionalFilters);
    foreach ($additionalFilters as $additionalFilter) {
        $suggestQuery->addFilter($additionalFilter);
    }
}
#--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
// Search
 /**
  * Constructor for class tx_solr_pi_results_SpellcheckFormModifier
  *
  */
 public function __construct()
 {
     $this->search = t3lib_div::makeInstance('tx_solr_Search');
     $this->configuration = tx_solr_Util::getSolrConfiguration();
 }
 /**
  * Returns the number of results per Page.
  *
  * @return	int	number of results to show per page
  */
 public function getNumberOfResultsPerPage()
 {
     $configuration = tx_solr_Util::getSolrConfiguration();
     $resultsPerPageSwitchOptions = t3lib_div::intExplode(',', $configuration['search.']['results.']['resultsPerPageSwitchOptions']);
     $solrParameters = array();
     $solrPostParameters = t3lib_div::_POST('tx_solr');
     $solrGetParameters = t3lib_div::_GET('tx_solr');
     // check for GET parameters, POST takes precedence
     if (isset($solrGetParameters) && is_array($solrGetParameters)) {
         $solrParameters = $solrGetParameters;
     }
     if (isset($solrPostParameters) && is_array($solrPostParameters)) {
         $solrParameters = $solrPostParameters;
     }
     if (isset($solrParameters['resultsPerPage']) && in_array($solrParameters['resultsPerPage'], $resultsPerPageSwitchOptions)) {
         $GLOBALS['TSFE']->fe_user->setKey('ses', 'tx_solr_resultsPerPage', intval($solrParameters['resultsPerPage']));
         $this->resultsPerPageChanged = TRUE;
     }
     $defaultNumberOfResultsShown = $configuration['search.']['results.']['resultsPerPage'];
     $userSetNumberOfResultsShown = $GLOBALS['TSFE']->fe_user->getKey('ses', 'tx_solr_resultsPerPage');
     $currentNumberOfResultsShown = $defaultNumberOfResultsShown;
     if (!is_null($userSetNumberOfResultsShown) && in_array($userSetNumberOfResultsShown, $resultsPerPageSwitchOptions)) {
         $currentNumberOfResultsShown = (int) $userSetNumberOfResultsShown;
     }
     if ($this->conf['search.']['allowEmptyQuery'] && empty($this->piVars['q'])) {
         // set number of rows to return to 0
         $currentNumberOfResultsShown = 0;
     }
     return $currentNumberOfResultsShown;
 }
 /**
  * constructor for class tx_solr_viewhelper_SortUrl
  */
 public function __construct(array $arguments = array())
 {
     $this->search = t3lib_div::makeInstance('tx_solr_Search');
     $this->configuration = tx_solr_Util::getSolrConfiguration();
     $this->query = $this->search->getQuery();
 }
 /**
  * Checks whether a page has a page type that can be indexed.
  * Currently standard pages and mount pages can be indexed.
  *
  * @param array $record A page record
  * @return boolean TRUE if the page can be indexed according to its page type, FALSE otherwise
  */
 protected function isIndexablePageType(array $record)
 {
     return tx_solr_Util::isAllowedPageType($record);
 }
Пример #12
0
 /**
  * Adds an item to the index queue.
  *
  * Not meant for public use.
  *
  * @param string $itemType The item's type, usually a table name.
  * @param string $itemUid The item's uid, usually an integer uid, could be a
  *      different value for non-database-record types.
  * @param string $indexingConfiguration The item's indexing configuration to use.
  *      Optional, overwrites existing / determined configuration.
  * @return void
  */
 private function addItem($itemType, $itemUid, $indexingConfiguration)
 {
     // FIXME must respect the indexer's additionalWhereClause option:
     // must not add items to the index queue which are excluded through
     // additionalWhereClause. Requires construction of additionalWhereClause
     // through multiple options instead of just one
     // FIXME temporary until we have a query builder to take care of this
     $additionalRecordFields = '';
     if ($itemType == 'pages') {
         $additionalRecordFields = ', doktype, uid';
     }
     $record = t3lib_BEfunc::getRecord($itemType, $itemUid, 'pid' . $additionalRecordFields);
     // FIXME temporary until we have a query builder to take care of this
     if (empty($record) || $itemType == 'pages' && !Tx_Solr_Util::isAllowedPageType($record)) {
         return;
     }
     if ($itemType == 'pages') {
         $rootPageId = Tx_Solr_Util::getRootPageId($itemUid);
     } else {
         $rootPageId = Tx_Solr_Util::getRootPageId($record['pid']);
     }
     if (Tx_Solr_Util::isRootPage($rootPageId)) {
         $item = array('root' => $rootPageId, 'item_type' => $itemType, 'item_uid' => $itemUid, 'changed' => $this->getItemChangedTime($itemType, $itemUid));
         if (!empty($indexingConfiguration)) {
             $indexingConfigurationList = array($indexingConfiguration);
         } else {
             $indexingConfigurationList = $this->getIndexingConfigurationsByItem($itemType, $itemUid, $rootPageId);
         }
         // make a backup of the current item
         $baseItem = $item;
         foreach ($indexingConfigurationList as $indexingConfigurationCurrent) {
             $item = $baseItem;
             $item['indexing_configuration'] = $indexingConfigurationCurrent;
             $writeToIndex = TRUE;
             // Ensure additionalWhereClause is applied.
             $solrConfiguration = tx_solr_Util::getSolrConfigurationFromPageId($record['pid']);
             if (!empty($solrConfiguration['index.']['queue.'][$item['indexing_configuration'] . '.']['additionalWhereClause'])) {
                 $record = t3lib_BEfunc::getRecord($itemType, $itemUid, 'pid' . $additionalRecordFields, ' AND ' . $solrConfiguration['index.']['queue.'][$item['indexing_configuration'] . '.']['additionalWhereClause']);
                 if (empty($record)) {
                     $writeToIndex = FALSE;
                 }
             }
             if ($writeToIndex) {
                 $GLOBALS['TYPO3_DB']->exec_INSERTquery('tx_solr_indexqueue_item', $item);
             }
         }
     }
 }
Пример #13
0
 /**
  *
  *
  */
 private function executeQuery()
 {
     $this->queryExecuted = true;
     $solrConnection = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('tx_solr_ConnectionManager')->getConnection();
     $search = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('tx_solr_Search', $solrConnection);
     $query = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('tx_solr_Query', $this->getKeywords());
     $solrConfiguration = \tx_solr_Util::getSolrConfiguration();
     $query->setFieldList($this->getFieldList());
     if ($this->hasSorting()) {
         $sortArray = $this->sorting;
         // Handle the case where the sorting array is like array('field', 'asc') instead of array('field' => 'asc')
         if (count($sortArray) == 2 && is_numeric(key($sortArray))) {
             $sortArray = array($sortArray[0] => $sortArray[1]);
         }
         $sorts = array();
         foreach ($sortArray as $field => $dir) {
             if ($dir != \tx_solr_Query::SORT_DESC && $dir != \tx_solr_Query::SORT_ASC) {
                 $dir = \tx_solr_Query::SORT_ASC;
                 // an implicit default
             }
             $sorts[] = "{$field} " . strtolower($dir);
         }
         $query->setSorting(implode(',', $sorts));
     }
     if ($this->boostQuery) {
         $query->setBoostQuery($this->boostQuery);
     }
     // Get default filters from the SOLR search configuration
     if (isset($solrConfiguration['search.']['query.']['filter.']) && is_array($solrConfiguration['search.']['query.']['filter.'])) {
         $defaultFilters = array();
         foreach ($solrConfiguration['search.']['query.']['filter.'] as $searchFilter) {
             $parts = explode(':', $searchFilter);
             $defaultFilters[$parts[0]] = $parts[1];
         }
         // Calling this will trigger any subclasses that may need to make modifications
         $this->setFilters($defaultFilters);
     }
     foreach ($this->filters as $filter) {
         $query->addFilter($filter);
     }
     $this->response = $search->search($query, $this->getQueryOffset(), $this->getQueryLimit());
     $this->body = json_decode($this->response->getRawResponse());
     $this->search = $search;
     $this->query = $query;
     $this->numFound = $this->body->response->numFound;
 }
 /**
  * Creates a Solr document for a project
  *
  * @param	stdClass	$project A Redmine project
  * @return	Apache_Solr_Document	The Solr document representation for the project
  */
 protected function projectToDocument($project)
 {
     $document = t3lib_div::makeInstance('Apache_Solr_Document');
     $site = t3lib_div::makeInstance('tx_solr_Site', $this->solrServer['rootPageUid']);
     // system fields
     $document->setField('id', tx_solr_Util::getDocumentId(self::ITEM_TYPE_PROJECT, $this->solrServer['rootPageUid'], $project->id));
     $document->setField('appKey', 'EXT:solr_redmine');
     $document->setField('type', self::ITEM_TYPE_PROJECT);
     $document->setField('siteHash', $site->getSiteHash());
     // content fields
     $document->setField('uid', $project->id);
     $document->setField('pid', $this->solrServer['rootPageUid']);
     $document->setField('title', $project->name);
     $document->setField('content', $project->description);
     $document->setField('created', $this->getIsoDateFromProjectDate($project->created_on));
     $document->setField('changed', $this->getIsoDateFromProjectDate($project->updated_on));
     $document->setField('url', $this->redmineServer . 'projects/' . $project->identifier);
     $document->setField('identifier_stringS', $project->identifier);
     // typo3.org specific fields
     // FIXME These are #t3o specific fields,
     // for general purpose use/add a hook or TS configuration to provide additional fields
     $document->setField('site', 'http://forge.typo3.org');
     $document->setField('siteName_stringS', 'forge_t3o');
     $document->setField('language', 0);
     if (t3lib_div::isFirstPartOfStr($project->identifier, 'extension-')) {
         $extensionKey = substr($project->identifier, 10);
         $document->setField('extensionKey_stringS', $extensionKey);
     }
     return $document;
 }
 protected function getResultsPerPageSwitch()
 {
     $template = clone $this->parentPlugin->getTemplate();
     $template->workOnSubpart('results_per_page_switch');
     $configuration = tx_solr_Util::getSolrConfiguration();
     $resultsPerPageSwitchOptions = t3lib_div::intExplode(',', $configuration['search.']['results.']['resultsPerPageSwitchOptions']);
     $currentNumberOfResultsShown = $this->parentPlugin->getNumberOfResultsPerPage();
     $selectOptions = array();
     foreach ($resultsPerPageSwitchOptions as $option) {
         $selected = '';
         $selectedClass = '';
         if ($option == $currentNumberOfResultsShown) {
             $selected = ' selected="selected"';
             $selectedClass = ' class="currentNumberOfResults"';
         }
         $selectOptions[] = array('value' => $option, 'selected' => $selected, 'selectedClass' => $selectedClass, 'url' => $this->parentPlugin->pi_linkTP_keepPIvars_url(array('resultsPerPage' => $option)));
     }
     $template->addLoop('options', 'option', $selectOptions);
     $form = array('action' => $this->parentPlugin->pi_linkTP_keepPIvars_url());
     $template->addVariable('form', $form);
     return $template->render();
 }
Пример #16
0
 /**
  * Adds an item to the index queue.
  *
  * Not meant for public use.
  *
  * @param string $itemType The item's type, usually a table name.
  * @param string $itemUid The item's uid, usually an integer uid, could be a
  *      different value for non-database-record types.
  * @param string $indexingConfiguration The item's indexing configuration to use.
  *      Optional, overwrites existing / determined configuration.
  * @return void
  */
 private function addItem($itemType, $itemUid, $indexingConfiguration)
 {
     $additionalRecordFields = '';
     if ($itemType == 'pages') {
         $additionalRecordFields = ', doktype, uid';
     }
     $record = BackendUtility::getRecord($itemType, $itemUid, 'pid' . $additionalRecordFields);
     if (empty($record) || $itemType == 'pages' && !Tx_Solr_Util::isAllowedPageType($record)) {
         return;
     }
     if ($itemType == 'pages') {
         $rootPageId = Tx_Solr_Util::getRootPageId($itemUid);
     } else {
         $rootPageId = Tx_Solr_Util::getRootPageId($record['pid']);
     }
     if (Tx_Solr_Util::isRootPage($rootPageId)) {
         $item = array('root' => $rootPageId, 'item_type' => $itemType, 'item_uid' => $itemUid, 'changed' => $this->getItemChangedTime($itemType, $itemUid));
         if (!empty($indexingConfiguration)) {
             $indexingConfigurationList = array($indexingConfiguration);
         } else {
             $indexingConfigurationList = $this->getIndexingConfigurationsByItem($itemType, $itemUid, $rootPageId);
         }
         $solrConfiguration = tx_solr_Util::getSolrConfigurationFromPageId($rootPageId);
         // make a backup of the current item
         $baseItem = $item;
         foreach ($indexingConfigurationList as $indexingConfigurationCurrent) {
             $item = $baseItem;
             $item['indexing_configuration'] = $indexingConfigurationCurrent;
             $addItemToQueue = TRUE;
             // Ensure additionalWhereClause is applied.
             if (!empty($solrConfiguration['index.']['queue.'][$item['indexing_configuration'] . '.']['additionalWhereClause'])) {
                 $indexingConfigurationCheckRecord = BackendUtility::getRecord($itemType, $itemUid, 'pid' . $additionalRecordFields, ' AND ' . $solrConfiguration['index.']['queue.'][$item['indexing_configuration'] . '.']['additionalWhereClause']);
                 if (empty($indexingConfigurationCheckRecord)) {
                     // item does not match the indexing configuration's additionalWhereClause
                     $addItemToQueue = FALSE;
                 }
             }
             if ($addItemToQueue) {
                 $GLOBALS['TYPO3_DB']->exec_INSERTquery('tx_solr_indexqueue_item', $item);
             }
         }
     }
 }
 /**
  * Resolves variables to marker. Markers can be simple markers like
  * ###MY_MARKER## or "nested" markers which devide their sub values by a
  * dot: ###MY_MARKER.MY_VALUE### ###MY_MARKER.MY_OTHER_VALUE###.
  *
  * @param	array	array with markers to resolve
  * @param	mixed	the marker's value, which can be an array of values, an object with certain getter methods or a simple string
  * @return	array	with marker as index and value for it
  */
 protected function resolveVariableMarkers(array $markers, $variableValue)
 {
     $resolvedMarkers = array();
     foreach ($markers as $marker) {
         $dotPosition = strpos($marker, '.');
         if ($dotPosition !== FALSE) {
             $resolvedValue = NULL;
             // the marker contains a dot, thus we have to resolve the
             // second part of the marker
             $valueSelector = substr($marker, $dotPosition + 1);
             $valueSelector = $this->normalizeString($valueSelector);
             if (is_array($variableValue)) {
                 $normalizedKeysArray = array();
                 foreach ($variableValue as $key => $value) {
                     $key = $this->normalizeString($key);
                     $normalizedKeysArray[$key] = $value;
                 }
                 if (array_key_exists($valueSelector, $normalizedKeysArray)) {
                     $resolvedValue = $normalizedKeysArray[$valueSelector];
                 }
             } else {
                 if (is_object($variableValue)) {
                     $resolveMethod = 'get' . tx_solr_Util::camelize($valueSelector);
                     $resolvedValue = $variableValue->{$resolveMethod}();
                 }
             }
         } else {
             $resolvedValue = $variableValue[strtolower($marker)];
         }
         if (is_null($resolvedValue)) {
             if ($this->debugMode) {
                 $resolvedValue = '!!! Marker "' . $marker . '" could not be resolved.';
             } else {
                 $resolvedValue = '';
             }
         }
         $resolvedMarkers[$marker] = $resolvedValue;
     }
     return $resolvedMarkers;
 }
 /**
  * Given a page id, returns a document representing that page.
  *
  * @return	Apache_Solr_Document	A documment representing the page
  */
 protected function getPageDocument()
 {
     $document = t3lib_div::makeInstance('Apache_Solr_Document');
     $cHash = $this->filterInvalidContentHash($this->page->cHash);
     $pageRecord = $this->page->page;
     self::$pageSolrDocumentId = $documentId = tx_solr_Util::getPageDocumentId($this->page->id, $this->page->type, $this->page->sys_language_uid, $this->getDocumentIdGroups(), $cHash);
     $document->setField('id', $documentId);
     // system fields
     //			2011-08-15T14:18:54.851Z
     $document->setField('date_creation', date("Y-m-d\\TH:i:s\\Z", $pageRecord['crdate']));
     !empty($pageRecord['starttime']) ? $document->setField('date_online', date("Y-m-d\\TH:i:s\\Z", $pageRecord['starttime'])) : '';
     !empty($pageRecord['endtime']) ? $document->setField('date_offline', date("Y-m-d\\TH:i:s\\Z", $pageRecord['endtime'])) : '';
     $document->setField('date_updated', date("Y-m-d\\TH:i:s\\Z", $pageRecord['tstamp']));
     // access
     if ($this->page->page['endtime']) {
         $document->setField('date_offline', $pageRecord['endtime']);
     }
     // content
     $document->setField('title', $this->utf8encode($this->contentExtractor->getPageTitle()));
     $document->setField('subtitle', addslashes($this->utf8encode($pageRecord['subtitle'])));
     $document->setField('summary', !empty($pageRecord['description']) ? $this->utf8encode($pageRecord['description']) : substr($this->contentExtractor->getIndexableContent(), 0, 210));
     $document->setField('body', addslashes($this->contentExtractor->getIndexableContent()));
     $document->setField('deeplink', $this->pageUrl);
     // keywords
     $keywords = array_unique(t3lib_div::trimExplode(',', $this->utf8encode($pageRecord['keywords'])));
     foreach ($keywords as $keyword) {
         $document->addField('keywords', $keyword);
     }
     return $document;
 }
 /**
  * Retrieves the filter parmeters from the url and adds an additional facet
  * to create a link to add additional facets to a search result.
  *
  * @param	string	$facetToAdd Facet filter to add to the filter parameters
  * @return	array	An array of filter parameters
  */
 protected function addFacetAndEncodeFilterParameters($facetToAdd)
 {
     $solrConfiguration = tx_solr_Util::getSolrConfiguration();
     $resultParameters = t3lib_div::_GPmerged('tx_solr');
     $filterParameters = array();
     if (isset($resultParameters['filter']) && !$solrConfiguration['search.']['faceting.']['singleFacetMode']) {
         $filterParameters = array_map('urldecode', $resultParameters['filter']);
     }
     $filterParameters[] = $facetToAdd;
     $filterParameters = array_unique($filterParameters);
     $filterParameters = array_map('urlencode', $filterParameters);
     return $filterParameters;
 }
 /**
  * constructor for class tx_solr_query_modifier_Faceting
  */
 public function __construct()
 {
     $this->configuration = tx_solr_Util::getSolrConfiguration();
 }