Changeset 27884


Ignore:
Timestamp:
Mar 23, 2014, 6:38:05 AM (6 years ago)
Author:
rvelices
Message:

bug 3056: quick search

  • added inflectors for english and french languages
  • current quick search is kept in the quick search input box
  • small fixes
Location:
trunk
Files:
3 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/functions_search.inc.php

    r27882 r27884  
    593593  var $images_iids;
    594594  var $iids;
     595
     596  var $variants;
    595597}
    596598
     
    599601  //@TODO: inflections for english / french
    600602  $qsr->images_iids = array_fill(0, count($expr->tokens), array());
     603
     604  $inflector = null;
     605  $lang_code = substr(get_default_language(),0,2);
     606  include_once(PHPWG_ROOT_PATH.'include/inflectors/'.$lang_code.'.php');
     607  $class_name = 'Inflector_'.$lang_code;
     608  if (class_exists($class_name))
     609  {
     610    $inflector = new $class_name;
     611  }
     612
    601613  $query_base = 'SELECT id from '.IMAGES_TABLE.' i WHERE ';
    602614  for ($i=0; $i<count($expr->stokens); $i++)
     
    608620    $like = str_replace( array('%','_'), array('\\%','\\_'), $like); // escape LIKE specials %_
    609621    $clauses[] = 'CONVERT(file, CHAR) LIKE \'%'.$like.'%\'';
     622
     623    if ($inflector!=null && strlen($token)>2
     624      && ($expr->stoken_modifiers[$i] & (QST_QUOTED|QST_WILDCARD))==0
     625      && strcspn($token, '\'0123456789') == strlen($token)
     626      )
     627    {
     628      $variants = array_unique( array_diff( $inflector->get_variants($token), array($token) ) );
     629      $qsr->variants[$token] = $variants;
     630    }
     631    else
     632    {
     633      $variants = array();
     634    }
    610635
    611636    if (strlen($token)>3) // default minimum full text index
     
    616641      if ($expr->stoken_modifiers[$i] & QST_WILDCARD_END)
    617642        $ft .= '*';
     643      foreach ($variants as $variant)
     644      {
     645        $ft.=' '.$variant;
     646      }
    618647      $clauses[] = 'MATCH(i.name, i.comment) AGAINST( \''.addslashes($ft).'\' IN BOOLEAN MODE)';
    619648    }
     
    622651      foreach( array('i.name', 'i.comment') as $field)
    623652      {
    624         $clauses[] = $field.' LIKE \''.$like.' %\'';
     653        /*$clauses[] = $field.' LIKE \''.$like.' %\'';
    625654        $clauses[] = $field.' LIKE \'% '.$like.'\'';
    626         $clauses[] = $field.' LIKE \'% '.$like.' %\'';
     655        $clauses[] = $field.' LIKE \'% '.$like.' %\'';*/
     656        $clauses[] = $field.' REGEXP \'[[:<:]]'.addslashes(preg_quote($token)).'[[:>:]]\'';
    627657      }
    628658    }
     
    754784        $tag_id = $token_tag_ids[$i][$j];
    755785        $counter += $all_tags[$tag_id]['counter'];
    756         if ($counter > 200 && $j>0 && $token_tag_scores[$i][0] > $token_tag_scores[$i][$j] )
    757         {// "many" images in previous tags and starting from this tag is less relevent
     786        if ( $j>0 && (
     787          ($counter > 100 && $token_tag_scores[$i][0] > $token_tag_scores[$i][$j]) // "many" images in previous tags and starting from this tag is less relevant
     788          || ($token_tag_scores[$i][0]==1 && $token_tag_scores[$i][$j]<0.8)
     789          || ($token_tag_scores[$i][0]>0.8 && $token_tag_scores[$i][$j]<0.5)
     790          ))
     791        {// we remove this tag from the results, but we still leave it in all_tags list so that if we are wrong, the user chooses it
    758792          array_splice($token_tag_ids[$i], $j);
    759793          array_splice($token_tag_scores[$i], $j);
     
    865899  global $conf;
    866900  //@TODO: maybe cache for 10 minutes the result set to avoid many expensive sql calls when navigating the pictures
     901  $q = trim(stripslashes($q));
    867902  $search_results =
    868903    array(
    869904      'items' => array(),
    870       'qs' => array('q'=>stripslashes($q)),
     905      'qs' => array('q'=>$q),
    871906    );
    872   $q = trim($q);
     907
    873908  $expression = new QExpression($q);
    874909//var_export($expression);
     
    885920  for ($i=0; $i<count($expression->stokens); $i++)
    886921  {
    887     $debug[] = $expression->stokens[$i].': '.count($qsr->tag_ids[$i]).' tags, '.count($qsr->tag_iids[$i]).' tiids, '.count($qsr->images_iids[$i]).' iiids, '.count($qsr->iids[$i]).' iids';
     922    $debug[] = $expression->stokens[$i].': '.count($qsr->tag_ids[$i]).' tags, '.count($qsr->tag_iids[$i]).' tiids, '.count($qsr->images_iids[$i]).' iiids, '.count($qsr->iids[$i]).' iids'
     923      .( !empty($qsr->variants[$expression->stokens[$i]]) ? ' variants: '.implode(', ',$qsr->variants[$expression->stokens[$i]]): '');
    888924  }
    889925  $debug[] = 'before perms '.count($ids);
  • trunk/index.php

    r27882 r27884  
    8686$template->assign('thumb_navbar', $page['navigation_bar'] );
    8787
     88if ( $page['section']=='search' and isset($page['qsearch_details']) )
     89{
     90  $template->assign('QUERY_SEARCH', htmlspecialchars($page['qsearch_details']['q']) );
     91}
     92
    8893// caddie filling :-)
    8994if (isset($_GET['caddie']))
     
    219224      !isset($page['chronology_field']) and isset($page['qsearch_details']) )
    220225  {
    221     $template->assign('QUERY_SEARCH',
    222       htmlspecialchars($page['qsearch_details']['q']) );
    223 
    224226    $cats = array_merge(
    225227        (array)@$page['qsearch_details']['matching_cats_no_images'],
  • trunk/themes/default/template/menubar_menu.tpl

    r21817 r27884  
    44        <form action="{$ROOT_URL}qsearch.php" method="get" id="quicksearch" onsubmit="return this.q.value!='' && this.q.value!=qsearch_prompt;">
    55                <p style="margin:0;padding:0"{*this <p> is for html validation only - does not affect positioning*}>
    6                         <input type="text" name="q" id="qsearchInput" onfocus="if (value==qsearch_prompt) value='';" onblur="if (value=='') value=qsearch_prompt;" style="width:90%">
     6                        <input type="text" name="q" id="qsearchInput" onfocus="if (value==qsearch_prompt) value='';" onblur="if (value=='') value=qsearch_prompt;" style="width:90%"{if !empty($QUERY_SEARCH)} value="{$QUERY_SEARCH}"{/if}>
    77                </p>
    88        </form>
    9         <script type="text/javascript">var qsearch_prompt="{'Quick search'|@translate|@escape:'javascript'}"; document.getElementById('qsearchInput').value=qsearch_prompt;</script>
     9        <script type="text/javascript">var qsearch_prompt="{'Quick search'|@translate|@escape:'javascript'}";{if empty($QUERY_SEARCH)}document.getElementById('qsearchInput').value=qsearch_prompt;{/if}</script>
    1010{/if}
    1111        <ul>{strip}
Note: See TracChangeset for help on using the changeset viewer.