[Opentrep-svn] SF.net SVN: opentrep:[141] trunk/opentrep/opentrep/bom
Status: Beta
Brought to you by:
denis_arnaud
From: <den...@us...> - 2009-07-19 10:47:09
|
Revision: 141 http://opentrep.svn.sourceforge.net/opentrep/?rev=141&view=rev Author: denis_arnaud Date: 2009-07-19 10:47:08 +0000 (Sun, 19 Jul 2009) Log Message: ----------- [Dev] Improved the notification scheme when there are several matches with the same percentage. Modified Paths: -------------- trunk/opentrep/opentrep/bom/Document.cpp trunk/opentrep/opentrep/bom/Document.hpp trunk/opentrep/opentrep/bom/ResultHolder.cpp trunk/opentrep/opentrep/bom/StringMatcher.cpp Modified: trunk/opentrep/opentrep/bom/Document.cpp =================================================================== --- trunk/opentrep/opentrep/bom/Document.cpp 2009-07-18 23:30:37 UTC (rev 140) +++ trunk/opentrep/opentrep/bom/Document.cpp 2009-07-19 10:47:08 UTC (rev 141) @@ -5,6 +5,7 @@ #include <cassert> // OpenTREP #include <opentrep/bom/Document.hpp> +#include <opentrep/service/Logger.hpp> namespace OPENTREP { @@ -22,20 +23,20 @@ // ////////////////////////////////////////////////////////////////////// std::string Document::describeKey() const { std::ostringstream oStr; - oStr << describeShortKey(); + oStr << "`" << describeShortKey() << "´"; if (_correctedQueryString.empty() == false) { - oStr << " (corrected into " << _correctedQueryString << ")"; + oStr << " (corrected into `" << _correctedQueryString << "´)"; } return oStr.str(); } // ////////////////////////////////////////////////////////////////////// - std::string Document::toString() const { + std::string Document::toShortString() const { std::ostringstream oStr; - oStr << describeKey() << std::endl; + oStr << describeShortKey(); const Xapian::docid& lDocID = _document.get_docid(); - oStr << "Document ID " << lDocID << "\t" << _percentage + oStr << " => Document ID " << lDocID << " matching at " << _percentage << "% [" << _document.get_data() << "]"; if (_documentList.empty() == false) { @@ -62,6 +63,38 @@ } // ////////////////////////////////////////////////////////////////////// + std::string Document::toString() const { + std::ostringstream oStr; + oStr << describeKey(); + + const Xapian::docid& lDocID = _document.get_docid(); + oStr << " => Document ID " << lDocID << " matching at " << _percentage + << "% [" << _document.get_data() << "]"; + + if (_documentList.empty() == false) { + oStr << " along with " << _documentList.size() + << " other matching document(s) { "; + + unsigned short idx = 0; + for (XapianDocumentList_T::const_iterator itDoc = _documentList.begin(); + itDoc != _documentList.end(); ++itDoc, ++idx) { + const Xapian::Document& lXapianDoc = *itDoc; + const Xapian::docid& lDocID = lXapianDoc.get_docid(); + if (idx != 0) { + oStr << ", "; + } + oStr << "Doc ID " << lDocID << " [" << lXapianDoc.get_data() << "]"; + } + oStr << " }." << std::endl; + + } else { + oStr << std::endl; + } + + return oStr.str(); + } + + // ////////////////////////////////////////////////////////////////////// void Document::toStream (std::ostream& ioOut) const { ioOut << toString(); } @@ -70,4 +103,22 @@ void Document::fromStream (std::istream& ioIn) { } + // ////////////////////////////////////////////////////////////////////// + NbOfMatches_T Document::notifyIfExtraMatch () const { + NbOfMatches_T oNbOfMatches = _documentList.size(); + + // DEBUG + if (oNbOfMatches != 0) { + OPENTREP_LOG_NOTIFICATION ("NOTE: the following document gets several " + << "matches with the same matching percentage." + << " You may want to alter the SQL database " + << "and re-index the Xapian database, so as " + << "to allow a more specific match:" + << std::endl << toString()); + } + + // Return the total number of matches (main plus extras) + return (1 + oNbOfMatches); + } + } Modified: trunk/opentrep/opentrep/bom/Document.hpp =================================================================== --- trunk/opentrep/opentrep/bom/Document.hpp 2009-07-18 23:30:37 UTC (rev 140) +++ trunk/opentrep/opentrep/bom/Document.hpp 2009-07-19 10:47:08 UTC (rev 141) @@ -80,20 +80,35 @@ _documentList.push_back (iMatchingDocument); } + + public: + // /////////// Business methods ///////// + /** Retrieve the number of extra matches for the given query string, + and print a notification in the logs, so that the SQL and Xapian + databases can be altered in order to get more specific matches. + @param const TravelQuery_T& Query string having yielded that matching + document. + @return NbOfMatches_T The number of matches (i.e., one chosen match + added to the extra matches). */ + NbOfMatches_T notifyIfExtraMatch() const; + public: // /////////// Display support methods ///////// - /** Dump a Business Object into an output stream. + /** Dump the structure into an output stream. @param ostream& the output stream. */ void toStream (std::ostream& ioOut) const; - /** Read a Business Object from an input stream. + /** Read a structure from an input stream. @param istream& the input stream. */ void fromStream (std::istream& ioIn); - /** Get the serialised version of the Business Object. */ + /** Get the serialised version of the structure. */ std::string toString() const; + /** Get a shorter serialised version of the structure. */ + std::string toShortString() const; + /** Get a string describing the whole key (differentiating two objects at any level). */ std::string describeKey() const; Modified: trunk/opentrep/opentrep/bom/ResultHolder.cpp =================================================================== --- trunk/opentrep/opentrep/bom/ResultHolder.cpp 2009-07-18 23:30:37 UTC (rev 140) +++ trunk/opentrep/opentrep/bom/ResultHolder.cpp 2009-07-19 10:47:08 UTC (rev 141) @@ -156,9 +156,8 @@ ioDocumentList.push_back (lMatchingDocument); // DEBUG - const XapianDocumentList_T& lXapianDocumentList = - lMatchingDocument.getExtraDocumentList(); - const NbOfMatches_T lNbOfMatches = 1 + lXapianDocumentList.size(); + const NbOfMatches_T lNbOfMatches = + lMatchingDocument.notifyIfExtraMatch(); OPENTREP_LOG_DEBUG ("==> " << lNbOfMatches << " matches for the query string: `" << lMatchedString << "´ (from `" Modified: trunk/opentrep/opentrep/bom/StringMatcher.cpp =================================================================== --- trunk/opentrep/opentrep/bom/StringMatcher.cpp 2009-07-18 23:30:37 UTC (rev 140) +++ trunk/opentrep/opentrep/bom/StringMatcher.cpp 2009-07-19 10:47:08 UTC (rev 141) @@ -295,21 +295,41 @@ */ Xapian::MSetIterator itDoc = iMatchingSet.begin(); assert (itDoc != iMatchingSet.end()); - + + // Store the percentage const Xapian::percent& lBestPercentage = itDoc.get_percent(); ioMatchingDocument.setXapianPercentage (lBestPercentage); - ioMatchingDocument.setXapianDocument (itDoc.get_document()); + // Store the (Xapian) document itself + const Xapian::Document& lBestDocument = itDoc.get_document(); + ioMatchingDocument.setXapianDocument (lBestDocument); + + // Go on in the list of matches, if any + ++itDoc; + + /* + if (itDoc != iMatchingSet.end()) { + // DEBUG + OPENTREP_LOG_DEBUG ("There are extra matches for Document ID " + << lBestDocument.get_docid() + << ", itself matching at " << lBestPercentage + << "%."); + } + */ + /** Add all the Xapian documents having reached the same matching percentage. */ NbOfMatches_T idx = 1; - for (++itDoc ; itDoc != iMatchingSet.end(); ++itDoc, ++idx) { + for ( ; itDoc != iMatchingSet.end(); ++itDoc, ++idx) { const Xapian::percent& lPercentage = itDoc.get_percent(); + const Xapian::Document& lDocument = itDoc.get_document(); // DEBUG - OPENTREP_LOG_DEBUG ("[" << idx << "] extra. Best " << lBestPercentage - << "%, other " << lPercentage << "% (" - << itDoc.get_document().get_docid() << ")"); + /* + OPENTREP_LOG_DEBUG ("Extra #" << idx << ": Doc ID " + << lDocument.get_docid() << " matching at " + << lPercentage << "%."); + */ if (lPercentage == lBestPercentage) { ioMatchingDocument.addExtraDocument (itDoc.get_document()); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |