Warning: curl_exec() has been disabled for security reasons in /pub/host/sunboyu/sunboyu/www/wp-includes/http.php on line 1022

Warning: Cannot modify header information - headers already sent by (output started at /pub/host/sunboyu/sunboyu/www/wp-includes/http.php:1022) in /pub/host/sunboyu/sunboyu/www/wp-includes/feed-rss2.php on line 8
一个程序猿 » Java http://www.sunboyu.cn 时光不会倒流,脚步总要前进 Tue, 31 Jan 2012 10:50:34 +0000 http://wordpress.org/?v=2.7 en hourly 1 Tokyo Cabinet table表的jsp接口 http://www.sunboyu.cn/2011/08/16/tokyo-cabinet-table%e8%a1%a8%e7%9a%84jsp%e6%8e%a5%e5%8f%a3.shtml http://www.sunboyu.cn/2011/08/16/tokyo-cabinet-table%e8%a1%a8%e7%9a%84jsp%e6%8e%a5%e5%8f%a3.shtml#comments Tue, 16 Aug 2011 06:50:22 +0000 admin http://www.sunboyu.cn/?p=1436 终于完成了Tokyo Cabinet的jsp接口,在tomcat下性能不是那么出众,看来性能还是得用c。

部署方法看上一偏配置说明。

代码 api.tar.gz

信息插入与修改:

  1. $data['database'] = "sunboyudata2";
  2. $jsondata = array();
  3. while($row = mysql_fetch_array($query,MYSQL_ASSOC)){
  4. $jsondata[] = $row;
  5. }
  6. $data['jsondata'] = json_encode($jsondata);
  7. $url= http_build_query($data );
  8. $postdate = array (
  9. 'http' => array (
  10. 'method' => 'POST',
  11. 'header'=> "Content-type: application/x-www-form-urlencoded\r\n" .
  12. "Content-Length: " . strlen($url) . "\r\n",
  13. 'content' => $url
  14. ),
  15. );
  16. $postcontent = stream_context_create($postdate);
  17. $return= file_get_contents('http://192.168.138.29:8080/api.jsp', false, $postcontent );

查询:

http://192.168.138.29:8080/search.jsp?database=sunboyudata2&query=fid:QCNUMEQ:1604&skip=20000&max=10

database:数据库文件名[无扩展名]
query:查询条件 每组查询条件三个部分 字段:规则:值 每组之间用|分割
skip:记录起始
max:返回的记录条数

缺点:在频繁大数据量提交的时候,tomcat总是影响失败。性能没有预期那么好,tc需要优化。

]]>
http://www.sunboyu.cn/2011/08/16/tokyo-cabinet-table%e8%a1%a8%e7%9a%84jsp%e6%8e%a5%e5%8f%a3.shtml/feed
linux下tokyocabinet存储引擎java接口的配置 http://www.sunboyu.cn/2011/08/12/linux%e4%b8%8btokyocabinet%e5%ad%98%e5%82%a8%e5%bc%95%e6%93%8ejava%e6%8e%a5%e5%8f%a3%e7%9a%84%e9%85%8d%e7%bd%ae.shtml http://www.sunboyu.cn/2011/08/12/linux%e4%b8%8btokyocabinet%e5%ad%98%e5%82%a8%e5%bc%95%e6%93%8ejava%e6%8e%a5%e5%8f%a3%e7%9a%84%e9%85%8d%e7%bd%ae.shtml#comments Fri, 12 Aug 2011 07:01:47 +0000 admin http://www.sunboyu.cn/?p=1432 tokyocabinet是一个性能极高的存储引擎,除支持传统的keyvalue存储外,还支持table表的存储,具体可以看这里 http://fallabs.com/tokyocabinet/spex-en.html#tctdbapi

使用tc常用的工具就是作者另外写的一个api:tt http://fallabs.com/tokyotyrant/ 兼容memcached协议,非常好用和高效。

但这里我期望使用的是table表,它提供了C的接口,但没有php方便调用的的方式,所以张宴同学做了一个很方便的tcsql http://blog.s135.com/tcsql/

因为我C的水平问题,一直没有写出稳定的操作接口,并且张宴同学tcsql的设计理念非常好,支持分布式的结构。

因此我改变了设计思路,并且使用我想对熟悉的java接口来做这个事情。

linux下配置过程:

环境装备:标准JDK环境

1、下载java api http://fallabs.com/tokyocabinet/javapkg/

2、解压后进入 tokyocabinet-java-1.24 目录

3、运行 ./configure –prefix=/opt/tcjava && make && make install

4、环境变量配置:
这里是包含JDK的全部配置

export JAVA_HOME=/opt/jdk
export CLASSPATH=.:$CLASSPATH:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:/opt/tcjava/lib/tokyocabinet.jar:/opt/tcjava/lib/libjtokyocabinet.so:/opt/tcjava/lib/
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/tcjava/lib/
export PATH=$PATH:$JAVA_HOME/bin
export JRE_HOME=$JAVA_HOME/jrei
JAVA_OPTS="-server"
JAVA_OPTS="$JAVA_OPTS -Xms64m -Xmx128m"
JAVA_OPTS="$JAVA_OPTS -D64 -Djava.library.path=/usr/local/lib/"

把以上代码增加到 /etc/profile 文件尾部,而后 source /etc/profile

配置完成,开始测试:

进入 tokyocabinet-java-1.24/example 执行 make

然后运行 java TCTDBEX 如果看到跟代码中预期的结果,则tc的javaapi在此服务器上安装成功。

]]>
http://www.sunboyu.cn/2011/08/12/linux%e4%b8%8btokyocabinet%e5%ad%98%e5%82%a8%e5%bc%95%e6%93%8ejava%e6%8e%a5%e5%8f%a3%e7%9a%84%e9%85%8d%e7%bd%ae.shtml/feed
android Activity之间传参 http://www.sunboyu.cn/2011/07/26/android-activity%e4%b9%8b%e9%97%b4%e4%bc%a0%e5%8f%82.shtml http://www.sunboyu.cn/2011/07/26/android-activity%e4%b9%8b%e9%97%b4%e4%bc%a0%e5%8f%82.shtml#comments Tue, 26 Jul 2011 05:40:59 +0000 admin http://www.sunboyu.cn/?p=1422 貌似跟网页不一样,没有get post了,但提供了这样的传参方式:

前一个页面

Intent intent = new Intent(IndexappActivity.this, LoginappActivity.class);
intent.putExtra("test", "这是来自MainActivity的数据。");
startActivity(intent);

接受页面


Bundle extras = getIntent().getExtras();
String data = null;
if(extras != null)
{
data = extras.getString("test");
}
setTitle( data);

还有其他数据格式,不过这种意境够我用了,结贴

]]>
http://www.sunboyu.cn/2011/07/26/android-activity%e4%b9%8b%e9%97%b4%e4%bc%a0%e5%8f%82.shtml/feed
常用的Intent的URI及示例 (转) http://www.sunboyu.cn/2011/07/25/%e5%b8%b8%e7%94%a8%e7%9a%84intent%e7%9a%84uri%e5%8f%8a%e7%a4%ba%e4%be%8b-%e8%bd%ac.shtml http://www.sunboyu.cn/2011/07/25/%e5%b8%b8%e7%94%a8%e7%9a%84intent%e7%9a%84uri%e5%8f%8a%e7%a4%ba%e4%be%8b-%e8%bd%ac.shtml#comments Mon, 25 Jul 2011 14:20:59 +0000 admin http://www.sunboyu.cn/?p=1420 以下是常用到的Intent的URI及其示例,包含了大部分应用中用到的共用Intent。
一、打开一个网页,类别是Intent.ACTION_VIEW
Uri uri = Uri.parse(“http://blog.3gstdy.com/”);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
二、打开地图并定位到一个点
Uri uri = Uri.parse(“geo:52.76,-79.0342″);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);

