From e8fcd35fefca31ebfeef78364525a40181b8049a Mon Sep 17 00:00:00 2001 From: Jean-Francois Dockes Date: Fri, 28 Jan 2011 15:47:58 +0100 Subject: [PATCH] fix term highlighting for field searches --- src/rcldb/searchdata.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/rcldb/searchdata.cpp b/src/rcldb/searchdata.cpp index efaee7ea..91c53226 100644 --- a/src/rcldb/searchdata.cpp +++ b/src/rcldb/searchdata.cpp @@ -597,7 +597,11 @@ void StringToXapianQ::processSimpleSpan(const string& span, bool nostemexp, string sterm; // dumb version of user term string prefix; expandTerm(nostemexp, span, exp, sterm, &prefix); - m_terms.insert(m_terms.end(), exp.begin(), exp.end()); + // m_terms is used for highlighting, we don't want prefixes in there. + for (list::const_iterator it = exp.begin(); + it != exp.end(); it++) { + m_terms.push_back(it->substr(prefix.size())); + } // Push either term or OR of stem-expanded set Xapian::Query xq(Xapian::Query::OP_OR, exp.begin(), exp.end()); @@ -640,8 +644,16 @@ void StringToXapianQ::processPhraseOrNear(TextSplitQ *splitData, string sterm; listexp; - expandTerm(nostemexp, *it, exp, sterm); - groups.push_back(vector(exp.begin(), exp.end())); + string prefix; + expandTerm(nostemexp, *it, exp, sterm, &prefix); + + // groups is used for highlighting, we don't want prefixes in there. + vector noprefs; + for (list::const_iterator it = exp.begin(); + it != exp.end(); it++) { + noprefs.push_back(it->substr(prefix.size())); + } + groups.push_back(noprefs); orqueries.push_back(Xapian::Query(Xapian::Query::OP_OR, exp.begin(), exp.end())); #ifdef XAPIAN_NEAR_EXPAND_SINGLE_BUF