本文整理汇总了C++中DocumentPtr类的典型用法代码示例。如果您正苦于以下问题:C++ DocumentPtr类的具体用法?C++ DocumentPtr怎么用?C++ DocumentPtr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DocumentPtr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TEST_F
TEST_F(BooleanScorerTest, testMethod) {
static const String FIELD = L"category";
RAMDirectoryPtr directory = newLucene<RAMDirectory>();
Collection<String> values = newCollection<String>(L"1", L"2", L"3", L"4");
IndexWriterPtr writer = newLucene<IndexWriter>(directory, newLucene<WhitespaceAnalyzer>(), true, IndexWriter::MaxFieldLengthLIMITED);
for (int32_t i = 0; i < values.size(); ++i) {
DocumentPtr doc = newLucene<Document>();
doc->add(newLucene<Field>(FIELD, values[i], Field::STORE_YES, Field::INDEX_NOT_ANALYZED));
writer->addDocument(doc);
}
writer->close();
BooleanQueryPtr booleanQuery1 = newLucene<BooleanQuery>();
booleanQuery1->add(newLucene<TermQuery>(newLucene<Term>(FIELD, L"1")), BooleanClause::SHOULD);
booleanQuery1->add(newLucene<TermQuery>(newLucene<Term>(FIELD, L"2")), BooleanClause::SHOULD);
BooleanQueryPtr query = newLucene<BooleanQuery>();
query->add(booleanQuery1, BooleanClause::MUST);
query->add(newLucene<TermQuery>(newLucene<Term>(FIELD, L"9")), BooleanClause::MUST_NOT);
IndexSearcherPtr indexSearcher = newLucene<IndexSearcher>(directory, true);
Collection<ScoreDocPtr> hits = indexSearcher->search(query, FilterPtr(), 1000)->scoreDocs;
EXPECT_EQ(2, hits.size());
}
示例2: QUERY
// ** Films::filmIdToObjectId
OID Films::filmIdToObjectId( int filmId ) const
{
DocumentPtr document = m_source->collection( "items" )->findOne( QUERY( "itemId" << filmId ) );
assert( document != NULL );
return document->_id();
}
示例3: OID
// ** Films::similarTo
SimilarFilmsArray Films::similarTo( const std::string& oid, int count ) const
{
SimilarFilmsArray result;
OID objectId = OID( oid );
CollectionPtr similars = m_target->collection( "similar" );
CursorPtr cursor = similars->find( QUERY( "$or" << ARRAY( DOCUMENT( "first" << oid ) << DOCUMENT( "second" << objectId ) ) ) );
DocumentPtr document;
while( (document = cursor->next()) ) {
// ** Read data from document
OID first = document->objectId( "first" );
OID second = document->objectId( "second" );
int value = document->integer( "value" );
// ** Decode similarity & accuracy
float similarity, accuracy;
decodeSimilarity( value, similarity, accuracy );
// ** Push similar film
Film film = filmById( first == objectId ? second : first );
Quality quality = qualityFromRange( similarity, m_similarityQuartiles );
result.push_back( SimilarFilm( film, similarity, accuracy, quality ) );
}
std::sort( result.begin(), result.end(), SimilarFilm::sortBySimilarity );
if( count ) {
result.resize( std::min( count, ( int )result.size() ) );
}
return result;
}
示例4: filmFromDocument
// ** Films::filmFromDocument
Film Films::filmFromDocument( const DocumentPtr& document ) const
{
Film film( document->_id(), document->string( "name.ru" ), document->integerSet( "genres" ), document->integer( "year" ) );
film.m_video = document->string( "video" );
return film;
}
示例5: writeTestFile
void StandardDocumentProcessorTestCase::testProcessWithEmptyField()
{
String sPath = writeTestFile("file_with_empty_field.txt", TEST_FILE_WITH_EMPTY_FIELD);
StandardDocumentProcessor processor;
processor.init(m_pDocSchema.get());
DocumentSource docSource(m_pDocSchema.get());
RawDocumentPtr pRawDoc = new RawDocument();
pRawDoc->setPath(sPath);
docSource.setRawDocument(pRawDoc);
processor.process(docSource);
DocumentPtr pDoc = docSource.stealLastDocument();
CPPUNIT_ASSERT(pDoc.isNotNull());
Answer ans;
makeAnswer(TEST_FILE_WITH_EMPTY_FIELD, ans);
Document::Iterator it = pDoc->iterator();
CPPUNIT_ASSERT_EQUAL(ans.size(), it.size());
size_t i = 0;
while (it.hasNext())
{
const Field* pField = it.next();
// cout << ans[i].first << " : " << ans[i].second << endl;
CPPUNIT_ASSERT_EQUAL(ans[i].first, pField->getFieldSchema()->getName());
CPPUNIT_ASSERT_EQUAL(ans[i].second, std::string(pField->getValue().c_str()));
++i;
}
}
示例6: lock
//---------------------------------------------------------------------
ElementPtr PeerContactProfile::getPrivateProfile() const
{
AutoRecursiveLock lock(mLock);
if (!mDocument) return ElementPtr();
if (!hasContactProfileSecret()) return ElementPtr();
try {
ElementPtr contactProfileElement = getContactProfileElement();
if (!contactProfileElement) return ElementPtr();
ElementPtr privateElement = contactProfileElement->findFirstChildElementChecked("private");
ElementPtr profileElement = privateElement->findFirstChildElementChecked("encryptedProfile");
ElementPtr saltElement = privateElement->findFirstChildElementChecked("salt");
String saltAsBase64 = saltElement->getText(true);
SecureByteBlock output;
decryptAndNulTerminateFromBase64(
"profile",
mContactProfileSecret,
saltAsBase64,
profileElement->getText(true),
output
);
String parseData = (CSTR)((const BYTE *)output);
DocumentPtr temp = Document::create();
temp->parse(parseData);
ElementPtr result = temp->findFirstChildElementChecked("profile");
result->orphan();
return result;
} catch (zsLib::XML::Exceptions::CheckFailed &) {
}
return ElementPtr();
}
示例7: AsDocument
void OGRLIBKMLLayer::SetStyleTableDirectly( OGRStyleTable * poStyleTable )
{
if( !bUpdate || m_poKmlLayer == NULL )
return;
KmlFactory *poKmlFactory = m_poOgrDS->GetKmlFactory();
if( m_poStyleTable )
delete m_poStyleTable;
m_poStyleTable = poStyleTable;
if( m_poKmlLayer->IsA( kmldom::Type_Document ) )
{
/***** delete all the styles *****/
DocumentPtr poKmlDocument = AsDocument( m_poKmlLayer );
const int nKmlStyles =
static_cast<int>(poKmlDocument->get_schema_array_size());
for( int iKmlStyle = nKmlStyles - 1; iKmlStyle >= 0; iKmlStyle-- )
{
poKmlDocument->DeleteStyleSelectorAt( iKmlStyle );
}
/***** add the new style table to the document *****/
styletable2kml( poStyleTable, poKmlFactory,
AsContainer( poKmlDocument ) );
}
/***** mark the layer as updated *****/
bUpdated = true;
m_poOgrDS->Updated();
}
示例8: FieldCacheSanityCheckerTestFixture
FieldCacheSanityCheckerTestFixture()
{
RAMDirectoryPtr dirA = newLucene<RAMDirectory>();
RAMDirectoryPtr dirB = newLucene<RAMDirectory>();
IndexWriterPtr wA = newLucene<IndexWriter>(dirA, newLucene<WhitespaceAnalyzer>(), true, IndexWriter::MaxFieldLengthLIMITED);
IndexWriterPtr wB = newLucene<IndexWriter>(dirB, newLucene<WhitespaceAnalyzer>(), true, IndexWriter::MaxFieldLengthLIMITED);
int64_t theLong = LLONG_MAX;
double theDouble = DBL_MAX;
uint8_t theByte = UCHAR_MAX;
int32_t theInt = INT_MAX;
for (int32_t i = 0; i < NUM_DOCS; ++i)
{
DocumentPtr doc = newLucene<Document>();
doc->add(newLucene<Field>(L"theLong", StringUtils::toString(theLong--), Field::STORE_NO, Field::INDEX_NOT_ANALYZED));
doc->add(newLucene<Field>(L"theDouble", StringUtils::toString(theDouble--), Field::STORE_NO, Field::INDEX_NOT_ANALYZED));
doc->add(newLucene<Field>(L"theByte", StringUtils::toString(theByte--), Field::STORE_NO, Field::INDEX_NOT_ANALYZED));
doc->add(newLucene<Field>(L"theInt", StringUtils::toString(theInt--), Field::STORE_NO, Field::INDEX_NOT_ANALYZED));
if (i % 3 == 0)
wA->addDocument(doc);
else
wB->addDocument(doc);
}
wA->close();
wB->close();
readerA = IndexReader::open(dirA, true);
readerB = IndexReader::open(dirB, true);
readerX = newLucene<MultiReader>(newCollection<IndexReaderPtr>(readerA, readerB));
}
示例9: encode
//---------------------------------------------------------------------
DocumentPtr LockboxContentGetRequest::encode()
{
DocumentPtr ret = IMessageHelper::createDocumentWithRoot(*this);
ElementPtr root = ret->getFirstChildElement();
String clientNonce = IHelper::randomString(32);
LockboxInfo lockboxInfo;
lockboxInfo.mAccessToken = mLockboxInfo.mAccessToken;
if (mLockboxInfo.mAccessSecret.hasData()) {
lockboxInfo.mAccessSecretProofExpires = zsLib::now() + Seconds(OPENPEER_STACK_MESSAGE_LOCKBOX_CONTENT_GET_REQUEST_EXPIRES_TIME_IN_SECONDS);
lockboxInfo.mAccessSecretProof = IHelper::convertToHex(*IHelper::hmac(*IHelper::hmacKeyFromPassphrase(mLockboxInfo.mAccessSecret), "lockbox-access-validate:" + clientNonce + ":" + IHelper::timeToString(lockboxInfo.mAccessSecretProofExpires) + ":" + lockboxInfo.mAccessToken + ":lockbox-content-get"));
}
root->adoptAsLastChild(IMessageHelper::createElementWithText("nonce", clientNonce));
if (lockboxInfo.hasData()) {
root->adoptAsLastChild(MessageHelper::createElement(lockboxInfo));
}
ElementPtr namespacesEl = IMessageHelper::createElement("namespaces");
for (NamespaceInfoMap::iterator iter = mNamespaceInfos.begin(); iter != mNamespaceInfos.end(); ++iter)
{
const NamespaceInfo &namespaceInfo = (*iter).second;
namespacesEl->adoptAsLastChild(MessageHelper::createElement(namespaceInfo));
}
if (namespacesEl->hasChildren()) {
root->adoptAsLastChild(namespacesEl);
}
return ret;
}
示例10: docSource
void TrecDocumentProcessorTestCase::testProcessGZipFile()
{
TrecDocumentProcessor processor;
processor.init(m_pDocSchema.get(), m_pDocTemp.get());
DocumentSource docSource(m_pDocSchema.get());
RawDocumentPtr pRawDoc = new RawDocument();
pRawDoc->setPath(getTestPath() + "/1.gz");
docSource.setRawDocument(pRawDoc);
Answer ans;
makeAnswer(TEST_FILE2, ans);
size_t i = 0;
do
{
processor.process(docSource);
DocumentPtr pDoc = docSource.stealLastDocument();
CPPUNIT_ASSERT(pDoc);
Document::Iterator it = pDoc->iterator();
while (it.hasNext())
{
const Field* pField = it.next();
CPPUNIT_ASSERT_EQUAL(ans[i].first, pField->getFieldSchema()->getName());
CPPUNIT_ASSERT_EQUAL(ans[i].second, std::string(pField->getValue().c_str()));
++i;
}
} while(docSource.toBeContinued());
CPPUNIT_ASSERT_EQUAL(ans.size(), i);
}
示例11: checkAgainstRAMDirectory
/// Build a randomish document for both RAMDirectory and MemoryIndex, and run all the queries against it.
void checkAgainstRAMDirectory() {
StringStream fooField;
StringStream termField;
// add up to 250 terms to field "foo"
int32_t fieldCount = random->nextInt(250) + 1;
for (int32_t i = 0; i < fieldCount; ++i) {
fooField << L" " << randomTerm();
}
// add up to 250 terms to field "foo"
int32_t termCount = random->nextInt(250) + 1;
for (int32_t i = 0; i < termCount; ++i) {
termField << L" " << randomTerm();
}
RAMDirectoryPtr ramdir = newLucene<RAMDirectory>();
AnalyzerPtr analyzer = randomAnalyzer();
IndexWriterPtr writer = newLucene<IndexWriter>(ramdir, analyzer, IndexWriter::MaxFieldLengthUNLIMITED);
DocumentPtr doc = newLucene<Document>();
FieldPtr field1 = newLucene<Field>(L"foo", fooField.str(), Field::STORE_NO, Field::INDEX_ANALYZED);
FieldPtr field2 = newLucene<Field>(L"term", termField.str(), Field::STORE_NO, Field::INDEX_ANALYZED);
doc->add(field1);
doc->add(field2);
writer->addDocument(doc);
writer->close();
MemoryIndexPtr memory = newLucene<MemoryIndex>();
memory->addField(L"foo", fooField.str(), analyzer);
memory->addField(L"term", termField.str(), analyzer);
checkAllQueries(memory, ramdir, analyzer);
}
示例12: writeTestFile
void TrecDocumentProcessorTestCase::testProcessFileMisField()
{
string sPath = writeTestFile("trec_file3.txt", TEST_FILE_MISS_FIELD);
TrecDocumentProcessor processor;
processor.init(m_pDocSchema.get(), m_pDocTemp.get());
DocumentSource docSource(m_pDocSchema.get());
RawDocumentPtr pRawDoc = new RawDocument();
pRawDoc->setPath(sPath);
docSource.setRawDocument(pRawDoc);
processor.process(docSource);
DocumentPtr pDoc = docSource.stealLastDocument();
CPPUNIT_ASSERT(pDoc);
Answer ans;
makeAnswer(TEST_FILE_MISS_FIELD, ans);
Document::Iterator it = pDoc->iterator();
CPPUNIT_ASSERT_EQUAL(ans.size(), it.size());
size_t i = 0;
while (it.hasNext())
{
const Field* pField = it.next();
// cout << ans[i].first << " : " << ans[i].second << endl;
CPPUNIT_ASSERT_EQUAL(ans[i].first, pField->getFieldSchema()->getName());
CPPUNIT_ASSERT_EQUAL(ans[i].second, std::string(pField->getValue().c_str()));
++i;
}
}
示例13: st
void DateTimeIndexTestCase::buildDateTimeIndex(const string& sDocs)
{
try
{
DocumentSchema schema;
schema.addField("DateTime1", "DATETIME_I", true);
Index index;
index.open(getIndexPath(), Index::WRITE, &schema);
IndexWriterPtr pIndexWriter = index.acquireWriter();
StringTokenizer st(sDocs, ";", StringTokenizer::TOKEN_TRIM |
StringTokenizer::TOKEN_IGNORE_EMPTY);
for (StringTokenizer::Iterator it = st.begin(); it != st.end(); ++it)
{
DocumentPtr pDoc = new Document(pIndexWriter->getDocSchema());
pDoc->addField(0, (*it).c_str());
pIndexWriter->addDocument(pDoc);
}
pIndexWriter->close();
}
catch (const FirteXException& )
{
CPPUNIT_ASSERT(false);
}
}
示例14: index
void index(const tstring& sDir)
{
IndexWriterPtr pIndexWriter = m_pIndex->acquireWriter();
DirectoryIterator di(sDir, false);
while(di.hasNext())
{
const File& f = di.next();
if(f.isFile())
{
BinaryFile bf;
bf.open(f.getPath().c_str(), BinaryFile::READ);
if(bf.isFileOpen())
{
size_t nRead = (size_t)bf.getLength();
if (nRead > 0)
{
DocumentPtr pDoc = new Document(pIndexWriter->getDocSchema());
pDoc->addField(0, f.getPath().c_str());
char* buf = new char[nRead + 1];
bf.read(buf, nRead);
buf[nRead] = 0;
pDoc->addField(1, buf, nRead, false);
delete[] buf;
pIndexWriter->addDocument(pDoc);
}
}
}
}
docPool.commit();
pIndexWriter->close();
}
示例15: encode
//---------------------------------------------------------------------
DocumentPtr IdentityLookupRequest::encode()
{
DocumentPtr ret = IMessageHelper::createDocumentWithRoot(*this);
ElementPtr root = ret->getFirstChildElement();
ElementPtr providersEl = Element::create("providers");
for (ProviderList::iterator iter = mProviders.begin(); iter != mProviders.end(); ++iter)
{
Provider &info = (*iter);
ElementPtr providerEl = Element::create("provider");
if (!info.mBase.isEmpty()) {
providerEl->adoptAsLastChild(IMessageHelper::createElementWithTextAndJSONEncode("base", info.mBase));
}
if (!info.mSeparator.isEmpty()) {
providerEl->adoptAsLastChild(IMessageHelper::createElementWithTextAndJSONEncode("separator", info.mSeparator));
}
if (!info.mIdentities.isEmpty()) {
providerEl->adoptAsLastChild(IMessageHelper::createElementWithTextAndJSONEncode("identities", info.mIdentities));
}
if (providerEl) {
providersEl->adoptAsLastChild(providerEl);
}
}
if (providersEl->hasChildren()) {
root->adoptAsLastChild(providersEl);
}
return ret;
}