Skip to content

Instantly share code, notes, and snippets.

@anunay
Created February 13, 2014 14:34
Show Gist options
  • Save anunay/8976068 to your computer and use it in GitHub Desktop.
Save anunay/8976068 to your computer and use it in GitHub Desktop.
listcode
<?php
fuel_set_var("page_title","Search");
$results = array();
$search = $this->load->model('search_model');
$current_page = $this->input->get("page");
$rowLimit = $this->input->get("limit");
$tabsource = $this->input->get("tab-source");
$tabcat = $this->input->get("tab-category");
$parameters["qs"] = $this->input->get("qs");
$parameters["unit-type"] = $this->input->get("unit-type");
$parameters["min-bed"] = $this->input->get("min-bed");
$parameters["max-bed"] = $this->input->get("max-bed");
$parameters["min-price"] = $this->input->get("min-price");
$parameters["max-price"] = $this->input->get("max-price");
$parameters["current_page"] = (isset($current_page) && $current_page!="") ? $current_page : 1;
$parameters["offset"] = isset($offset)? $offset : 0;
$parameters["limit"] = (isset($rowLimit) && $rowLimit!="") ? $rowLimit : 12;
$parameters["sortby"] = $this->input->get("sortby");
$parameters['sort'] = $this->input->get("sort");
$parameters['tabcat'] = (isset($tabcat)) ? $tabcat : "sell";
$parameters["tab-source"] = isset($tabsource)? $tabsource : "sell";
$pagination = "";
if ($parameters["tab-source"]) {
$search->setPath($parameters["tab-source"]);
//$search->setOffset($parameters["current_page"]);
$search->setOffset($parameters["current_page"]);
$search->setLimit($parameters['limit']);
$q = "*:*";
$array_params = array();
/*
* If value from the open text field is not null
*/
if (!empty($parameters['qs'])) {
$q = "text:*" . $parameters['qs'] ."*";
}
// echo "QUERY : " . $q;
// echo "<br />";
$unit_type_arr = array(
"sell"=>array(
"Commercial"=>array('"Office Space"','"Full Floor"','"Villa"','"Commercial Building"'),
"Residential" => array('"Apartment"','"Full Floor"','"Villa"','"Commercial Building"') ,
"Industrial" => array("Labour Camp","Wearhouse"),
"Lands" => array('"Residential"','"Commercial"'),
"Hotels" => array('"Hotels"')
),
"rent"=>array(
"Commercial"=>array('"Office Space"','"Full Floor"','"Villa"','"Commercial Building"'),
"Residential" => array('"Apartment"','"Full Floor"','"Villa"','"Commercial Building"') ,
"Industrial" => array("Labour Camp","Wearhouse"),
"Lands" => array('"Residential"','"Commercial"'),
"Retail" => array("Shop","Showroom")
)
);
if (!empty($parameters["unit-type"])) {
$array_params = array('Category:"' . $parameters['unit-type'] . '"');
}else{
$cat_filter_arr = $unit_type_arr[$parameters["tab-source"]][$parameters['tabcat']];
$array_params = array("Category:" . implode(" Category:",$cat_filter_arr));
}
$array_params[] = "!Status:Blocked"; // filter Blocked status properties
$sortval = "Sellprice asc";
$defaultSortCol = "Sellprice";
if(strtolower($parameters['tab-source'])=="sell"){
$sortval = "Sellprice asc";
}else{
$sortval = "rent asc";
$defaultSortCol = "rent";
}
if(!empty($parameters["sortby"])){
$sortval = $parameters["sortby"] . " ";
if(!empty($parameters["sort"]) && in_array($parameters["sort"],array("asc","desc"))){
$sortval .= " " . $parameters["sort"];
}else{
$sortval .= " asc";
}
}
$sortColumn = (isset($parameters['sortby']) && !empty($parameters['sortby'])) ? @$parameters['sortby'] : $defaultSortCol;
$sortMode = (isset($parameters['sort']) && !empty($parameters['sort'])) ? @$parameters['sort'] : 'asc';
if (!empty($parameters['min-bed']) || !empty($parameters['max-bed'])) {
if ($parameters['min-bed'] != '' && $parameters['max-bed'] != '') {//if both minimum and maximum beds are selected
$array_params[] = "Bedrooms:[" . $parameters['min-bed'] . " TO " . $parameters['max-bed'] . "]";
// Returns values between two ranges
} elseif ($parameters['min-bed'] != '') {//If only minimum beds are selected
$array_params[] = "Bedrooms:[" . $parameters['min-bed'] . " TO *]";
// Minumum bed to any number of beds
} elseif ($parameters['max-bed'] != '') {//If only minimum beds are selected
$array_params[] = "Bedrooms:[* TO " . $parameters['max-bed'] . "]";
// Any minimum to a fixed max value
}
}
if (!empty($parameters['min-price']) || !empty($parameters['max-price'])) {
if ($parameters['min-price'] != '' && $parameters['max-price'] != '') {//if both minimum and maximum rent are selected
//print_r($array_params);
if($tabsource=="rent"){
$array_params[] = "rent:[" . $parameters['min-price'] . " TO " . $parameters['max-price'] . "]";
}else{
$array_params[] = "Sellprice:[" . $parameters['min-price'] . " TO " . $parameters['max-price'] . "]";
}
// Returns values between two ranges
} elseif ($parameters['min-price'] != '') {//If only minimum rent are selected
if($tabsource=="rent"){
$array_params[] = "rent:[" . $parameters['min-price'] . " TO *]";
}else{
$array_params[] = "Sellprice:[" . $parameters['min-price'] . " TO *]";
}
// Minumum rent to any rent
} elseif ($parameters['max-bed'] != '') {//If only minimum rent is selected
if($tabsource=="rent"){
$array_params[] = "rent:[* TO " . $parameters['max-price'] . "]";
}else{
$array_params[] = "Sellprice:[* TO " . $parameters['max-price'] . "]";
}
// Any minimum to a fixed max value
}
}
if (!empty($parameters['min-area']) || !empty($parameters['max-area'])) {
if ($parameters['min-area'] != '' && $parameters['max-area'] != '') {//if both minimum and maximum area are selected
$array_params[] = "Built_upArea:[" . $parameters['min-area'] . " TO " . $parameters['max-area'] . "]";
// Returns values between two ranges
} elseif ($parameters['min-area'] != '') {//If only minimum rent are selected
$array_params[] = "Built_upArea:[" . $parameters['min-area'] . " TO *]";
// Minumum area to any area
} elseif ($parameters['max-area'] != '') {//If only minimum rent is selected
$array_params[] = "Built_upArea:[* TO " . $parameters['max-area'] . "]";
// Any minimum to a fixed max value
}
}
//print_r($array_params);
$additionalParameters = array('fq' => $array_params, 'sort' => array($sortval), 'facet' => 'on', 'facet.mincount' => 1, 'facet.field' => array('propertyname'));
$search->setQuery($q);
print_r($additionalParameters);
// exit;
$search->setAdditionalParameters($additionalParameters);
$results = $search->list_items();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment