110,538
社区成员
发帖
与我相关
我的任务
分享
using (TcpConnection connection = new PersistentTcpConnection("127.0.0.1", 9312))
{
SearchCommand search = new SearchCommand(connection);
SearchQuery query = new SearchQuery(key);
// Sphinx indexes
//query.Indexes.UnionWith();
// select fields clause
query.Select = "1";
// match type
query.MatchMode = 0;
// ranking
query.RankingMode = 0;
// comment
query.Comment = "";
// sorting
query.SortMode = 0;
query.SortBy = "";
// limits
query.Limit = query.MaxMatches = 3;
// document id filtering
query.MinDocumentId = 0;
query.MaxDocumentId = 0;
// grouping
query.GroupFunc = 0;
query.GroupBy = "";
query.GroupSort = "";
query.GroupDistinct = "";
//query.AttributeFilters.Add(new AttributeFilterRangeDateTime("PublishDate", PublicationStartDate.Value, PublicationEndDate.Value, false));
// index weights
search.QueryList.Add(query);
// run the query and get the results
string output = "";
try
{
search.Execute();
}
catch (SphinxException ex)
{
output = "<h2 style='color: red;'>Error is occured:<h2>" + ex.Message;
return output;
}
foreach (SearchQueryResult res in search.Result.QueryResults)
{
foreach (Sphinx.Client.Commands.Search.Match mt in res.Matches)
{
output += mt.DocumentId + ",";
}
}
if (output.Length > 0)
{
output = output.Substring(0, output.Length - 1);
}
return output;
}
#MySQL数据源配置,详情请查看:http://www.coreseek.cn/products-install/mysql/
#请先将var/test/documents.sql导入数据库,并配置好以下的MySQL用户密码数据库
#源定义
source news
{
type = mysql
sql_host = 192.168.1.8
sql_user = news
sql_pass = news
sql_db = news_test
sql_port = 3306
sql_query_pre = SET NAMES utf8
sql_query = SELECT NewsId as id,DataDate as datadate,NewsTitle as title, NewsTitleText,NewsContentText from table_news
#sql_query第一列id需为整数
#title、content作为字符串/文本字段,被全文索引
sql_attr_string = NewsTitleText
sql_attr_string = NewsContent
sql_attr_timestamp = datadate
sql_query_info_pre = SET NAMES utf8 #命令行查询时,设置正确的字符集
#sql_query_info = SELECT * FROM table_news WHERE NewsId=$id #命令行查询时,从数据库读取原始数据信息
sql_query_info = SELECT * WHERE ID=$id
}
source book : news
{
sql_query = SELECT ID as id, Title as title,Author as author,Publisher as publisher,ISBN13 as isbn13 FROM book
}
#index定义
index news
{
source = news #对应的source名称
path = C:\Coreseek\coreseek-4.1-win32\var\data\mysql #请修改为实际使用的绝对路径,例如:/usr/local/coreseek/var/...
docinfo = extern
mlock = 0
morphology = none
min_word_len = 1
html_strip = 0
#中文分词配置,详情请查看:http://www.coreseek.cn/products-install/coreseek_mmseg/
#charset_dictpath = /usr/local/mmseg3/etc/ #BSD、Linux环境下设置,/符号结尾
charset_dictpath = C:\Coreseek\coreseek-4.1-win32\etc #Windows环境下设置,/符号结尾,最好给出绝对路径,例如:C:/usr/local/coreseek/etc/...
charset_type = zh_cn.utf-8
}
index book : news
{
source = book
path = C:\Coreseek\coreseek-4.1-win32\var\data\mysql
}
#全局index定义
indexer
{
mem_limit = 256M
}
#searchd服务定义
searchd
{
listen = 9312
read_timeout = 5
max_children = 30
max_matches = 1000
seamless_rotate = 0
preopen_indexes = 0
unlink_old = 1
pid_file = C:\Coreseek\coreseek-4.1-win32\var\log\searchd_mysql.pid
log = C:\Coreseek\coreseek-4.1-win32\var\log\searchd_mysql.log
query_log = C:\Coreseek\coreseek-4.1-win32\var\log\query_mysql.log
compat_sphinxql_magics = 0
}