Skip to content

Commit

Permalink
优化搜索缓存失效的判断,发现失效文档后清空缓存
Browse files Browse the repository at this point in the history
  • Loading branch information
hightman committed Jan 11, 2013
1 parent 0426e5e commit e465665
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 29 deletions.
2 changes: 2 additions & 0 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ Big Plans of Xunsearch

标识符含义:* 暂定未做;+ 已完成;= 正在做;- 取消

* 优化 task.cc 分为(db+db_a)时如果实时 update 某一条数据可能导致 docid 修改而 cache 扔起作用会出现空白内容

* 优化 task.cc 让 queryparser 可以复用与共享

* 优化日志,减少输出,记录错误为主;增加状态监控模块,各个进程的详细情况。
Expand Down
60 changes: 31 additions & 29 deletions src/task.cc
Original file line number Diff line number Diff line change
Expand Up @@ -240,47 +240,49 @@ static inline void cut_matched_string(string &s, int v, unsigned int id, struct
* @param conn (XS_CONN *)
* @param rd (struct result_doc *)
*/
static int send_result_doc(XS_CONN *conn, struct result_doc *rd)
static int send_result_doc(XS_CONN *conn, struct result_doc *rd, struct cache_result *cr)
{
int rc;
int rc = CMD_RES_CONT;

// send the doc header
log_debug_conn("search result doc (ID:%u, PERCENT:%d%%)", rd->docid, rd->percent);
rc = conn_respond(conn, CMD_SEARCH_RESULT_DOC, 0, (char *) rd, sizeof(struct result_doc));
if (rc == CMD_RES_CONT)
try
{
// send the data (body, check to cut)
int vno;
string data;
struct search_zarg *zarg = (struct search_zarg *) conn->zarg;
try
{
Xapian::Document d = zarg->db->get_document(rd->docid);
Xapian::ValueIterator v = d.values_begin();
Xapian::Document d = zarg->db->get_document(rd->docid);
Xapian::ValueIterator v = d.values_begin();

// send other fields (value)
while (v != d.values_end() && rc == CMD_RES_CONT)
{
vno = v.get_valueno();
data = *v++;

cut_matched_string(data, vno, rd->docid, (struct search_zarg *) conn->zarg);
rc = conn_respond(conn, CMD_SEARCH_RESULT_FIELD, vno, data.data(), data.size());
}
// send doc header
rc = conn_respond(conn, CMD_SEARCH_RESULT_DOC, 0, (char *) rd, sizeof(struct result_doc));
if (rc != CMD_RES_CONT)
return rc;

// send data (body)
data = d.get_data();
vno = XS_DATA_VNO;
// send other fields (value)
while (v != d.values_end() && rc == CMD_RES_CONT)
{
vno = v.get_valueno();
data = *v++;

cut_matched_string(data, vno, rd->docid, (struct search_zarg *) conn->zarg);
rc = conn_respond(conn, CMD_SEARCH_RESULT_FIELD, vno, data.data(), data.size());
}
catch (const Xapian::Error &e)
{
// ignore the error simply
log_error_conn("xapian exception on sending doc (ERROR:%s)", e.get_msg().data());
rc = CMD_RES_CONT;
}

// send data (body)
data = d.get_data();
vno = XS_DATA_VNO;

cut_matched_string(data, vno, rd->docid, (struct search_zarg *) conn->zarg);
rc = conn_respond(conn, CMD_SEARCH_RESULT_FIELD, vno, data.data(), data.size());
}
catch (const Xapian::Error &e)
{
// ignore the error simply
log_error_conn("xapian exception on sending doc (ERROR:%s)", e.get_msg().data());
if (cr != NULL)
cr->count = cr->lastid = 0;
rc = CMD_RES_CONT;
}
return rc;
}
Expand Down Expand Up @@ -1005,7 +1007,7 @@ static int zcmd_task_get_result(XS_CONN *conn)
if (rd.docid == 0) continue;

// send the doc
if ((rc = send_result_doc(conn, &rd)) != CMD_RES_CONT)
if ((rc = send_result_doc(conn, &rd, NULL)) != CMD_RES_CONT)
break;
}

Expand Down Expand Up @@ -1048,7 +1050,7 @@ static int zcmd_task_get_result(XS_CONN *conn)
limit += off;
do
{
if ((rc = send_result_doc(conn, &cr->doc[off])) != CMD_RES_CONT)
if ((rc = send_result_doc(conn, &cr->doc[off], cr)) != CMD_RES_CONT)
break;
}
while (++off < limit);
Expand Down

0 comments on commit e465665

Please sign in to comment.