opensearch开放平台 配置多长时间通一次mysql

RDS&opensearch&实现discuz的论坛搜索插件
以下内容来自于阿里云开放搜索OpenSearch服务论坛
产品使用分享,欢迎大家下载插件进行测试体验,记得将体验和使用中得问题、建议分享给我们噢~~&
上一回讲到了基于RDS
opensearch 的wordpress搜索插件,今天讲一讲基于RDS和opensearch配合使用来替换discuz底层的数据库搜索。
使用RDS的mysql数据库,并且区域和opensearch所在的区域一致。
开通了opensearch的服务。
测试的的discuz版本3.2 UTF8/GBK。
第一步:创建应用
创建流程和wordpress的基本一致,下载模板文件(请在微博中论坛贴中下载安装),并解压缩。
创建一个模板,选择上传这个模板文件,下一步到完成,模板创建成功。
创建一个应用,应用名例如discuz,然后选择模板,选择你刚刚创建好的模板,下一步一致到完成。
第二步:配置数据源:
点击刚刚创建好的应用,点击数据源,然后点击修改数据源。
会展示3个表,然后选择第一个表forum_thread,点击数据来源,选择rds,点击添加数据。会展示需要的基本配置,输入你的实例ID,数据库名,数据表名(这个为默认为forum_thread,如果你的表有前缀就加上前缀),过滤条件(hidden=0,更多的过滤条件可以自行定义),连接数据库的用户名、密码,然后勾选数据自动同步和同意协议,点连接数据。如果是新版的discuz,所有的字段会默认给匹配上,如下:<img src="/blog7style/images/common/sg_trans.gif" real_src ="/large/005ODmEAjw1eqhss41yunj30ri0ebabo.jpg"
ALT="RDS&opensearch&实现discuz的论坛搜索插件"
TITLE="RDS&opensearch&实现discuz的论坛搜索插件" />&
点击保存,第一个表就算配完了,为了保险起见(登录过期导致数据没有保存)最好再点击保存,然后在点击修改数据源配置第二个表的信息。
第二个表forum_post 表,填写你的实例ID,数据库名,数据库表名(默认为forum_post
如果表有前缀加上前缀,类似pre_forum_post),过滤条件为first=1(表示主贴),数据库的用户名和密码,然后勾选自动同步和统一协议,点击“连接数据”。默认的库表应该所有的字段都能匹配上,如下图:
<img src="/blog7style/images/common/sg_trans.gif" real_src ="/large/005ODmEAjw1eqhssj2g4lj30ri0acmyc.jpg"
ALT="RDS&opensearch&实现discuz的论坛搜索插件"
TITLE="RDS&opensearch&实现discuz的论坛搜索插件" />5.&配置第三个表forum_forum,然后选择rds,点击“添加数据”,同上,区别的地方为表名,默认为forum_forum,如果有前缀的话加上前缀,过滤条件为空。配置好了
点击“连接数据”,在展示中有2个字段,fid和name能默认匹配上,然后点击添加数据,选择fid_name,源字段名称随便选择一个,然后点击内容转换的
,选择第三个插件StringCatenateExtractor,
中的字段列表为"fid,name",字段连接符为"_",点击保存,点击保存,点击保存如下:<img src="/blog7style/images/common/sg_trans.gif" real_src ="/large/005ODmEAjw1eqhstojn7uj30ri0crgnp.jpg"
ALT="RDS&opensearch&实现discuz的论坛搜索插件"
TITLE="RDS&opensearch&实现discuz的论坛搜索插件" />&<img src="/blog7style/images/common/sg_trans.gif" real_src ="/large/005ODmEAjw1eqhstrnvxwj30ri0cjgm4.jpg"
ALT="RDS&opensearch&实现discuz的论坛搜索插件"
TITLE="RDS&opensearch&实现discuz的论坛搜索插件" />&6.保存完了数据源就配置好了,然后点击左侧的搜索结果摘要,点击添加,增加subject
和message两个字段,message 的长度为250(用户自定义,为展示summary的长度),点击保存。<img src="/blog7style/images/common/sg_trans.gif" real_src ="/large/005ODmEAjw1eqhsu4ivt8j30ri04z3yi.jpg"
ALT="RDS&opensearch&实现discuz的论坛搜索插件"
TITLE="RDS&opensearch&实现discuz的论坛搜索插件" />&
第三步:激活应用
在应用列表中找到这个应用,点击右侧的"激活",选择合适的档位,存储容量&=0.2g免费,qps&=5
免费。点击激活。
第四步:索引重建
点击您的应用,然后点击左侧的“索引重建”,然后点击“手动索引重建”,然后点击“导入数据并重建索引”,选择所有表,然后点击创建。<img src="/blog7style/images/common/sg_trans.gif" real_src ="/large/005ODmEAjw1eqhsv2uq41j30ri0dngmf.jpg"
ALT="RDS&opensearch&实现discuz的论坛搜索插件"
TITLE="RDS&opensearch&实现discuz的论坛搜索插件" />&
这个时候opensearch控制台的操作完毕,等索引重建完毕的话您的rds数据源的数据会被导入到opensearch里边,并且新增的数据也会实时的进入opensearch。
第五步:配置discuz插件
注意:最好在您的测试的论坛中测试此功能,因为有可能您的操作导致线上的搜索服务不可用。待测试环境测试完毕,再操作线上的服务。另外如果您需要对搜索的样式或者别的内容改动,则可以在测试环境中改好,然后打包到线上。
根据不同的的编码下载不同的插件,UTF编码的请下载:,GBK编码的请下载:(请下载帖子2楼的压缩包),下载完毕解压缩,变成了cloudopensearch
复制cloudopensearch目录到discuz主目录下边的/source/plugin/下。
点击“安装”,成功之后,点击“启用”,然后点解开放搜索插件的“设置”如下:
<img STYLE="outline: margin-right: 0 margin-bottom: 0 margin-left: 0 padding: 0 font-family: font-style: font-variant: font-weight: font-stretch: vertical-align:" src="/blog7style/images/common/sg_trans.gif" real_src ="/attachment/Fid_242/242_9025_fae.jpg?14"
ALT="RDS&opensearch&实现discuz的论坛搜索插件"
TITLE="RDS&opensearch&实现discuz的论坛搜索插件" />
点击“安装”,成功之后,点击“启用”,然后点解开放搜索插件的“设置”如下:
<img src="/blog7style/images/common/sg_trans.gif" real_src ="/large/005ODmEAjw1eqht0t3upfj30o303dq31.jpg"
ALT="RDS&opensearch&实现discuz的论坛搜索插件"
TITLE="RDS&opensearch&实现discuz的论坛搜索插件" />6.填写您的阿里云的Access
Key Id、secret、host和每页显示条数,accessKeyId和secret
通过登录opensearch控制台,在右上角“ACCESSKEY管理”点击可以获取,host你可以点击你的应用,在基本信息中有API域名。Debug
为调试所用,在打开之后,会在搜索结果的源代码中增加debug信息(&!-- debug 信息
7.如果确认opensearch中已经有了您导入的所有数据,则可以点击提交,否则最好等opensearch索引重建完毕以后再点击提交。
8.提交以后默认搜索会被替换成opensearch的搜索,搜索结果类似如下:<img src="/blog7style/images/common/sg_trans.gif" real_src ="/large/005ODmEAjw1eqht3e8nrkj30ri0hf0um.jpg"
ALT="RDS&opensearch&实现discuz的论坛搜索插件"
TITLE="RDS&opensearch&实现discuz的论坛搜索插件" />&9.您可以对搜索结果样式、内容进行变更,代码位与:discuz主目录/source/plugin/cloudopensearch下。
10.另外您对搜索结果的排序和权重有自己的看法,例如我想对日期的权重增加,或者对精华帖增加权重等等,但又不是按照日期排序,完全可以在控制台增加表达式来修改任何字段的RANK。
任何使用的问题可随时在qq群()、旺旺群()、论坛中反馈。
<img src="/blog7style/images/common/sg_trans.gif" real_src ="/large/005ODmEAjw1eqht8z1fjhj303k03k3yi.jpg"
ALT="RDS&opensearch&实现discuz的论坛搜索插件"
TITLE="RDS&opensearch&实现discuz的论坛搜索插件" />&
已投稿到:
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。DBI and MySQL - Windows
Installing DBI and Using MySQL with Perl in Windows
You will learn in this tutorial how to install the
(the Perl interface to databases) in Windows (NT, XP, 2000). There is another version for Linux . You can obtain a more detailed introduction to DBI by reading its . You can see below the basic DBI model. The scripts are written in Perl using standard Perl variables, commands and syntax. The DBI has methods and handles which are database software independent. You program to access, change or query a database using the standard SQL language, combined with the DBI methods and handles. You install as many DBD::type
modules as you need to support the different database software you may have, but you Perl script will be the same.
You will also see in this tutorial the basics of using DBI to perform queries, and display the results. Once you learn the basics you can use Perl to program the other SQL commands we saw briefly in our class on MySQL, and you should have learned in more details in the DB course. Please note that we have on reserve at the Library the book
, the authoritative reference to DBI.
Installation
You will need to download and install three pieces of software: DB_File, DBI, Table and MySQL DBD module.
If you were installing support for another database like Oracle, Informix, etc, you would also have to download their DBD modules.
The installation in Windows relies in
(Comprehensive Perl Archive Network) archives and
(Programmer's Package Manager) from .
When you installed Perl, PPM was installed automatically and it allows you to install and manages modules, originally available in CPAN.
you open a Command Prompt Window and type ppm. An
starts (requires you to be connected to the Internet to search the modules repository) and you can search for the module you want to install, and later install it.
finally at the ppm prompt type install package-name (package-name is the name you want to install after you found it) and PPM will install the module in the Perl/lib directory.
Install DBI
first. At the ppm prompt type search DB_File and if it is found (it will), then type install DB_FIle ( it done).
Proceed to download DBI, the Perl module to interface with Ddatabases. You will only need to download one version of DBI to use with any database: MySQL, Oracle, Informix, etc.
Once more at the PPM prompt type search DBI and you will see a
you can install, related to DBI. Install the main DBI module as shown . The following
let you test if your installation is working fine:
#!/usr/bin/perl -w
tie %database, 'DB_File', "createdb.dat" or die "Can't initialize database: $!\n";
If all went well a file createdb.dat will be created by the script.
Install Data-Table
You will only need to install one version of Table to use with any database: MySQL, Oracle, Informix, etc. Again, at the ppm prompt type search Data-Table and when found type install Data-Table, as shown .
Install the MySQL module
You will need to download one version of the DBD module to use with each database: MySQL, Oracle, Informix, etc. These instructions refer to downloading and installing the DBD module for MySQL, but you can install more than one of the modules to access different types of database software. The same Perl commands wich work for one database type will work for the other types: the code is portable not only across platforms, but also across database software.
Once more, at the ppm prompt type search DBD and see the
of modules available. You are only interested in installing the driver for Mysql and at the ppm prompt type
and this is it.
This completes the installation of Perl modules to manipulate MySQL databases.
The following
let you test if your installation is working fine with MySQL, assuming you have created a MYTEST database and the root password is rootpass:
#!/usr/bin/perl
#definition of variables
$db="MYTEST";
$host="localhost";
$user="root";
$password="rootpass";
# the root password
#connect to MySQL database
= DBI->connect ("DBI:mysql:database=$db:host=$host",
$password)
or die "Can't connect to database: $DBI::errstr\n";
#disconnect
from database
$dbh->disconnect or warn "Disconnection error: $DBI::errstr\n";
Using MySQL with the Perl DBI Interface
The basic documentation for the MySQL module is the reference table and methods for the , including specific commands only available in MySQL.
Lets see some basic concepts and a series of examples to illustrate them.
Basic concepts
Perl uses three levels of handlers to deal with databases:
the driver handle = DBD::mysql, which is transparent for you once is installed. You will not need regularly to include $drh in your script.
$dbh -- the database handle = what you will need to create a connection to the database, it is different for each type of database software. It has the following format in MySQL:
my $dbh = DBI->connect ("DBI:mysql:database=$db:host=$host",$user,$password);
$sth -- the statement handle = children of the $dbh, and will let the various statements be declared. The types of statements will depend on the SQL commands you are using. SELECT uses three statements in order to perform the query and display the results: prepare, execute and fetch (see examples below). INSERT,UPDATE and DELETE do not use fetch, only prepare and execute.
See the above on-line references and the book on reserve for more details.
: Connecting, quering and displaying results of query.
#!/usr/bin/perl
#definition of variables
$db="MYTEST";
$host="localhost";
$user="root";
$password="rootpass";
#connect to MySQL database
= DBI->connect ("DBI:mysql:database=$db:host=$host",
$password)
or die "Can't connect to database: $DBI::errstr\n";
#prepare the query
my $sth = $dbh->prepare( "
FROM people");
#execute the query
$sth->execute( );
## Retrieve the results of a row of data and print
print "\tQuery results:\n================================================\n";
while ( my @row = $sth->fetchrow_array( ) )
print "@row\n";
warn "Problem in retrieving results", $sth->errstr( ), "\n"
if $sth->err( );
Once you run the script you will see the following results:
[root@alaptop dbi]# ./queryall
Query results:
================================================
347 Al Bento 1420 N. Charles St, Baltimore, MD 21201
458 John Morris 1420 N. Charles St, Baltimore, MD 21201
569 Milt Jenkins 1420 N. Charles St, Baltimore, MD 21201
: select fields and place results in variables
This is a modification of the example 1, where we select some fields and we split the query results into variables before printing.
#!/usr/bin/perl
#definition of variables
$db="MYTEST";
$host="localhost";
$user="root";
$password="rootpass";
#connect to MySQL database
= DBI->connect ("DBI:mysql:database=$db:host=$host",
$password)
or die "Can't connect to database: $DBI::errstr\n";
#prepare the query
my $sth = $dbh->prepare( "
SELECT name,address
FROM people");
#execute the query
$sth->execute( );
## Retrieve the results of a row of data and print
print "\tQuery results:\n================================================\n";
while ( ($name,$address) = $sth->fetchrow_array( ) )
print "Name: $name, Address: $address\n";
warn "Problem in retrieving results", $sth->errstr( ), "\n"
if $sth->err( );
Once you run the script you will see the following results:
[root@alaptop dbi]# ./querynames
Query results:
================================================
Name: Al Bento, Address: 1420 N. Charles St, Baltimore, MD 21201
Name: John Morris, Address: 1420 N. Charles St, Baltimore, MD 21201
Name: Milt Jenkins, Address: 1420 N. Charles St, Baltimore, MD 21201
: another way to query and obtain results
#!/usr/bin/perl
#definition of variables
$db="MYTEST";
$host="localhost";
$user="root";
$password="rootpass";
#connect to MySQL database
= DBI->connect ("DBI:mysql:database=$db:host=$host",
$password)
or die "Can't connect to database: $DBI::errstr\n";
#prepare the query
my $sql = "SELECT * FROM people";
my $sth = $dbh->prepare( $sql);
#execute the query
$sth->execute( );
## Retrieve the results of a row of data and print
my ( $userid,$name,$address);
$sth->bind_columns ( undef,\$userid, \$name, \$address );
print "\tQuery results:\n================================================\n";
while ( $sth->fetch( ) )
print "Userid is $userid, the name is $name, and the address is $address\n";
$sth->finish( );
$dbh->disconnect( );
Once you run the script you will see the following results:
[root@alaptop dbi]# ./queryallfancy
Query results:
================================================
Userid is 347, the name is Al Bento, and the address is 1420 N. Charles St, Baltimore, MD 21201
Userid is 458, the name is John Morris, and the address is 1420 N. Charles St, Baltimore, MD 21201
Userid is 569, the name is Milt Jenkins, and the address is 1420 N. Charles St, Baltimore, MD 21201
You are not limited to queries when using DBI. You can create and drop tables, insert, update, etc.
This page is maintained by
who can be reached at . This page was last updated on October 28, 2002. Although we will attempt to keep this information accurate, we can not guarantee the accuracy of the information provided.}

我要回帖

更多关于 opensearch 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信