5

autocompleter検索にはjQueryを使用しています。

以下のコードから、検索は大文字と小文字を区別する場合にのみ行われます。大文字と小文字を区別しない検索を行います。例えば。$array={the king, The king, The man}

そして、私の検索キーワードは「The」であり、現在、小文字であるため{The king, The man} 取得していないような出力のみを取得しています。the king

私が欲しいのは、「the」と書くと、3つの結果すべてが得られるはずです。

私の問題を解決するのを手伝ってください

view.php

<script type="text/javascript">
$(document).ready(function() {
        $(function() {
                $( "#autocomplete" ).autocomplete({


                        source: function(request, response) {

                     $.ajax({ url: "<?php echo base_url().'search/suggestions'?>",
                                data: { term: $("#autocomplete").val()},
                                dataType: "json",
                                type: "POST",
                                success: function(data){

                                        response(data);
                                }
                        });
                },

                minLength: 3,
                select: function (a, b) {
    $(this).val(b.item.value);
    $(".searchform1").submit()
}
                });
        });
        $('#autocomplete').focus(); 
});


  function monkeyPatchAutocomplete() {

      // Don't really need to save the old fn, 
      // but I could chain if I wanted to
      var oldFn = $.ui.autocomplete.prototype._renderItem;

      $.ui.autocomplete.prototype._renderItem = function( ul, item) {
          var re = new RegExp("^" + this.term, "i") ;
          var t = item.label.replace(re,"<span style='font-weight:bold;color:Black;'>" + this.term + "</span>");
          return $( "<li></li>" )
              .data( "item.autocomplete", item )
              .append( "<a>" + t + "</a>" )
              .appendTo( ul );
      };
  }


  $(document).ready(function() {

      monkeyPatchAutocomplete();

      $("#input1").autocomplete({
          // The source option can be an array of terms.  In this case, if
          // the typed characters appear in any position in a term, then the
          // term is included in the autocomplete list.
          // The source option can also be a function that performs the search,
          // and calls a response function with the matched entries.
          source: function(req, responseFn) {
              addMessage("search on: '" + req.term + "'<br/>");
              var re = $.ui.autocomplete.escapeRegex(req.term);
              var matcher = new RegExp( "^" + re, "i" );
              var a = $.grep( wordlist, function(item,index){
                  //addMessage("&nbsp;&nbsp;sniffing: '" + item + "'<br/>");
                  return matcher.test(item);
              });
              addMessage("Result: " + a.length + " items<br/>");
              responseFn( a );
          },

          select: function(value, data){
              if (typeof data == "undefined") {
                  addMessage('You selected: ' + value + "<br/>");
              }else {
                  addMessage('You selected: ' + data.item.value + "<br/>");
              }
          }
      });
  });
</script>
     ---------------
     ---------------
        <form class="searchform1" action="<?php echo base_url().'search/searchresult/pgn/grid/'?>" method="POST"> 
                        <img src="<?php echo base_url()?>css/images/icons/searchicon.png" style="vertical-align:middle;"/>  
                        <input id="autocomplete" value="<?php  if(isset($srchvalue)){echo $srchvalue ;} ?>" class="deletable"   type="text" name="keywords" style="height: 30px;width: 450px;font-size: 16px;border: 0;border-bottom:solid 4px #dfdfdf;border-top:solid 4px #dfdfdf;"  maxlength="70" placeholder="  Search for Title, Author Name, Isbn , Publisher"/>

                        <input type="submit" value="&nbsp;&nbsp;Search&nbsp;&nbsp;" class="searchbtn"/>
       </form> 
4

2 に答える 2

4

同様の演算子をたくさん使用しないでください。全文検索はその方法です。デフォルトでは、完全な txtsearch は大文字と小文字を区別しません。したがって、問題はありません。

mysql フルテキストを codeigniter と統合する方法は次のとおりです。

MySQL と CodeIgniter で Match と Against を使用する

于 2013-03-09T04:49:11.143 に答える
0

テーブルで大文字と小文字を区別する照合を意図的に使用していますか? 大文字と小文字を区別しない照合に変更すると、問題が解決します。別の解決策は、文字列を小文字 (または大文字) で一致させることです。このようなもの:

$this->db->or_like('LOWER(auth_lastname)', strtolower($keyword));

また、mysqlのストレージエンジンとしてInnoDBを使用すると全文検索ができません

于 2013-03-10T11:35:12.137 に答える