三、打开拨号界面 ,类型是Intent.ACTION_DIAL
Uri uri = Uri.parse(“tel:10086″);
Intent intent = new Intent(Intent.ACTION_DIAL, uri);
四、直接拨打电话,与三不同的是,这个直接拨打电话,而不是打开拨号界面
Uri uri = Uri.parse(“tel:10086″);
Intent intent = new Intent(Intent.ACTION_CALL, uri);
五、卸载一个应用,Intent的类别是Intent.ACTION_DELETE
Uri uri = Uri.fromParts(“package”, “xxx”, null);
Intent intent = new Intent(Intent.ACTION_DELETE, uri);
六、安装应用程序,Intent的类别是Intent.ACTION_PACKAGE_ADDED
Uri uri = Uri.fromParts(“package”, “xxx”, null);
Intent intent = new Intent(Intent.ACTION_PACKAGE_ADDED, uri);
七、播放音频文件
Uri uri = Uri.parse(“file:///sdcard/download/everything.mp3″);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
intent.setType(“audio/mp3″);
八、打开发邮件界面
Uri uri= Uri.parse(“mailto:admin@3gstdy.com”);
Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
九、发邮件,与八不同这里是将邮件发送出去,
Intent intent = new Intent(Intent.ACTION_SEND);
String[] tos = { “admin@3gstdy.com” };
String[] ccs = { “webmaster@3gstdy.com” };
intent.putExtra(Intent.EXTRA_EMAIL, tos);
intent.putExtra(Intent.EXTRA_CC, ccs);
intent.putExtra(Intent.EXTRA_TEXT, “I come from http://blog.3gstdy.com”);
intent.putExtra(Intent.EXTRA_SUBJECT, “http://blog.3gstdy.com”);
intent.setType(“message/rfc882″);
Intent.createChooser(intent, “Choose Email Client”);
//发送带附件的邮件
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_SUBJECT, “The email subject text”);
intent.putExtra(Intent.EXTRA_STREAM, “file:///sdcard/mysong.mp3″);
intent.setType(“audio/mp3″);
startActivity(Intent.createChooser(intent, “Choose Email Client”));
十、发短信
Uri uri= Uri.parse(“tel:10086″);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
intent.putExtra(“sms_body”, “I come from http://blog.3gstdy.com”);
intent.setType(“vnd.android-dir/mms-sms”);
十一、直接发邮件
Uri uri= Uri.parse(“smsto://100861″);
Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
intent.putExtra(“sms_body”, “3g android http://blog.3gstdy.com”);
十二、发彩信
Uri uri= Uri.parse(“content://media/external/images/media/23″);
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(“sms_body”, “3g android http://blog.3gstdy.com”);
intent.putExtra(Intent.EXTRA_STREAM, uri);
intent.setType(“image/png”);
十三、# Market 相关
1 //寻找某个应用
Uri uri = Uri.parse(“market://search?q=pname:pkg_name”);
Intent it = new Intent(Intent.ACTION_VIEW, uri);
startActivity(it);
//where pkg_name is the full package path for an application
2 //显示某个应用的相关信息
Uri uri = Uri.parse(“market://details?id=app_id”);
Intent it = new Intent(Intent.ACTION_VIEW, uri);
startActivity(it);
//where app_id is the application ID, find the ID
//by clicking on your application on Market home
//page, and notice the ID from the address bar
十四、路径规划
Uri uri = Uri.parse(“http://maps.google.com/maps?f=d&saddr=startLat%20startLng&daddr=endLat%20endLng&hl=en”);
Intent it = new Intent(Intent.ACTION_VIEW, uri);
startActivity(it);

]]>
http://www.sunboyu.cn/2011/07/25/%e5%b8%b8%e7%94%a8%e7%9a%84intent%e7%9a%84uri%e5%8f%8a%e7%a4%ba%e4%be%8b-%e8%bd%ac.shtml/feed
android点击返回按钮弹出的提示 http://www.sunboyu.cn/2011/06/28/android%e7%82%b9%e5%87%bb%e8%bf%94%e5%9b%9e%e6%8c%89%e9%92%ae%e5%bc%b9%e5%87%ba%e7%9a%84%e6%8f%90%e7%a4%ba.shtml http://www.sunboyu.cn/2011/06/28/android%e7%82%b9%e5%87%bb%e8%bf%94%e5%9b%9e%e6%8c%89%e9%92%ae%e5%bc%b9%e5%87%ba%e7%9a%84%e6%8f%90%e7%a4%ba.shtml#comments Tue, 28 Jun 2011 03:53:18 +0000 admin http://www.sunboyu.cn/?p=1418
import android.view.KeyEvent;
import android.app.AlertDialog;
import android.content.DialogInterface;
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {

if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
AlertDialog.Builder dlg=new AlertDialog.Builder(this);
dlg.setTitle("Alert");
dlg.setMessage("退出?");
dlg.setPositiveButton("是", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
setResult(RESULT_OK);
finish();
}
});
dlg.setNegativeButton("不", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {

}
});
dlg.show();
}
return super.onKeyDown(keyCode, event);
}

]]>
http://www.sunboyu.cn/2011/06/28/android%e7%82%b9%e5%87%bb%e8%bf%94%e5%9b%9e%e6%8c%89%e9%92%ae%e5%bc%b9%e5%87%ba%e7%9a%84%e6%8f%90%e7%a4%ba.shtml/feed
discuz全文检索lucene解决方案图例 http://www.sunboyu.cn/2010/12/17/discuz%e5%85%a8%e6%96%87%e6%a3%80%e7%b4%a2lucene%e8%a7%a3%e5%86%b3%e6%96%b9%e6%a1%88%e5%9b%be%e4%be%8b.shtml http://www.sunboyu.cn/2010/12/17/discuz%e5%85%a8%e6%96%87%e6%a3%80%e7%b4%a2lucene%e8%a7%a3%e5%86%b3%e6%96%b9%e6%a1%88%e5%9b%be%e4%be%8b.shtml#comments Fri, 17 Dec 2010 03:17:12 +0000 admin http://www.sunboyu.cn/?p=1347 discuz论坛搜索方案

已经全部调试通过,正在往一个线上环境上部署。文档也在敢写之中,谢谢关注。

]]>
http://www.sunboyu.cn/2010/12/17/discuz%e5%85%a8%e6%96%87%e6%a3%80%e7%b4%a2lucene%e8%a7%a3%e5%86%b3%e6%96%b9%e6%a1%88%e5%9b%be%e4%be%8b.shtml/feed
使用Lucene 构建强大的discuz 论坛搜索模块 http://www.sunboyu.cn/2010/07/27/discuz_lucene.shtml http://www.sunboyu.cn/2010/07/27/discuz_lucene.shtml#comments Tue, 27 Jul 2010 06:21:18 +0000 admin http://www.sunboyu.cn/?p=1263 在我搞完公司的论坛优化后,我一直想写一个圈套的dz性能优化的方案。当时的全文检索使用的是公司内部某人开发的检索系统,没有开源,所以我做此方案来实现。
此文刚打完草稿,处于调试通过的状态。没有形成具体可用的用户文档。希望在这个底稿的基础上,朋友能给予测试和支持,以鼓励我做出一套完整的方案。

下载:lucene_dz

欢迎加入QQ讨论群:41886598

]]>
http://www.sunboyu.cn/2010/07/27/discuz_lucene.shtml/feed
jar命令的一些应用 http://www.sunboyu.cn/2008/10/21/jar%e5%91%bd%e4%bb%a4%e7%9a%84%e4%b8%80%e4%ba%9b%e5%ba%94%e7%94%a8.shtml http://www.sunboyu.cn/2008/10/21/jar%e5%91%bd%e4%bb%a4%e7%9a%84%e4%b8%80%e4%ba%9b%e5%ba%94%e7%94%a8.shtml#comments Tue, 21 Oct 2008 08:29:46 +0000 admin http://www.sunboyu.cn/?p=358 对于我,最常用的两个功能,就是打包类库,创建可执行的JAR。

