jquery autocomplete实现solr查询字段自动填充并执行查询

页面引入三个JS:

 
  1. <script type="text/javascript" src="js/jquery-1.7.2.js"></script>  
  2.         <script type="text/javascript" src="js/jquery-ui.js"></script>  
  3.                 <script type="text/javascript" src="js/json.js"></script>  

 
  1. 引入JQUERY UI的CSS文件  

 
  1. <link rel="stylesheet" href="css/redmond/jqstyle.css" type="text/css"></link></head>  


 
  1. $(function() {  
  2.       
  3.     function log( message ) {  
  4.             $( "<div/>" ).text( message ).prependTo( "#log" );  
  5.             $( "#log" ).scrollTop( 0 );  
  6.         }  
  7.       
  8.     //http://localhost:8088/solr-src/core0/suggest?q=so&wt=json  
  9.     //搜索引擎关键字自动填充  
  10.     $( "#city" ).autocomplete({  
  11.             source: function( request, response ) {  
  12.                 $.ajax({  
  13.                       
  14.                     url: "http://localhost:8088/solr-src/core0/suggest",  
  15.                     dataType: "json",  
  16.                     data: {  
  17.                         wt:"json",  
  18.                         q: request.term  
  19.                     },  
  20.                     success: function( data ) {  
  21.                           
  22.                         response(data.spellcheck.suggestions[1].suggestion)  
  23.                     /*  
  24.                         response( $.map( data, function( item ) {  
  25.                             return {  
  26.                                 label: item.username,  
  27.                                 value: item.username  
  28.                             }  
  29.                         }));  
  30.                     */    
  31.                     }  
  32.                 });  
  33.             },  
  34.             minLength: 2,//输入两个字符才会发送请求  
  35.               
  36.             select: function( event, ui ) {  
  37.                 log( ui.item ?  
  38.                     "Selected: " + ui.item.label :  
  39.                     "Nothing selected, input was " + this.value);  
  40.                 //执行搜索  
  41.                 $.getJSON("http://localhost:8088/solr-src/core0/select",  
  42.                 { "q": ui.item.label, "version": "2.2","start":0,"rows":10,"indent":"on","wt":"json" },  
  43.                  function(result) {  
  44.                  //显示搜索结果,这里简单显示json字符串  
  45.                  $("div#content").append(JSON.stringify(result.response.docs));  
  46.                   
  47.                   
  48.             });   
  49.                   
  50.             },  
  51.             open: function() {  
  52.                 $( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" );  
  53.             },  
  54.             close: function() {  
  55.                 $( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" );  
  56.             }  
  57.               
  58.         });  
  59. });  


 

html代码:


 
  1. <div class="ui-widget">  
  2.     <label for="city">Your city: </label>  
  3.     <input id="city" />  
  4. </div>  
  5.   
  6. <div class="ui-widget" style="margin-top:2em; font-family:Arial">  
  7.     Result:  
  8.     <div id="log" style="height: 200px; width: 300px; overflow: auto;" class="ui-widget-content"></div>  
  9. </div>  
  10.   
  11. </div>  


solrconfig.xml中配置拼写检查和自动补全组件:


 
  1. <searchComponent name="spellcheck" class="solr.SpellCheckComponent">  
  2.   
  3.     <str name="queryAnalyzerFieldType">textSpell</str>  
  4.   
  5.     <!-- Multiple "Spell Checkers" can be declared and used by this  
  6.          component  
  7.       -->  
  8.   
  9.     <!-- a spellchecker built from a field of the main index, and  
  10.          written to disk  
  11.       -->  
  12.     <lst name="spellchecker">  
  13.       <str name="name">default</str>  
  14.       <str name="field">name</str>  
  15.       <str name="buildOnCommit">true</str>  
  16.       <str name="spellcheckIndexDir">spellchecker</str>  
  17.       <!-- uncomment this to require terms to occur in 1% of the documents   
  18.            in order to be included in the dictionary  
  19.         -->  
  20.       <!-- 
  21.         <float name="thresholdTokenFrequency">.01</float> 
  22.       -->  
  23.     </lst>  
  24.   
  25.     <!-- a spellchecker that uses a different distance measure -->  
  26.     <!--  
  27.        <lst name="spellchecker">  
  28.          <str name="name">jarowinkler</str>  
  29.          <str name="field">spell</str>  
  30.          <str name="distanceMeasure">  
  31.            org.apache.lucene.search.spell.JaroWinklerDistance  
  32.          </str>  
  33.          <str name="spellcheckIndexDir">spellcheckerJaro</str>  
  34.        </lst>  
  35.      -->  
  36.   
  37.     <!-- a spellchecker that use an alternate comparator   
  38.   
  39.          comparatorClass be one of:  
  40.           1. score (default)  
  41.           2. freq (Frequency first, then score)  
  42.           3. A fully qualified class name  
  43.       -->  
  44.     <!--  
  45.        <lst name="spellchecker">  
  46.          <str name="name">freq</str>  
  47.          <str name="field">lowerfilt</str>  
  48.          <str name="spellcheckIndexDir">spellcheckerFreq</str>  
  49.          <str name="comparatorClass">freq</str>  
  50.          <str name="buildOnCommit">true</str>  
  51.       -->  
  52.   
  53.     <!-- A spellchecker that reads the list of words from a file -->  
  54.     <!--  
  55.        <lst name="spellchecker">  
  56.          <str name="classname">solr.FileBasedSpellChecker</str>  
  57.          <str name="name">file</str>  
  58.          <str name="sourceLocation">spellings.txt</str>  
  59.          <str name="characterEncoding">UTF-8</str>  
  60.          <str name="spellcheckIndexDir">spellcheckerFile</str>  
  61.        </lst>  
  62.       -->  
  63.   </searchComponent>  
  64.   
  65.   <!-- A request handler for demonstrating the spellcheck component.    
  66.   
  67.        NOTE: This is purely as an example.  The whole purpose of the  
  68.        SpellCheckComponent is to hook it into the request handler that  
  69.        handles your normal user queries so that a separate request is  
  70.        not needed to get suggestions.  
  71.   
  72.        IN OTHER WORDS, THERE IS REALLY GOOD CHANCE THE SETUP BELOW IS  
  73.        NOT WHAT YOU WANT FOR YOUR PRODUCTION SYSTEM!  
  74.          
  75.        See http://wiki.apache.org/solr/SpellCheckComponent for details  
  76.        on the request parameters.  
  77.     -->  
  78.        
  79.   <requestHandler name="/spell" class="solr.SearchHandler" startup="lazy">  
  80.     <lst name="defaults">  
  81.       <str name="df">text</str>  
  82.       <str name="spellcheck.onlyMorePopular">false</str>  
  83.       <str name="spellcheck.extendedResults">false</str>  
  84.       <str name="spellcheck.count">1</str>  
  85.     </lst>  
  86.     <arr name="last-components">  
  87.       <str>spellcheck</str>  
  88.     </arr>  
  89.   </requestHandler>  
  90.      
  91.       
  92.     <searchComponent class="solr.SpellCheckComponent" name="suggest">  
  93.     <lst name="spellchecker">  
  94.       <str name="name">suggest</str>  
  95.       <str name="classname">org.apache.solr.spelling.suggest.Suggester</str>  
  96.       <str name="lookupImpl">org.apache.solr.spelling.suggest.tst.TSTLookup</str>  
  97.       <!-- Alternatives to lookupImpl:   
  98.            org.apache.solr.spelling.suggest.fst.FSTLookup   [finite state automaton]  
  99.            org.apache.solr.spelling.suggest.fst.WFSTLookupFactory [weighted finite state automaton]  
  100.            org.apache.solr.spelling.suggest.jaspell.JaspellLookup [default, jaspell-based]  
  101.            org.apache.solr.spelling.suggest.tst.TSTLookup   [ternary trees]  
  102.       -->  
  103.       <str name="field">text</str>  <!-- the indexed field to derive suggestions from -->  
  104.       <float name="threshold">0.005</float>  
  105.       <str name="buildOnCommit">true</str>  
  106. <!-- 
  107.       <str name="sourceLocation">american-english</str> 
  108. -->  
  109.     </lst>  
  110.   </searchComponent>  
  111.   <requestHandler class="org.apache.solr.handler.component.SearchHandler" name="/suggest">  
  112.     <lst name="defaults">  
  113.       <str name="spellcheck">true</str>  
  114.       <str name="spellcheck.dictionary">suggest</str>  
  115.       <str name="spellcheck.onlyMorePopular">true</str>  
  116.       <str name="spellcheck.count">5</str>  
  117.       <str name="spellcheck.collate">true</str>  
  118.     </lst>  
  119.     <arr name="components">  
  120.       <str>suggest</str>  
  121.     </arr>  
  122.   </requestHandler>  


当输入so的时候,如下图:

当选择solr时,如下图:

提供了一个基于51单片机的RFID门禁系统的完整资源文件,包括PCB图、原理图、论文以及源程序。该系统设计由单片机、RFID-RC522频射卡模块、LCD显示、灯控电路、蜂鸣器报警电路、存储模块和按键组成。系统支持通过密码和刷卡两种方式进行门禁控制,灯亮表示开门成功,蜂鸣器响表示开门失败。 资源内容 PCB图:包含系统的PCB设计图,方便用户进行硬件电路的制作和调试。 原理图:详细展示了系统的电路连接和模块布局,帮助用户理解系统的工作原理。 论文:提供了系统的详细设计思路、实现方法以及测试结果,适合学习和研究使用。 源程序:包含系统的全部源代码,用户可以根据需要进行修改和优化。 系统功能 刷卡开门:用户可以通过刷RFID卡进行门禁控制,系统会自动识别卡片判断是否允许开门。 密码开门:用户可以通过输入预设密码进行门禁控制,系统会验证密码的正确性。 状态显示:系统通过LCD显示显示当前状态,如刷卡成功、密码错误等。 灯光提示:灯亮表示开门成功,灯灭表示开门失败或未操作。 蜂鸣器报警:当刷卡或密码输入错误时,蜂鸣器会发出报警声,提示用户操作失败。 适用人群 电子工程、自动化等相关专业的学生和研究人员。 对单片机和RFID技术感兴趣的爱好者。 需要开发类似门禁系统的工程师和开发者。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值