Revize 2334
Přidáno uživatelem Ondřej Fibich před více než 10 roky(ů)
freenetis/branches/1.2/application/controllers/search.php | ||
---|---|---|
// each rule should get oportunity to be searched (reserved limits)
|
||
$result_limit = !empty($limit) ? ceil($limit / count($search_rules)) : NULL;
|
||
|
||
$total_count = 0;
|
||
|
||
// foreach all search rules
|
||
foreach ($search_rules as $rule)
|
||
{
|
||
... | ... | |
$total_counts[$rule['model']] = 1;
|
||
}
|
||
|
||
$result = $search_model->{$rule['method']}($key, $result_limit);
|
||
$method_result_limit = ceil($result_limit * $rule['limit_weight']);
|
||
$result = $search_model->{$rule['method']}($key, $method_result_limit);
|
||
|
||
foreach ($result as $row)
|
||
{
|
||
... | ... | |
// add rating about the current result
|
||
$sums[$rule['model']][$row->id] += $percent * $weight;
|
||
$counts[$rule['model']][$row->id]++;
|
||
|
||
$total_count++;
|
||
|
||
// end if we have already enought results
|
||
if (!empty($limit) && $total_count >= $limit)
|
||
{
|
||
break 3;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
$result_sums = array();
|
||
$this->results = array();
|
||
|
||
// transforms to 1-dimensional array
|
||
foreach ($sums as $model => $model_sums)
|
freenetis/branches/1.2/application/models/search.php | ||
---|---|---|
* - weight: that defines importance of the property in system, these field
|
||
* is used for searching of results. Weight should be a non-negative
|
||
* number from interval (0, 10>
|
||
* - limit_weight: that may be use for rising number of searched results
|
||
* in the simple AJAX search
|
||
* - ignore_special_threatment: that defines whether weight can be changed
|
||
* if property equals to searched keyword [optional, default FALSE]
|
||
* - variation_enabled: enable variations of keyword for searching this
|
||
... | ... | |
'method' => 'member_name',
|
||
'model' => 'member',
|
||
'weight' => 5,
|
||
'limit_weight' => 2.5,
|
||
'variation_enabled' => TRUE,
|
||
'access' => array('Members_Controller', 'members')
|
||
),
|
||
... | ... | |
'method' => 'member_id',
|
||
'model' => 'member',
|
||
'weight' => 0.1,
|
||
'limit_weight' => 0.5,
|
||
'access' => array('Members_Controller', 'members')
|
||
),
|
||
array
|
||
... | ... | |
'method' => 'member_variable_symbol',
|
||
'model' => 'member',
|
||
'weight' => 0.1,
|
||
'limit_weight' => 0.5,
|
||
'access' => array('Members_Controller', 'members')
|
||
),
|
||
array
|
||
... | ... | |
'method' => 'member_comment',
|
||
'model' => 'member',
|
||
'weight' => 0.5,
|
||
'limit_weight' => 0.5,
|
||
'variation_enabled' => TRUE,
|
||
'access' => array('Members_Controller', 'members')
|
||
),
|
||
... | ... | |
'method' => 'member_town',
|
||
'model' => 'member',
|
||
'weight' => 0.4,
|
||
'limit_weight' => 1,
|
||
'ignore_special_threatment' => TRUE,
|
||
'variation_enabled' => TRUE,
|
||
'access' => array('Members_Controller', 'members')
|
||
... | ... | |
'method' => 'member_street',
|
||
'model' => 'member',
|
||
'weight' => 0.6,
|
||
'limit_weight' => 1,
|
||
'variation_enabled' => TRUE,
|
||
'access' => array('Members_Controller', 'members')
|
||
),
|
||
... | ... | |
'method' => 'member_street_number',
|
||
'model' => 'member',
|
||
'weight' => 0.1,
|
||
'limit_weight' => 1,
|
||
'access' => array('Members_Controller', 'members')
|
||
),
|
||
array
|
||
... | ... | |
'method' => 'member_organization_identifier',
|
||
'model' => 'member',
|
||
'weight' => 0.1,
|
||
'limit_weight' => 1,
|
||
'access' => array('Members_Controller', 'members')
|
||
),
|
||
array
|
||
... | ... | |
'method' => 'member_vat_organization_identifier',
|
||
'model' => 'member',
|
||
'weight' => 0.1,
|
||
'limit_weight' => 1,
|
||
'access' => array('Members_Controller', 'members')
|
||
),
|
||
array
|
||
... | ... | |
'method' => 'user_name',
|
||
'model' => 'user',
|
||
'weight' => 1,
|
||
'limit_weight' => 1,
|
||
'variation_enabled' => TRUE,
|
||
'access' => array('Users_Controller', 'show')
|
||
),
|
||
... | ... | |
'method' => 'user_login',
|
||
'model' => 'user',
|
||
'weight' => 0.5,
|
||
'limit_weight' => 1,
|
||
'access' => array('Members_Controller', 'members')
|
||
),
|
||
array
|
||
... | ... | |
'method' => 'user_contact',
|
||
'model' => 'user',
|
||
'weight' => 0.1,
|
||
'limit_weight' => 1,
|
||
'access' => array('Members_Controller', 'members')
|
||
),
|
||
array
|
||
... | ... | |
'method' => 'town_name',
|
||
'model' => 'town',
|
||
'weight' => 1,
|
||
'limit_weight' => 1,
|
||
'variation_enabled' => TRUE,
|
||
'access' => array('Address_points_Controller', 'town')
|
||
),
|
||
... | ... | |
'method' => 'device_name',
|
||
'model' => 'device',
|
||
'weight' => 1,
|
||
'limit_weight' => 1,
|
||
'variation_enabled' => TRUE,
|
||
'access' => array('Devices_Controller', 'devices')
|
||
),
|
||
... | ... | |
'method' => 'device_mac',
|
||
'model' => 'device',
|
||
'weight' => 0.5,
|
||
'limit_weight' => 1,
|
||
'access' => array('Devices_Controller', 'devices')
|
||
),
|
||
array
|
||
... | ... | |
'method' => 'device_ip_address',
|
||
'model' => 'device',
|
||
'weight' => 0.5,
|
||
'limit_weight' => 1,
|
||
'access' => array('Devices_Controller', 'devices')
|
||
),
|
||
array(
|
||
'method' => 'device_ssid',
|
||
'model' => 'device',
|
||
'weight' => 0.5,
|
||
'limit_weight' => 1,
|
||
'access' => array('Devices_Controller', 'devices')
|
||
),
|
||
array
|
||
... | ... | |
'method' => 'subnet_name',
|
||
'model' => 'subnet',
|
||
'weight' => 1,
|
||
'limit_weight' => 1,
|
||
'variation_enabled' => TRUE,
|
||
'access' => array('Subnets_Controller', 'subnet')
|
||
),
|
||
... | ... | |
'method' => 'subnet_address',
|
||
'model' => 'subnet',
|
||
'weight' => 1,
|
||
'limit_weight' => 1,
|
||
'access' => array('Subnets_Controller', 'subnet')
|
||
),
|
||
array
|
||
... | ... | |
'method' => 'link_name',
|
||
'model' => 'link',
|
||
'weight' => 1,
|
||
'limit_weight' => 1,
|
||
'variation_enabled' => TRUE,
|
||
'access' => array('Links_Controller', 'link')
|
||
),
|
||
... | ... | |
CONCAT(IFNULL(t.translated_term,e.value),' ',m.name,IF(mf.id IS NOT NULL,?,'')) AS return_value,
|
||
'members/show/' AS link FROM members m
|
||
JOIN enum_types e ON m.type = e.id
|
||
LEFT JOIN translations t ON e.value LIKE t.original_term AND t.lang = 'cs'
|
||
LEFT JOIN translations t ON e.value LIKE t.original_term AND t.lang = ?
|
||
JOIN address_points ap ON m.address_point_id = ap.id
|
||
JOIN streets s ON ap.street_id = s.id
|
||
JOIN towns tw ON ap.town_id = tw.id
|
||
LEFT JOIN membership_interrupts mi ON m.id = mi.member_id
|
||
LEFT JOIN members_fees mf ON mi.members_fee_id = mf.id AND (mf.activation_date < CURDATE() AND mf.deactivation_date > CURDATE())
|
||
WHERE m.name LIKE ? COLLATE utf8_general_ci
|
||
GROUP BY m.id
|
||
ORDER BY ABS(LENGTH(value) - " . mb_strlen($keyword) . ")
|
||
".$sql_limit, array
|
||
(
|
||
" (" . __('I') . ")",
|
||
Config::get('lang'),
|
||
"%$keyword%"
|
||
));
|
||
}
|
||
... | ... | |
CONCAT(IFNULL(t.translated_term,e.value),' ',m.name,IF(mf.id IS NOT NULL,?,'')) AS return_value,
|
||
'members/show/' AS link FROM members m
|
||
JOIN enum_types e ON m.type = e.id
|
||
LEFT JOIN translations t ON e.value LIKE t.original_term AND t.lang = 'cs'
|
||
LEFT JOIN translations t ON e.value LIKE t.original_term AND t.lang = ?
|
||
JOIN address_points ap ON m.address_point_id = ap.id
|
||
LEFT JOIN streets s ON ap.street_id = s.id
|
||
JOIN towns tw ON ap.town_id = tw.id
|
||
LEFT JOIN membership_interrupts mi ON m.id = mi.member_id
|
||
LEFT JOIN members_fees mf ON mi.members_fee_id = mf.id AND (mf.activation_date < CURDATE() AND mf.deactivation_date > CURDATE())
|
||
WHERE m.id LIKE ? COLLATE utf8_general_ci
|
||
GROUP BY m.id
|
||
ORDER BY ABS(LENGTH(value) - " . mb_strlen($keyword) . ")
|
||
".$sql_limit, array
|
||
(
|
||
" (" . __('I') . ")",
|
||
Config::get('lang'),
|
||
"$keyword%"
|
||
));
|
||
}
|
||
... | ... | |
JOIN enum_types e ON m.type = e.id
|
||
LEFT JOIN accounts a ON a.member_id = m.id
|
||
LEFT JOIN variable_symbols vs ON vs.account_id = a.id
|
||
LEFT JOIN translations t ON e.value LIKE t.original_term AND t.lang = 'cs'
|
||
LEFT JOIN translations t ON e.value LIKE t.original_term AND t.lang = ?
|
||
JOIN address_points ap ON m.address_point_id = ap.id
|
||
LEFT JOIN streets s ON ap.street_id = s.id
|
||
JOIN towns tw ON ap.town_id = tw.id
|
||
LEFT JOIN membership_interrupts mi ON m.id = mi.member_id
|
||
LEFT JOIN members_fees mf ON mi.members_fee_id = mf.id AND (mf.activation_date < CURDATE() AND mf.deactivation_date > CURDATE())
|
||
WHERE vs.variable_symbol LIKE ? COLLATE utf8_general_ci
|
||
GROUP BY m.id
|
||
ORDER BY ABS(LENGTH(value) - " . mb_strlen($keyword) . ")
|
||
".$sql_limit, array
|
||
(
|
||
__('Variable symbol') . ": ",
|
||
" (" . __('I') . ")",
|
||
Config::get('lang'),
|
||
"$keyword%"
|
||
));
|
||
}
|
||
... | ... | |
CONCAT(IFNULL(t.translated_term,e.value),' ',m.name,IF(mf.id IS NOT NULL,?,'')) AS return_value,
|
||
'members/show/' AS link FROM members m
|
||
JOIN enum_types e ON m.type = e.id
|
||
LEFT JOIN translations t ON e.value LIKE t.original_term AND t.lang = 'cs'
|
||
LEFT JOIN translations t ON e.value LIKE t.original_term AND t.lang = ?
|
||
JOIN address_points ap ON m.address_point_id = ap.id
|
||
LEFT JOIN streets s ON ap.street_id = s.id
|
||
JOIN towns tw ON ap.town_id = tw.id
|
||
LEFT JOIN membership_interrupts mi ON m.id = mi.member_id
|
||
LEFT JOIN members_fees mf ON mi.members_fee_id = mf.id AND (mf.activation_date < CURDATE() AND mf.deactivation_date > CURDATE())
|
||
WHERE m.comment LIKE ? COLLATE utf8_general_ci
|
||
GROUP BY m.id
|
||
ORDER BY ABS(LENGTH(value) - " . mb_strlen($keyword) . ")
|
||
".$sql_limit, array
|
||
(
|
||
__('Comment') . ": ",
|
||
" (" . __('I') . ")",
|
||
Config::get('lang'),
|
||
"%$keyword%"
|
||
));
|
||
}
|
||
... | ... | |
CONCAT(IFNULL(t.translated_term,e.value),' ',m.name,IF(mf.id IS NOT NULL,?,'')) AS return_value,
|
||
'members/show/' AS link FROM members m
|
||
JOIN enum_types e ON m.type = e.id
|
||
LEFT JOIN translations t ON e.value LIKE t.original_term AND t.lang = 'cs'
|
||
LEFT JOIN translations t ON e.value LIKE t.original_term AND t.lang = ?
|
||
JOIN address_points ap ON m.address_point_id = ap.id
|
||
LEFT JOIN streets s ON ap.street_id = s.id
|
||
JOIN towns tw ON ap.town_id = tw.id
|
||
LEFT JOIN membership_interrupts mi ON m.id = mi.member_id
|
||
LEFT JOIN members_fees mf ON mi.members_fee_id = mf.id AND (mf.activation_date < CURDATE() AND mf.deactivation_date > CURDATE())
|
||
WHERE CONCAT(tw.town, IF(tw.quarter IS NOT NULL, CONCAT(' ', tw.quarter), '')) LIKE ? COLLATE utf8_general_ci
|
||
GROUP BY m.id
|
||
ORDER BY ABS(LENGTH(value) - " . mb_strlen($keyword) . ")
|
||
".$sql_limit, " (" . __('I') . ")", "%$keyword%");
|
||
".$sql_limit, " (" . __('I') . ")", Config::get('lang'), "%$keyword%");
|
||
}
|
||
|
||
/**
|
||
... | ... | |
CONCAT(IFNULL(t.translated_term,e.value),' ',m.name,IF(mf.id IS NOT NULL,?,'')) AS return_value,
|
||
'members/show/' AS link FROM members m
|
||
JOIN enum_types e ON m.type = e.id
|
||
LEFT JOIN translations t ON e.value LIKE t.original_term AND t.lang = 'cs'
|
||
LEFT JOIN translations t ON e.value LIKE t.original_term AND t.lang = ?
|
||
JOIN address_points ap ON m.address_point_id = ap.id
|
||
JOIN streets s ON ap.street_id = s.id
|
||
JOIN towns tw ON ap.town_id = tw.id
|
||
LEFT JOIN membership_interrupts mi ON m.id = mi.member_id
|
||
LEFT JOIN members_fees mf ON mi.members_fee_id = mf.id AND (mf.activation_date < CURDATE() AND mf.deactivation_date > CURDATE())
|
||
WHERE CONCAT(s.street, ' ',ap.street_number) LIKE ? COLLATE utf8_general_ci
|
||
GROUP BY m.id
|
||
ORDER BY ABS(LENGTH(value) - " . mb_strlen($keyword) . ")
|
||
".$sql_limit, " (" . __('I') . ")", "%$keyword%");
|
||
".$sql_limit, " (" . __('I') . ")", Config::get('lang'), "%$keyword%");
|
||
}
|
||
|
||
/**
|
||
... | ... | |
CONCAT(IFNULL(t.translated_term,e.value),' ',m.name,IF(mf.id IS NOT NULL,?,'')) AS return_value,
|
||
'members/show/' AS link FROM members m
|
||
JOIN enum_types e ON m.type = e.id
|
||
LEFT JOIN translations t ON e.value LIKE t.original_term AND t.lang = 'cs'
|
||
LEFT JOIN translations t ON e.value LIKE t.original_term AND t.lang = ?
|
||
JOIN address_points ap ON m.address_point_id = ap.id
|
||
LEFT JOIN streets s ON ap.street_id = s.id
|
||
JOIN towns tw ON ap.town_id = tw.id
|
||
LEFT JOIN membership_interrupts mi ON m.id = mi.member_id
|
||
LEFT JOIN members_fees mf ON mi.members_fee_id = mf.id AND (mf.activation_date < CURDATE() AND mf.deactivation_date > CURDATE())
|
||
WHERE ap.street_number LIKE ? COLLATE utf8_general_ci
|
||
GROUP BY m.id
|
||
ORDER BY ABS(LENGTH(value) - " . mb_strlen($keyword) . ")
|
||
".$sql_limit, " (" . __('I') . ")", "$keyword%");
|
||
".$sql_limit, " (" . __('I') . ")", Config::get('lang'), "$keyword%");
|
||
}
|
||
|
||
/**
|
||
... | ... | |
CONCAT(IFNULL(t.translated_term,e.value),' ',m.name,IF(mf.id IS NOT NULL,?,'')) AS return_value,
|
||
'members/show/' AS link FROM members m
|
||
JOIN enum_types e ON m.type = e.id
|
||
LEFT JOIN translations t ON e.value LIKE t.original_term AND t.lang = 'cs'
|
||
LEFT JOIN translations t ON e.value LIKE t.original_term AND t.lang = ?
|
||
JOIN address_points ap ON m.address_point_id = ap.id
|
||
LEFT JOIN streets s ON ap.street_id = s.id
|
||
JOIN towns tw ON ap.town_id = tw.id
|
||
LEFT JOIN membership_interrupts mi ON m.id = mi.member_id
|
||
LEFT JOIN members_fees mf ON mi.members_fee_id = mf.id AND (mf.activation_date < CURDATE() AND mf.deactivation_date > CURDATE())
|
||
WHERE m.organization_identifier LIKE ? COLLATE utf8_general_ci
|
||
GROUP BY m.id
|
||
ORDER BY ABS(LENGTH(value) - " . mb_strlen($keyword) . ")
|
||
".$sql_limit, array
|
||
(
|
||
" (" . __('I') . ")",
|
||
Config::get('lang'),
|
||
"$keyword%"
|
||
));
|
||
}
|
||
... | ... | |
CONCAT(IFNULL(t.translated_term,e.value),' ',m.name,IF(mf.id IS NOT NULL,?,'')) AS return_value,
|
||
'members/show/' AS link FROM members m
|
||
JOIN enum_types e ON m.type = e.id
|
||
LEFT JOIN translations t ON e.value LIKE t.original_term AND t.lang = 'cs'
|
||
LEFT JOIN translations t ON e.value LIKE t.original_term AND t.lang = ?
|
||
JOIN address_points ap ON m.address_point_id = ap.id
|
||
LEFT JOIN streets s ON ap.street_id = s.id
|
||
JOIN towns tw ON ap.town_id = tw.id
|
||
LEFT JOIN membership_interrupts mi ON m.id = mi.member_id
|
||
LEFT JOIN members_fees mf ON mi.members_fee_id = mf.id AND (mf.activation_date < CURDATE() AND mf.deactivation_date > CURDATE())
|
||
WHERE m.vat_organization_identifier LIKE ? COLLATE utf8_general_ci
|
||
GROUP BY m.id
|
||
ORDER BY ABS(LENGTH(value) - " . mb_strlen($keyword) . ")
|
||
".$sql_limit, array
|
||
(
|
||
" (" . __('I') . ")",
|
||
Config::get('lang'),
|
||
"$keyword%"
|
||
));
|
||
}
|
||
... | ... | |
LEFT JOIN users_contacts uc ON u.id = uc.user_id
|
||
LEFT JOIN contacts c ON uc.contact_id = c.id
|
||
LEFT JOIN enum_types e ON c.type = e.id
|
||
LEFT JOIN translations t ON e.value LIKE t.original_term AND t.lang = 'cs'
|
||
LEFT JOIN translations t ON e.value LIKE t.original_term AND t.lang = ?
|
||
WHERE c.value LIKE ? COLLATE utf8_general_ci
|
||
ORDER BY ABS(LENGTH(c.value) - " . mb_strlen($keyword) . ")
|
||
".$sql_limit, __('User') . ": ", "%$keyword%");
|
||
".$sql_limit, __('User') . ": ", Config::get('lang'), "%$keyword%");
|
||
}
|
||
|
||
/**
|
Také k dispozici: Unified diff
Merge oprav z trunku:
- vyhledavani nebylo internacionalizovano u enum typu (v SQL dotazech bylo natvrdo 'cs')
- fixes #913: Chybne vynechani vysledku s velkou vahou ve fulltextovem vyhledavani (reseno vahou pro limit vysledku z AJAXoveho vyhledavani)
- oprava shlukovani vyhledavani u vyhledavani spojeneho se clenem