打包文件,可以看下边的功能呢个表:

功能 命令
用一个单独的文件创建一个 JAR 文件 jar cf jar-file input-file…
用一个目录创建一个 JAR 文件 jar cf jar-file dir-name
创建一个未压缩的 JAR 文件 jar cf0 jar-file dir-name
更新一个 JAR 文件 jar uf jar-file input-file…
查看一个 JAR 文件的内容 jar tf jar-file
提取一个 JAR 文件的内容 jar xf jar-file
从一个 JAR 文件中提取特定的文件 jar xf jar-file archived-file…
运行一个打包为可执行 JAR 文件的应用程序 java -jar app.jar

创建一个可执行 JAR 很容易。首先将所有应用程序代码放到一个目录中。假设应用程序中的主类是 com.mycompany.myapp.Sample 。您要创建一个包含应用程序代码的 JAR 文件并标识出主类。为此,在某个位置(不是在应用程序目录中)创建一个名为 manifest 的文件,并在其中加入以下一行: Main-Class: com.mycompany.myapp.Sample

引用地址:http://www-128.ibm.com/developerworks/cn/java/j-jar/index.html

]]>
http://www.sunboyu.cn/2008/10/21/jar%e5%91%bd%e4%bb%a4%e7%9a%84%e4%b8%80%e4%ba%9b%e5%ba%94%e7%94%a8.shtml/feed
WordPress使用Lucene进行搜索 http://www.sunboyu.cn/2008/10/18/wordpress%e4%bd%bf%e7%94%a8lucene%e8%bf%9b%e8%a1%8c%e6%90%9c%e7%b4%a2.shtml http://www.sunboyu.cn/2008/10/18/wordpress%e4%bd%bf%e7%94%a8lucene%e8%bf%9b%e8%a1%8c%e6%90%9c%e7%b4%a2.shtml#comments Sat, 18 Oct 2008 05:52:56 +0000 admin http://www.sunboyu.cn/?p=354 java Search php 40个结果 http://www.sunboyu.cn/?p=332 http://www.sunboyu.cn/?p=164 http://www.sunboyu.cn/?p=213 http://www.sunboyu.cn/?p=123 http://www.sunboyu.cn/?p=124 http://www.sunboyu.cn/?p=180 http://www.sunboyu.cn/?p=283 http://www.sunboyu.cn/?p=282 http://www.sunboyu.cn/?p=234 http://www.sunboyu.cn/?p=53 http://www.sunboyu.cn/?p=159 http://www.sunboyu.cn/?p=235 http://www.sunboyu.cn/?p=221 http://www.sunboyu.cn/?p=73 http://www.sunboyu.cn/?p=11 http://www.sunboyu.cn/?p=51 http://www.sunboyu.cn/?p=240 http://www.sunboyu.cn/?p=196 http://www.sunboyu.cn/?p=52 http://www.sunboyu.cn/?p=308 http://www.sunboyu.cn/?p=298 http://www.sunboyu.cn/?p=9 http://www.sunboyu.cn/?page_id=38 http://www.sunboyu.cn/?p=236 http://www.sunboyu.cn/?p=320 http://www.sunboyu.cn/?p=141 http://www.sunboyu.cn/?p=78 http://www.sunboyu.cn/?p=291 http://www.sunboyu.cn/?p=218 http://www.sunboyu.cn/?p=154 http://www.sunboyu.cn/?p=121 http://www.sunboyu.cn/?p=200 http://www.sunboyu.cn/?p=244 http://www.sunboyu.cn/?p=280 http://www.sunboyu.cn/?page_id=112 http://www.sunboyu.cn/?p=288 http://www.sunboyu.cn/?p=292 http://www.sunboyu.cn/?p=20 http://www.sunboyu.cn/?p=130 http://www.sunboyu.cn/?p=87 E:\java> 可以看到,当我们搜索关键词“php”,返回了所有存在php关键词的链接。 当然,这个只是个简单的演示,在创建索引的时候,我们使用了SimpleAnalyzer的方法,这个方法对中文,其实就是基于单字的分词,对于中文信息检索基本是没有意义的。Lucene提供了开发的源代码,因为,我们可以很方便得为其附加我们自己的中文分词方法。 ]]> 接上篇,我们使用Lucene Document Field IndexWrite 等方法创建了索引,现在,使用内建的搜索的方法进行检索。
代码如下:

  1. import java.io.*;
  2. import org.apache.lucene.index.Term;
  3. import org.apache.lucene.index.IndexReader;
  4. import org.apache.lucene.analysis.*;
  5. import org.apache.lucene.queryParser.QueryParser;
  6. import org.apache.lucene.search.*;
  7.  
  8. public class Search
  9. {
  10. public static void main( String argv[] ) throws Exception
  11. {
  12. IndexReader reader = IndexReader.open("./index");
  13. Searcher searcher = new IndexSearcher(reader);
  14. SimpleAnalyzeranalyzer = new SimpleAnalyzer();
  15. QueryParser parser = new QueryParser("post_content", analyzer);
  16. Query query = parser.parse( argv[0] );
  17. Hits hits = searcher.search(query);
  18. System.out.println(hits.length() + "个结果");
  19. for(int i=0;i
  20. {
  21. System.out.println(hits.doc(i).get("guid"));
  22. }
  23. }
  24. }

编译后,我们在命令行进行查询:

E:\java>java Search php
40个结果
http://www.sunboyu.cn/?p=332
http://www.sunboyu.cn/?p=164
http://www.sunboyu.cn/?p=213
http://www.sunboyu.cn/?p=123
http://www.sunboyu.cn/?p=124
http://www.sunboyu.cn/?p=180
http://www.sunboyu.cn/?p=283
http://www.sunboyu.cn/?p=282
http://www.sunboyu.cn/?p=234
http://www.sunboyu.cn/?p=53
http://www.sunboyu.cn/?p=159
http://www.sunboyu.cn/?p=235
http://www.sunboyu.cn/?p=221
http://www.sunboyu.cn/?p=73
http://www.sunboyu.cn/?p=11
http://www.sunboyu.cn/?p=51
http://www.sunboyu.cn/?p=240
http://www.sunboyu.cn/?p=196
http://www.sunboyu.cn/?p=52
http://www.sunboyu.cn/?p=308
http://www.sunboyu.cn/?p=298
http://www.sunboyu.cn/?p=9
http://www.sunboyu.cn/?page_id=38
http://www.sunboyu.cn/?p=236
http://www.sunboyu.cn/?p=320
http://www.sunboyu.cn/?p=141
http://www.sunboyu.cn/?p=78
http://www.sunboyu.cn/?p=291
http://www.sunboyu.cn/?p=218
http://www.sunboyu.cn/?p=154
http://www.sunboyu.cn/?p=121
http://www.sunboyu.cn/?p=200
http://www.sunboyu.cn/?p=244
http://www.sunboyu.cn/?p=280
http://www.sunboyu.cn/?page_id=112
http://www.sunboyu.cn/?p=288
http://www.sunboyu.cn/?p=292
http://www.sunboyu.cn/?p=20
http://www.sunboyu.cn/?p=130
http://www.sunboyu.cn/?p=87

E:\java>
可以看到,当我们搜索关键词“php”,返回了所有存在php关键词的链接。

当然,这个只是个简单的演示,在创建索引的时候,我们使用了SimpleAnalyzer的方法,这个方法对中文,其实就是基于单字的分词,对于中文信息检索基本是没有意义的。Lucene提供了开发的源代码,因为,我们可以很方便得为其附加我们自己的中文分词方法。

]]>
http://www.sunboyu.cn/2008/10/18/wordpress%e4%bd%bf%e7%94%a8lucene%e8%bf%9b%e8%a1%8c%e6%90%9c%e7%b4%a2.shtml/feed
使用Lucene为WordPress创建索引 http://www.sunboyu.cn/2008/10/15/%e4%bd%bf%e7%94%a8lucene%e4%b8%bawordpress%e5%88%9b%e5%bb%ba%e7%b4%a2%e5%bc%95.shtml http://www.sunboyu.cn/2008/10/15/%e4%bd%bf%e7%94%a8lucene%e4%b8%bawordpress%e5%88%9b%e5%bb%ba%e7%b4%a2%e5%bc%95.shtml#comments Wed, 15 Oct 2008 07:41:04 +0000 admin http://www.sunboyu.cn/?p=346 上次说到Lucene的Document模型,现在,我们使用WordPress为例,为其创建索引。

