当前位置: 首页>>代码示例>>C++>>正文


C++ DocumentInfo::getExtract方法代码示例

本文整理汇总了C++中DocumentInfo::getExtract方法的典型用法代码示例。如果您正苦于以下问题:C++ DocumentInfo::getExtract方法的具体用法?C++ DocumentInfo::getExtract怎么用?C++ DocumentInfo::getExtract使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DocumentInfo的用法示例。


在下文中一共展示了DocumentInfo::getExtract方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: processResult

bool WebEngine::processResult(const string &queryUrl, DocumentInfo &result)
{
	Url queryUrlObj(queryUrl);
	string resultUrl(result.getLocation());
	string queryHost(Url::reduceHost(queryUrlObj.getHost(), 2));

	if (resultUrl.empty() == true)
	{
		return false;
	}

	// Is this URL relative to the search engine's domain ?
	if ((resultUrl[0] == '/') ||
		((resultUrl.length() > 1) &&
		(resultUrl[0] == '.') &&
		(resultUrl[1] == '/')))
	{
		string fullResultUrl(queryUrlObj.getProtocol());

		fullResultUrl += "://";
		fullResultUrl += queryUrlObj.getHost();
		if (resultUrl[0] == '.')
		{
			fullResultUrl += resultUrl.substr(1);
		}
		else
		{
			fullResultUrl += resultUrl;
		}

		resultUrl = fullResultUrl;
	}
	else
	{
		Url resultUrlObj(resultUrl);

		if ((resultUrlObj.getHost().empty() == true) ||
			(resultUrlObj.getHost() == "localhost"))
		{
			string fullResultUrl(queryUrlObj.getProtocol());

			fullResultUrl += "://";
			fullResultUrl += queryUrlObj.getHost();
			fullResultUrl += "/";
			fullResultUrl += resultUrl;
			resultUrl = fullResultUrl;
		}
	}


	Url resultUrlObj(resultUrl);

	// Is the result's host name the same as the search engine's ?
	// FIXME: not all TLDs have leafs at level 2
	if (queryHost == Url::reduceHost(resultUrlObj.getHost(), 2))
	{
		string protocol(resultUrlObj.getProtocol());

		if (protocol.empty() == false)
		{
			string embeddedUrl;

			string::size_type startPos = resultUrl.find(protocol, protocol.length());
			if (startPos != string::npos)
			{
				string::size_type endPos = resultUrl.find("&", startPos);
				if (endPos != string::npos)
				{
					embeddedUrl = resultUrl.substr(startPos, endPos - startPos);
				}
				else
				{
					embeddedUrl = resultUrl.substr(startPos);
				}

				resultUrl = Url::unescapeUrl(embeddedUrl);
			}
#ifdef DEBUG
			else cout << "WebEngine::processResult: no embedded URL" << endl;
#endif
		}
#ifdef DEBUG
		else cout << "WebEngine::processResult: no protocol" << endl;
#endif
	}

	// Trim spaces
	string trimmedUrl(resultUrl);
	StringManip::trimSpaces(trimmedUrl);

	// Make the URL canonical
	result.setLocation(Url::canonicalizeUrl(trimmedUrl));

	// Scan the extract for query terms
	string extract(result.getExtract());
	if (extract.empty() == true)
	{
		return true;
	}

//.........这里部分代码省略.........
开发者ID:BackupTheBerlios,项目名称:pinot-svn,代码行数:101,代码来源:WebEngine.cpp

示例2: documentInfoToDBus

/// Converts docId and docInfo to a dbus message.
bool DBusIndex::documentInfoToDBus(DBusMessageIter *iter, unsigned int docId,
	const DocumentInfo &docInfo)
{
        DBusMessageIter array_iter;
	DBusMessageIter struct_iter;

	if (iter == NULL)
	{
		return false;
	}

	// Append the document ID ?
	if (docId != 0)
	{
		dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT32, &docId);
	}
	if (!dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY,
		DBUS_STRUCT_BEGIN_CHAR_AS_STRING \
		DBUS_TYPE_STRING_AS_STRING \
		DBUS_TYPE_STRING_AS_STRING \
		DBUS_STRUCT_END_CHAR_AS_STRING, &array_iter))
	{
#ifdef DEBUG
		clog << "DBusIndex::documentInfoToDBus: couldn't open array container" << endl;
#endif
		return false;
	}

	for (unsigned int fieldNum = 0; g_fieldNames[fieldNum] != NULL; ++fieldNum)
	{
		string value;
		stringstream numStr;

		switch (fieldNum)
		{
			case 0:
				value = docInfo.getTitle();
				break;
			case 1:
				value = docInfo.getLocation(true);
				break;
			case 2:
				value = docInfo.getType();
				break;
			case 3:
				value = Languages::toEnglish(docInfo.getLanguage());
				break;
			case 4:
				value = docInfo.getTimestamp();
				break;
			case 5:
				numStr << docInfo.getSize();
				value = numStr.str();
				break;
			case 6:
				value = docInfo.getExtract();
				break;
			case 7:
				numStr << docInfo.getScore();
				value = numStr.str();
				break;
			default:
				break;
		}

		if (value.empty() == true)
		{
			continue;
		}

		if (!dbus_message_iter_open_container(&array_iter,
			DBUS_TYPE_STRUCT, NULL, &struct_iter))
		{
#ifdef DEBUG
			clog << "DBusIndex::documentInfoToDBus: couldn't open struct container" << endl;
#endif
			return false;
		}

		const char *pValue = value.c_str();
		dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_STRING, &g_fieldNames[fieldNum]);
		dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_STRING, &pValue);
#ifdef DEBUG
		clog << "DBusIndex::documentInfoToDBus: field " << g_fieldNames[fieldNum] << "=" << pValue << endl;
#endif

		if (!dbus_message_iter_close_container(&array_iter, &struct_iter))
		{
#ifdef DEBUG
			clog << "DBusIndex::documentInfoToDBus: couldn't close struct container" << endl;
#endif
			return false;
		}
	}

	if (!dbus_message_iter_close_container(iter, &array_iter))
	{
#ifdef DEBUG
		clog << "DBusIndex::documentInfoToDBus: couldn't close array container" << endl;
//.........这里部分代码省略.........
开发者ID:FabriceColin,项目名称:pinot,代码行数:101,代码来源:DBusIndex.cpp


注:本文中的DocumentInfo::getExtract方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。