#731 Full text search requires a string of at least three characters (configurable: full_text_needle_min)

SVN:trunk[3188]
This commit is contained in:
Romain Quetiez
2014-06-03 14:42:17 +00:00
parent e4bb0acd94
commit e8a7695353
5 changed files with 55 additions and 30 deletions

View File

@@ -535,8 +535,46 @@ try
}
else
{
// Sanity check of the accelerators
$iErrors = 0;
// Check if a class name/label is supplied to limit the search
$sClassName = '';
if (preg_match('/^([a-zA-Z]+):(.+)$/', $sFullText, $aMatches))
{
$sClassName = $aMatches[1];
if (MetaModel::IsValidClass($sClassName))
{
$sFullText = trim($aMatches[2]);
}
elseif ($sClassName = MetaModel::GetClassFromLabel($sClassName, false /* => not case sensitive */))
{
$sFullText = trim($aMatches[2]);
}
}
if (preg_match('/^"(.*)"$/', $sFullText, $aMatches))
{
// The text is surrounded by double-quotes, remove the quotes and treat it as one single expression
$aFullTextNeedles = array($aMatches[1]);
}
else
{
// Split the text on the blanks and treat this as a search for <word1> AND <word2> AND <word3>
$aFullTextNeedles = explode(' ', $sFullText);
}
// Check the needle length
$iMinLenth = MetaModel::GetConfig()->Get('full_text_needle_min');
foreach ($aFullTextNeedles as $sNeedle)
{
if (strlen($sNeedle) < $iMinLenth)
{
$oP->p(Dict::Format('UI:Search:NeedleTooShort', $sNeedle, $iMinLenth));
$iErrors++;
}
}
// Sanity check of the accelerators
$aAccelerators = MetaModel::GetConfig()->Get('full_text_accelerators');
foreach ($aAccelerators as $sClass => $aAccelerator)
{
@@ -568,10 +606,11 @@ try
$oP->add("<h2>".Dict::Format('UI:FullTextSearchTitle_Text', htmlentities($sFullText, ENT_QUOTES, 'UTF-8'))."</h2>");
$oP->add("</div>\n");
$oP->add("</div>\n");
$sJSNeedle = addslashes($sFullText);
$sJSClass = addslashes($sClassName);
$sJSNeedles = json_encode($aFullTextNeedles);
$oP->add_ready_script(
<<<EOF
var oParams = {operation: 'full_text_search', position: 0, text: '$sJSNeedle', tune: $iTune};
var oParams = {operation: 'full_text_search', position: 0, 'class': '$sJSClass', needles: $sJSNeedles, tune: $iTune};
$.post(GetAbsoluteUrlAppRoot()+'pages/ajax.render.php', oParams, function(data) {
$('#full_text_results').append(data);
});