分析wordpress数据库结构,我们只需要为标题内容,即主要的文本内容创建索引即可。

具体语句为:  SELECT ID,post_title,post_content,guid FROM wp_posts ORDER BY ID DESC

如下代码,mysql连接类用的上文的mysql类,代码风格还是很PHP。生成的索引全保存在当前的index文件夹下

E:\java\index 的目录

2008-10-16 14:40

.
2008-10-16 14:40 ..
2008-10-16 14:40 20 segments.gen
2008-10-16 14:40 98 segments_a4
2008-10-16 14:40 268,174 _a0.fdt
2008-10-16 14:40 2,600 _a0.fdx
2008-10-16 14:40 37 _a0.fnm
2008-10-16 14:40 20,990 _a0.frq
2008-10-16 14:40 1,304 _a0.nrm
2008-10-16 14:40 27,210 _a0.prx
2008-10-16 14:40 1,281 _a0.tii
2008-10-16 14:40 130,051 _a0.tis
2008-10-16 14:40 356 _a1.fdt

2008-10-16 14:40 8 _a1.fdx
2008-10-16 14:40 37 _a1.fnm
2008-10-16 14:40 23 _a1.frq
2008-10-16 14:40 8 _a1.nrm
2008-10-16 14:40 23 _a1.prx
2008-10-16 14:40 35 _a1.tii
2008-10-16 14:40 413 _a1.tis
2008-10-16 14:40 1,362 _a2.fdt
2008-10-16 14:40 8 _a2.fdx
2008-10-16 14:40 37 _a2.fnm
2008-10-16 14:40 74 _a2.frq
2008-10-16 14:40 8 _a2.nrm
2008-10-16 14:40 87 _a2.prx
2008-10-16 14:40 35 _a2.tii
2008-10-16 14:40 1,348 _a2.tis
26 个文件 455,627 字节
2 个目录 30,843,887,616 可用字节

E:\java\index

  1. import java.io.*;
  2. import org.apache.lucene.document.Document;
  3. import org.apache.lucene.document.Field;
  4. import org.apache.lucene.index.IndexWriter;
  5. import org.apache.lucene.analysis.SimpleAnalyzer;
  6. import org.apache.lucene.analysis.Analyzer;
  7. public class Index
  8. {
  9. private MysqlConn Db = null;
  10. //构造函数
  11. public void Index()
  12. {
  13. }
  14. //建立mysql连接
  15. public void getConn( String conndsn )
  16. {
  17. this.Db = new MysqlConn();
  18. this.Db.SetDsn( conndsn );
  19. }
  20. public static void main( String args[] )
  21. {
  22. Index index = new Index();
  23. index.getConn( "jdbc:mysql://localhost:3306/wp" );
  24. index.Db.SetUserPass( "root" , "123456" );
  25. index.Db.Conn();
  26. String sql = "SELECT ID,post_title,post_content,guid FROM wp_posts ORDER BY ID DESC";
  27. index.Db.sqlQuery( sql );
  28. try
  29. {
  30. while( index.Db.rs.next() )
  31. {
  32. String ID = index.Db.rs.getString( "ID" );
  33. String post_title = index.Db.rs.getString( "post_title" );
  34. String post_content = index.Db.rs.getString( "post_content" );
  35. String guid = index.Db.rs.getString( "guid" );
  36. Document doc = new Document();
  37. //注释1
  38. Field f1 = new Field("ID",ID,Field.Store.YES,Field.Index.TOKENIZED);
  39. Field f2 = new Field("post_title",post_title,Field.Store.YES,Field.Index.TOKENIZED);
  40. Field f3 = new Field("post_content",post_content,Field.Store.YES,Field.Index.TOKENIZED);
  41. Field f4 = new Field("guid",guid,Field.Store.YES,Field.Index.TOKENIZED);
  42. doc.add( f1 );
  43. doc.add( f2 );
  44. doc.add( f3 );
  45. doc.add( f4 );
  46. System.out.println( ID );
  47. try
  48. {
  49. IndexWriter writer = new IndexWriter( "./index" , new SimpleAnalyzer() );
  50. writer.setUseCompoundFile(false);
  51. writer.addDocument( doc );
  52. writer.close();
  53. }
  54. catch (Exception e)
  55. {
  56. System.out.println("Error : " + e.toString());
  57. }
  58. }
  59. }
  60. catch(Exception e)
  61. {
  62. System.out.println("Error : " + e.toString());
  63. }
  64.  
  65. }
  66. }
]]>
http://www.sunboyu.cn/2008/10/15/%e4%bd%bf%e7%94%a8lucene%e4%b8%bawordpress%e5%88%9b%e5%bb%ba%e7%b4%a2%e5%bc%95.shtml/feed
Lucene创建Document代码部分-循序渐进学Lucene http://www.sunboyu.cn/2008/10/08/lucene%e5%88%9b%e5%bb%badocument%e4%bb%a3%e7%a0%81%e9%83%a8%e5%88%86-%e5%be%aa%e5%ba%8f%e6%b8%90%e8%bf%9b%e5%ad%a6lucene.shtml http://www.sunboyu.cn/2008/10/08/lucene%e5%88%9b%e5%bb%badocument%e4%bb%a3%e7%a0%81%e9%83%a8%e5%88%86-%e5%be%aa%e5%ba%8f%e6%b8%90%e8%bf%9b%e5%ad%a6lucene.shtml#comments Wed, 08 Oct 2008 10:47:49 +0000 admin http://www.sunboyu.cn/?p=337
  1. import java.io.*;
  2. import org.apache.lucene.document.Document;
  3. import org.apache.lucene.document.Field;
  4. import org.apache.lucene.index.IndexWriter;
  5. import org.apache.lucene.analysis.SimpleAnalyzer;
  6. public class Index
  7. {
  8. public static void main( String args[] )
  9. {
  10. Document doc = new Document();
  11. //注释1
  12. Field f1 = new Field("name1","value1",Field.Store.YES,Field.Index.TOKENIZED);
  13. Field f2 = new Field("name2","value2",Field.Store.YES,Field.Index.TOKENIZED);
  14. doc.add( f1 );
  15. doc.add( f2 );
  16. try
  17. {
  18. IndexWriter writer = new IndexWriter( "./" , new SimpleAnalyzer() , true );
  19. writer.addDocument( doc );
  20. writer.close();
  21. }
  22. catch (Exception e)
  23. {
  24.                        e.printStackTrace();
  25. }
  26. }
  27. }

