BUG 0000 "Change on class.AppSolr search criteria" CHANGE

This commit is contained in:
Freddy Daniel Rojas Valda
2013-07-03 15:05:14 -04:00
parent 6924836281
commit 8df85522b0

View File

@@ -1171,59 +1171,56 @@ class AppSolr
} }
// validate phrase in case of date // validate phrase in case of date
if (($searchText [1] == "[")) { if (($searchText [1] == "["))
{
// validate date range format // validate date range format
// use regular expresion to validate it [yyyy-mm-dd TO yyyy-mm-dd] // use regular expresion to validate it [yyyy-mm-dd TO yyyy-mm-dd]
$reg = "/:\[(\d\d\d\d-\d\d-\d\d|\*)\sTO\s(\d\d\d\d-\d\d-\d\d|\*)\]/"; $result1 = strpos($searchText, '-');
// convert date to utc if ($result1 !== false)
$matched = preg_match ($reg, $searchText, $matches); {
if ($matched == 1) { $reg = "/:\[(\d\d\d\d-\d\d-\d\d|\*)\sTO\s(\d\d\d\d-\d\d-\d\d|\*)\]/";
// the date interval is valid // convert date to utc
// convert to SOlr format $matched = preg_match ($reg, $searchText, $matches);
$fromDateOriginal = $matches [1]; if ($matched == 1)
$fromDate = $matches [1]; {
// the date interval is valid
$toDateOriginal = $matches [2]; // convert to SOlr format
$toDate = $matches [2]; $fromDateOriginal = $matches [1];
$fromDate = $matches [1];
if ($fromDateOriginal != '*') { $toDateOriginal = $matches [2];
// TODO complete date creation $toDate = $matches [2];
// list($year, $month, $day) = sscanf($fromDateOriginal, if ($fromDateOriginal != '*')
// '%04d/%02d/%02d'); {
// $fromDateDatetime = new DateTime($fromDateOriginal); $fromDate = gmdate ("Y-m-d\T00:00:00\Z", strtotime ($fromDateOriginal));
// $fromDateDatetime = date_create_from_format ( 'Y-m-d', }
// $fromDateOriginal ); if ($toDateOriginal != '*')
// $fromDateDatetime->getTimestamp () {
$fromDate = gmdate ("Y-m-d\T00:00:00\Z", strtotime ($fromDateOriginal)); // list($year, $month, $day) = sscanf($fromDateOriginal,
} // '%04d/%02d/%02d');
if ($toDateOriginal != '*') { // $toDateDatetime = new DateTime($toDateOriginal);
// list($year, $month, $day) = sscanf($fromDateOriginal, // $toDateDatetime = date_create_from_format ( 'Y-m-d',
// '%04d/%02d/%02d'); // $toDateOriginal );
// $toDateDatetime = new DateTime($toDateOriginal); $toDate = gmdate ("Y-m-d\T23:59:59.999\Z", strtotime ($toDateOriginal));
// $toDateDatetime = date_create_from_format ( 'Y-m-d', }
// $toDateOriginal ); $searchText = ":[" . $fromDate . " TO " . $toDate . "]";
$toDate = gmdate ("Y-m-d\T23:59:59.999\Z", strtotime ($toDateOriginal)); }
} }
$searchText = ":[" . $fromDate . " TO " . $toDate . "]";
} }
else {
throw new InvalidIndexSearchTextException ("Invalid search text. Expected date interval format => {variable_name}:[YYYY-MM-DD TO YYYY-MM-DD]");
}
}
// validate phrase in case of < and <= // validate phrase in case of < and <=
$result1 = strpos($searchText, '<'); $result1 = strpos($searchText, '<');
if($result1 !== false) if($result1 !== false)
{ {
$result = strpos($searchText, '<='); $result = strpos($searchText, '<=');
if($result !== false) if($result !== false)
{ {
$v1 = str_replace( '<=', '', $searchText ); $v1 = str_replace( '<=', '', $searchText );
$v2 = str_replace( ':', '', $v1); $v2 = str_replace( ':', '', $v1);
$v3 = str_replace( '<','' ,':[* TO '.$v2.']' ); $v3 = str_replace( '<','' ,':[* TO '.$v2.']' );
$searchText = $v3; $searchText = $v3;
} }
else { else
{
$v1 = str_replace( '<', '', $searchText ); $v1 = str_replace( '<', '', $searchText );
$v2 = str_replace( ':', '', $v1); $v2 = str_replace( ':', '', $v1);
$v3 = (int) $v2-1; $v3 = (int) $v2-1;
@@ -1237,30 +1234,21 @@ class AppSolr
{ {
$result = strpos($searchText, '>='); $result = strpos($searchText, '>=');
if($result !== false) if($result !== false)
{ {
$v1 = str_replace( '>=', '', $searchText ); $v1 = str_replace( '>=', '', $searchText );
$v2 = str_replace( ':', '', $v1); $v2 = str_replace( ':', '', $v1);
$v3 = str_replace( '>','' ,':['.$v2.' TO *]' ); $v3 = str_replace( '>','' ,':['.$v2.' TO *]' );
$searchText = $v3; $searchText = $v3;
} }
else { else
$v1 = str_replace( '>', '', $searchText ); {
$v2 = str_replace( ':', '', $v1 ); $v1 = str_replace( '>', '', $searchText );
$v3 = (int) $v2+1; $v2 = str_replace( ':', '', $v1 );
$v4 = str_replace( '>','' ,':['.$v3.' TO *]' ); $v3 = (int) $v2+1;
$searchText = $v4; $v4 = str_replace( '>','' ,':['.$v3.' TO *]' );
} $searchText = $v4;
} }
// validate phrase in case of | }
$result2 = strpos($searchText, '|');
if($result2 !== false)
{
$v1 = str_replace( '|', ' TO ', $searchText );
$v2 = str_replace( ':', '', $v1 );
$v3 = str_replace( '','' ,':['.$v2.']' );
$searchText = $v3;
}
$formattedSearchText .= $indexFieldName . $searchText; $formattedSearchText .= $indexFieldName . $searchText;
$includeToken = true; $includeToken = true;
} }
@@ -1284,7 +1272,7 @@ class AppSolr
* @return array delegation records * @return array delegation records
*/ */
public function getApplicationDelegationsIndex($appUID) public function getApplicationDelegationsIndex($appUID)
{ {
$delIndexes = array (); $delIndexes = array ();
$c = new Criteria (); $c = new Criteria ();
@@ -3049,33 +3037,31 @@ class AppSolr
$trunk = $indexTrunkSize; $trunk = $indexTrunkSize;
if(!$this->isSolrEnabled()) if(!$this->isSolrEnabled())
throw new Exception(date('Y-m-d H:i:s:u') . " Error connecting to solr server."); throw new Exception(date('Y-m-d H:i:s:u') . " Error connecting to solr server.");
// delete all documents to begin reindex // delete all documents to begin reindex
// deleteAllDocuments(); // deleteAllDocuments();
// commitChanges(); // commitChanges();
// print "Deleted all documents \n"; // print "Deleted all documents \n";
// search trunks of id's to regenerate index // search trunks of id's to regenerate index
$numRows = $this->getCountApplicationsPMOS2 (); $numRows = $this->getCountApplicationsPMOS2 ();
print "Total number of records: " . $numRows . "\n"; print "Total number of records: " . $numRows . "\n";
// //
$initTimeAll = microtime (true); $initTimeAll = microtime (true);
for ($skip = $SkipRecords; $skip <= $numRows;) { for ($skip = $SkipRecords; $skip <= $numRows;) {
$aaAPPUIds = $this->getPagedApplicationUids ($skip, $trunk); $aaAPPUIds = $this->getPagedApplicationUids ($skip, $trunk);
printf ("Indexing %d to %d \n", $skip, $skip + $trunk);
printf ("Indexing %d to %d \n", $skip, $skip + $trunk); $initTimeDoc = microtime (true);
$initTimeDoc = microtime (true); $this->updateApplicationSearchIndex ($aaAPPUIds, false);
$this->updateApplicationSearchIndex ($aaAPPUIds, false); $curTimeDoc = gmdate ('H:i:s', (microtime (true) - $initTimeDoc));
printf ("Indexing document time: %s \n", $curTimeDoc);
$curTimeDoc = gmdate ('H:i:s', (microtime (true) - $initTimeDoc)); $skip += $trunk;
printf ("Indexing document time: %s \n", $curTimeDoc);
$skip += $trunk;
} }
$curTimeDoc = gmdate ('H:i:s', (microtime (true) - $initTimeAll));
$curTimeDoc = gmdate ('H:i:s', (microtime (true) - $initTimeAll)); printf ("Total reindex time: %s \n", $curTimeDoc);
printf ("Total reindex time: %s \n", $curTimeDoc); printf ("Reindex completed successfully!!.\n");
printf ("Reindex completed successfully!!.\n");
} }
} }