注释1:Field方法的在2.0.0版本中有5种方法,在2.3.2中增加到了7种,详细用法请参阅官方文档
http://lucene.apache.org/java/2_0_0/api/org/apache/lucene/document/Field.html
http://lucene.apache.org/java/2_3_2/api/org/apache/lucene/document/Field.html

]]>
http://www.sunboyu.cn/2008/10/08/lucene%e5%88%9b%e5%bb%badocument%e4%bb%a3%e7%a0%81%e9%83%a8%e5%88%86-%e5%be%aa%e5%ba%8f%e6%b8%90%e8%bf%9b%e5%ad%a6lucene.shtml/feed
Lucene文档模型(Document)简解 http://www.sunboyu.cn/2008/10/04/lucene%e6%96%87%e6%a1%a3%e6%a8%a1%e5%9e%8bdocument%e7%ae%80%e8%a7%a3.shtml http://www.sunboyu.cn/2008/10/04/lucene%e6%96%87%e6%a1%a3%e6%a8%a1%e5%9e%8bdocument%e7%ae%80%e8%a7%a3.shtml#comments Sat, 04 Oct 2008 03:39:51 +0000 admin http://www.sunboyu.cn/?p=334 最近仔细研究了Lucene的文档模式,现用通俗语言来解释。

Lucene的索引,基本结构为 Index->Document->Field 这样可以构建一个非关系型二维结构,由不同field构成的一个Document,由不同的Document构成的Index。

Lucene的Field方法很丰富,在2.0版本以后,由三种Field类型增加到了5种,支持三种数据流的传入方式(字符串,读取,二进制传入),支持数据的存储,索引,分词。

而我们使用Lucene的主要功能在于分词和生成索引。具体应用待详细使用后介绍。

]]>
http://www.sunboyu.cn/2008/10/04/lucene%e6%96%87%e6%a1%a3%e6%a8%a1%e5%9e%8bdocument%e7%ae%80%e8%a7%a3.shtml/feed
我的一个Java程序 http://www.sunboyu.cn/2008/10/03/%e6%88%91%e7%9a%84%e4%b8%80%e4%b8%aajava%e7%a8%8b%e5%ba%8f.shtml http://www.sunboyu.cn/2008/10/03/%e6%88%91%e7%9a%84%e4%b8%80%e4%b8%aajava%e7%a8%8b%e5%ba%8f.shtml#comments Fri, 03 Oct 2008 09:42:56 +0000 admin http://www.sunboyu.cn/?p=333 PHP总有其局限性,比如解释型语言在速度上的弱点,制约了它在效率方面的发挥。facebook开放了源代码,其底层大都是c来编写,而我现在计划用Java为一些服务写后台,这是我的第一个Java程序,希望大家多批评,虽然上边依然有太多php的影子。

  1. import java.sql.*;
  2. /*
  3.  *  Java Mysql数据库连接类
  4.  *  我的第一个java程序
  5.  */
  6. public class MysqlConn
  7. {
  8. private String dsn = "jdbc:mysql://localhost:3306/test";
  9. private String username = "root";
  10. private String password = "123456";
  11.  
  12. private Connection conn = null;
  13. private Statement stmt = null;
  14. private ResultSet rs = null;
  15.  
  16.  
  17.  
  18.  
  19.     public void MysqlConn()
  20. {
  21. }
  22.     //初始化连接参数
  23. public void SetDsn( String Dsn )
  24. {
  25. this.dsn = Dsn;
  26. }
  27. //初始化用户名密码
  28. public void SetUserPass( String Username , String Password )
  29. {
  30. this.username = Username;
  31. this.password = Password;
  32. }
  33. //连接函数
  34. public void Conn()
  35. {
  36. try
  37. {
  38. //加载Connetc/J驱动
  39. //Class.forName("com.mysql.jdbc.Driver");
  40. Class.forName("org.gjt.mm.mysql.Driver");
  41. //开始连接
  42. this.conn = DriverManager.getConnection( this.dsn , this.username , this.password );
  43. this.stmt = this.conn.createStatement( ResultSet.TYPE_SCROLL_SENSITIVE , ResultSet.CONCUR_UPDATABLE );
  44. }
  45. catch(SQLException ex)
  46. {
  47. System.out.println("Error : " + ex.toString());
  48. System.out.println("没有找到JDBC/ODBC驱动程序!");
  49. System.exit(0);
  50. }
  51. catch(Exception e)
  52. {
  53. System.out.println("Errors: " + e.toString());
  54. System.exit(0);
  55. }
  56. }
  57.     //返回结果集
  58. public ResultSet sqlQuery( String sql )
  59. {
  60. try
  61. {
  62. this.rs = this.stmt.executeQuery( sql );
  63. }
  64. catch (SQLException ex)
  65. {
  66. System.out.println("Error : " + ex.toString());
  67. System.exit(0);
  68. }
  69. catch (Exception ex)
  70. {
  71. System.out.println("Error : " + ex.toString());
  72. System.exit(0);
  73. }
  74. return rs;
  75. }
  76. //执行 update,insert之类
  77. public void Exec( String sql )
  78. {
  79. try
  80. {
  81. this.stmt.executeUpdate( sql )
  82. }
  83. catch (SQLException ex)
  84. {
  85. System.out.println("Error : " + ex.toString());
  86. System.exit(0);
  87. }
  88. catch (Exception ex)
  89. {
  90. System.out.println("Error : " + ex.toString());
  91. System.exit(0);
  92. }
  93. }
  94.  
  95. }
]]>
http://www.sunboyu.cn/2008/10/03/%e6%88%91%e7%9a%84%e4%b8%80%e4%b8%aajava%e7%a8%8b%e5%ba%8f.shtml/feed