本文整理汇总了C++中Hits类的典型用法代码示例。如果您正苦于以下问题:C++ Hits类的具体用法?C++ Hits怎么用?C++ Hits使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Hits类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _TestSearchesRun
void _TestSearchesRun(CuTest *tc, Analyzer* analyzer, Searcher* search, const TCHAR* qry){
Query* q = NULL;
Hits* h = NULL;
try{
q = QueryParser::parse(qry , _T("contents"), analyzer);
if ( q != NULL ){
h = search->search( q );
if ( h->length() > 0 ){
//check for explanation memory leaks...
CL_NS(search)::Explanation expl1;
search->explain(q, h->id(0), &expl1);
TCHAR* tmp = expl1.toString();
_CLDELETE_CARRAY(tmp);
if ( h->length() > 1 ){ //do a second one just in case
CL_NS(search)::Explanation expl2;
search->explain(q, h->id(1), &expl2);
tmp = expl2.toString();
_CLDELETE_CARRAY(tmp);
}
}
}
}catch(CLuceneError& err){
CuFail(tc,_T("Error: %s\n"), err.twhat());
}catch(...){
CuFail(tc,_T("Error: unknown\n"));
}
_CLDELETE(h);
_CLDELETE(q);
}
示例2: StringResponse
/**
Returns a Entry.
\id The key of the entry.
*/
Response * ZefaniaLex::getEntry(const QString &key)
{
try {
if(!hasIndex()) {
if(buildIndex() != 0) {
return new StringResponse(QObject::tr("Cannot build index."));
}
}
const QString index = indexPath();
const QString queryText = "key:" + key;
const TCHAR* stop_words[] = { nullptr };
standard::StandardAnalyzer analyzer(stop_words);
IndexReader* reader = IndexReader::open(index.toStdString().c_str());
IndexSearcher s(reader);
Query* q = QueryParser::parse(SearchTools::toTCHAR(queryText), _T("content"), &analyzer);
Hits* h = s.search(q);
QString ret = "";
for(size_t i = 0; i < h->length(); i++) {
Document* doc = &h->doc(i);
if(!ret.isEmpty())
ret.append("<hr /> ");
ret.append(SearchTools::toQString(doc->get(_T("content"))));
}
return ret.isEmpty() ? new StringResponse(QObject::tr("Nothing found for %1").arg(key)) : new StringResponse(ret);
} catch(...) {
return new StringResponse(QString());
}
}
示例3: testEqualScores
void testEqualScores()
{
// NOTE: uses index build in *this* setUp
IndexReader * pReader = IndexReader::open( m_pSmall );
IndexSearcher * pSearch = _CLNEW IndexSearcher( pReader );
Hits * pResult;
// some hits match more terms then others, score should be the same
Query * q = csrq( _T( "data" ), _T( "1" ), _T( "6" ), true, true );
pResult = pSearch->search( q );
size_t numHits = pResult->length();
assertEqualsMsg( _T( "wrong number of results" ), 6, numHits );
float_t score = pResult->score( 0 );
for( size_t i = 1; i < numHits; i++ )
{
assertTrueMsg( _T( "score was not the same" ), score == pResult->score( i ));
}
_CLDELETE( pResult );
_CLDELETE( q );
pSearch->close();
_CLDELETE( pSearch );
pReader->close();
_CLDELETE( pReader );
}
示例4: GetShipIndicesWeakestFirst
ShipBattle::Hits ShipBattle::GetHitsToDestroy(const Group& group, Dice& dice, int toHit) const
{
const auto shipIndices = GetShipIndicesWeakestFirst(group);
Hits hits;
for (int shipIndex : shipIndices)
{
int lives = group.lifeCounts[shipIndex];
Dice used = dice.Remove(lives, toHit);
if (used.empty())
break; // Can't destroy any more ships in this group.
// We can destroy this ship.
int damage = used.GetDamage();
if (damage > lives) // Don't want to waste damage. Can we destroy a healthier ship?
{
for (int shipIndex2 : shipIndices)
if (group.lifeCounts[shipIndex2] == damage)
{
// We can destroy this one with no waste.
shipIndex = shipIndex2;
lives = damage;
break;
}
}
hits.push_back(Hit(group.shipType, shipIndex, used));
}
return hits;
}
示例5: SearchFilesC
void SearchFilesC(const char* index, const char* fobizzle){
standard::StandardAnalyzer analyzer;
char line[80];
TCHAR tline[80];
TCHAR* buf;
IndexReader* reader = IndexReader::open(index);
//printf("Enter query string: ");
strncpy(line,fobizzle,80);
//line[strlen(line)-1]=0;
IndexReader* newreader = reader->reopen();
if ( newreader != reader ){
_CLLDELETE(reader);
reader = newreader;
}
IndexSearcher s(reader);
STRCPY_AtoT(tline,line,80);
Query* q = QueryParser::parse(tline,_T("contents"),&analyzer);
buf = q->toString(_T("contents"));
_tprintf(_T("Searching for: %S\n\n"), buf);
_CLDELETE_LCARRAY(buf);
uint64_t str = Misc::currentTimeMillis();
Hits* h = s.search(q);
uint32_t srch = (int32_t)(Misc::currentTimeMillis() - str);
str = Misc::currentTimeMillis();
//SearchData search[h->length()];
for ( size_t i=0; i < h->length(); i++ ){
Document* doc = &h->doc(i);
//const TCHAR* buf = doc.get(_T("contents"));
_tprintf(_T("%d. %S - %f\n"), i, doc->get(_T("path")), h->score(i));
//search[i].set_path(doc->get(_T("path")));
}
printf("\n\nSearch took: %d ms.\n", srch);
printf("Screen dump took: %d ms.\n\n", (int32_t)(Misc::currentTimeMillis() - str));
_CLLDELETE(h);
_CLLDELETE(q);
s.close();
reader->close();
_CLLDELETE(reader);
};
示例6: testBoost
void testBoost()
{
// NOTE: uses index build in *this* setUp
IndexReader * pReader = IndexReader::open( m_pSmall );
IndexSearcher * pSearch = _CLNEW IndexSearcher( pReader );
Hits * pResult;
// test for correct application of query normalization
// must use a non score normalizing method for this.
Query * q = csrq( _T( "data" ), _T( "1" ), _T( "6" ), true, true );
q->setBoost( 100 );
pResult = pSearch->search( q );
for( size_t i = 1; i < pResult->length(); i++ )
{
assertTrueMsg( _T( "score was not was not correct" ), 1.0f == pResult->score( i ));
}
_CLDELETE( pResult );
_CLDELETE( q );
//
// Ensure that boosting works to score one clause of a query higher
// than another.
//
Query * q1 = csrq( _T( "data" ), _T( "A" ), _T( "A" ), true, true ); // matches document #0
q1->setBoost( .1f );
Query * q2 = csrq( _T( "data" ), _T( "Z" ), _T( "Z" ), true, true ); // matches document #1
BooleanQuery * bq = _CLNEW BooleanQuery( true );
bq->add( q1, true, BooleanClause::SHOULD );
bq->add( q2, true, BooleanClause::SHOULD );
pResult = pSearch->search( bq );
assertEquals( 1, pResult->id( 0 ));
assertEquals( 0, pResult->id( 1 ));
assertTrue( pResult->score( 0 ) > pResult->score( 1 ));
_CLDELETE( pResult );
_CLDELETE( bq );
q1 = csrq( _T( "data" ), _T( "A" ), _T( "A" ), true, true ); // matches document #0
q1->setBoost( 10.0f );
q2 = csrq( _T( "data" ), _T( "Z" ), _T( "Z" ), true, true ); // matches document #1
bq = _CLNEW BooleanQuery( true );
bq->add( q1, true, BooleanClause::SHOULD );
bq->add( q2, true, BooleanClause::SHOULD );
pResult = pSearch->search( bq );
assertEquals( 0, pResult->id( 0 ));
assertEquals( 1, pResult->id( 1 ));
assertTrue( pResult->score( 0 ) > pResult->score( 1 ));
_CLDELETE( pResult );
_CLDELETE( bq );
pSearch->close();
_CLDELETE( pSearch );
pReader->close();
_CLDELETE( pReader );
}
示例7:
bool
Picker::getObjectIDs(const Hits& results, std::set<ObjectID>& out_objectIDs) const
{
ObjectIndex* index = Registry::objectIndex();
for(Hits::const_iterator hit = results.begin(); hit != results.end(); ++hit)
{
bool found = false;
// check for the uniform.
const osg::NodePath& path = hit->nodePath;
for(osg::NodePath::const_reverse_iterator n = path.rbegin(); n != path.rend(); ++n )
{
osg::Node* node = *n;
if ( node && node->getStateSet() )
{
osg::Uniform* u = node->getStateSet()->getUniform( index->getObjectIDUniformName() );
if ( u )
{
ObjectID oid;
if ( u->get(oid) )
{
out_objectIDs.insert( oid );
found = true;
}
}
}
}
if ( !found )
{
// check the geometry.
const osg::Geometry* geom = hit->drawable ? hit->drawable->asGeometry() : 0L;
if ( geom )
{
const ObjectIDArray* ids = dynamic_cast<const ObjectIDArray*>( geom->getVertexAttribArray(index->getObjectIDAttribLocation()) );
if ( ids )
{
for(unsigned i=0; i < hit->indexList.size(); ++i)
{
unsigned index = hit->indexList[i];
if ( index < ids->size() )
{
ObjectID oid = (*ids)[index];
out_objectIDs.insert( oid );
}
}
}
}
}
}
return !out_objectIDs.empty();
}
示例8: testIncludeLowerTrue
void testIncludeLowerTrue(CuTest* tc)
{
WhitespaceAnalyzer a;
RAMDirectory* index = _CLNEW RAMDirectory();
IndexWriter* writer = _CLNEW IndexWriter(index,
&a, true);
Document doc;
doc.add(*_CLNEW Field(_T("Category"), _T("a 1"), Field::STORE_YES | Field::INDEX_TOKENIZED));
writer->addDocument(&doc); doc.clear();
doc.add(*_CLNEW Field(_T("Category"), _T("a 2"), Field::STORE_YES | Field::INDEX_TOKENIZED));
writer->addDocument(&doc); doc.clear();
doc.add(*_CLNEW Field(_T("Category"), _T("a 3"), Field::STORE_YES | Field::INDEX_TOKENIZED));
writer->addDocument(&doc); doc.clear();
writer->close();
_CLLDELETE(writer);
IndexSearcher* s = _CLNEW IndexSearcher(index);
Filter* f = _CLNEW RangeFilter(_T("Category"), _T("3"), _T("3"), true, true);
Term* t = _CLNEW Term(_T("Category"), _T("a"));
Query* q1 = _CLNEW TermQuery(t);
_CLLDECDELETE(t);
t = _CLNEW Term(_T("Category"), _T("3"));
Query* q2 = _CLNEW TermQuery(t);
_CLLDECDELETE(t);
Hits* h = s->search(q1);
assertTrue(h->length() == 3);
_CLLDELETE(h);
h = s->search(q2);
assertTrue(h->length() == 1);
_CLLDELETE(h);
h = s->search(q1, f);
assertTrue(h->length() == 1);
_CLLDELETE(h);
s->close();
_CLLDELETE(s);
_CLLDELETE(q1);
_CLLDELETE(q2);
_CLLDELETE(f);
index->close();
_CLLDECDELETE(index);
}
示例9: Q_ASSERT
QMap< int, float >
FuzzyIndex::searchAlbum( const Tomahawk::query_ptr& query )
{
Q_ASSERT( query->isFullTextQuery() );
QMutexLocker lock( &m_mutex );
QMap< int, float > resultsmap;
try
{
if ( !m_luceneReader )
{
if ( !IndexReader::indexExists( TomahawkUtils::appDataDir().absoluteFilePath( "tomahawk.lucene" ).toStdString().c_str() ) )
{
qDebug() << Q_FUNC_INFO << "index didn't exist.";
return resultsmap;
}
m_luceneReader = IndexReader::open( m_luceneDir );
m_luceneSearcher = _CLNEW IndexSearcher( m_luceneReader );
}
QueryParser parser( _T( "album" ), m_analyzer );
QString escapedName = QString::fromWCharArray( parser.escape( DatabaseImpl::sortname( query->fullTextQuery() ).toStdWString().c_str() ) );
Query* qry = _CLNEW FuzzyQuery( _CLNEW Term( _T( "album" ), escapedName.toStdWString().c_str() ) );
Hits* hits = m_luceneSearcher->search( qry );
for ( uint i = 0; i < hits->length(); i++ )
{
Document* d = &hits->doc( i );
float score = hits->score( i );
int id = QString::fromWCharArray( d->get( _T( "albumid" ) ) ).toInt();
if ( score > 0.30 )
{
resultsmap.insert( id, score );
// tDebug() << "Index hit:" << id << score;
}
}
delete hits;
delete qry;
}
catch( CLuceneError& error )
{
tDebug() << "Caught CLucene error:" << error.what();
Q_ASSERT( false );
}
return resultsmap;
}
示例10: EIO_Search
static int EIO_Search(eio_req* req)
{
search_baton_t* baton = static_cast<search_baton_t*>(req->data);
standard::StandardAnalyzer analyzer;
IndexReader* reader = 0;
try {
reader = IndexReader::open(*(*baton->index));
} catch (CLuceneError& E) {
baton->error.assign(E.what());
return 0;
} catch(...) {
baton->error = "Got an unknown exception";
return 0;
}
IndexReader* newreader = reader->reopen();
if ( newreader != reader ) {
delete reader;
reader = newreader;
}
IndexSearcher s(reader);
try {
TCHAR* searchString = STRDUP_AtoT(*(*baton->search));
Query* q = QueryParser::parse(searchString, _T(""), &analyzer);
Hits* hits = s.search(q);
HandleScope scope;
//_CLDELETE(q);
free(searchString);
// Build the result array
Local<v8::Array> resultArray = v8::Array::New();
for (size_t i=0; i < hits->length(); i++) {
Document& doc(hits->doc(i));
// {"id":"ab34", "score":1.0}
Local<Object> resultObject = Object::New();
// TODO: This dup might be a leak
resultObject->Set(String::New("id"), String::New(STRDUP_TtoA(doc.get(_T("_id")))));
resultObject->Set(String::New("score"), Number::New(hits->score(i)));
resultArray->Set(i, resultObject);
}
baton->results = Persistent<v8::Array>::New(resultArray);
} catch (CLuceneError& E) {
baton->error.assign(E.what());
} catch(...) {
baton->error = "Got an unknown exception";
}
return 0;
}
示例11: searcher
vector<pair<string,uint32_t> >
CLuceneIndexReader::histogram(const string& query,
const string& fieldname, const string& labeltype) {
vector<pair<string,uint32_t> > h;
if (!checkReader()) {
return h;
}
Strigi::QueryParser parser;
Strigi::Query q = parser.buildQuery(query);
Query* bq = p->createQuery(q);
IndexSearcher searcher(reader);
Hits* hits = 0;
int s = 0;
try {
hits = searcher.search(bq);
s = hits->length();
} catch (CLuceneError& err) {
fprintf(stderr, "could not query: %s\n", err.what());
}
wstring field = utf8toucs2(fieldname);
int32_t max = INT_MIN;
int32_t min = INT_MAX;
vector<int32_t> values;
values.reserve(s);
char* end;
for (int i = 0; i < s; ++i) {
Document *d = &hits->doc(i);
const TCHAR* v = d->get(field.c_str());
if (v) {
int val = (int)strtol(wchartoutf8( v ).c_str(), &end, 10);
if ( *end != 0) {
_CLDELETE(hits);
return h;
}
values.push_back(val);
max = (max>val) ?max :val;
min = (min<val) ?min :val;
}
}
if (hits) {
_CLDELETE(hits);
}
searcher.close();
_CLDELETE(bq);
if (fieldname == FieldRegister::mtimeFieldName || labeltype == "time") {
return makeTimeHistogram(values);
} else {
return makeHistogram(values, min, max);
}
}
示例12: countDocuments
int32_t
CLuceneIndexReader::countHits(const Strigi::Query& q) {
if (!checkReader()) return -1;
// if the query is empty, we return the number of files in the index
if (q.term().string().size() == 0 && q.subQueries().size() == 0) {
return countDocuments();
}
Query* bq = p->createQuery(q);
if (reader == 0) {
return 0;
}
IndexSearcher searcher(reader);
vector<IndexedDocument> results;
Hits* hits = 0;
int s = 0;
try {
hits = searcher.search(bq);
s = hits->length();
} catch (CLuceneError& err) {
/* HitCounter counter;
QueryFilter* filter = _CLNEW QueryFilter(&bq);
try {
BitSet* bits = filter->bits(reader);
int32_t n = bits->size();
for (int32_t i=0; i<n; ++i) {
if (bits->get(i)) s++;
}
} catch (CLuceneError& err2) {
printf("ccould not query: %s\n", err.what());
}
try {
searcher._search(0, filter, &counter);
} catch (CLuceneError& err2) {
printf("ccould not query: %s\n", err.what());
}
s = counter.count();
printf("counted %i hits\n", count);
// try to do a constant score query
//QueryFilter* filter = _CLNEW QueryFilter(&bq);
ConstantScoreQuery csq(filter);*/
fprintf(stderr, "could not query: %s\n", err.what());
}
delete hits;
searcher.close();
_CLDELETE(bq);
return s;
}
示例13: testBooleanScorer
/// TestBooleanScorer.java, ported 5/9/2009
void testBooleanScorer(CuTest *tc) {
const TCHAR* FIELD = _T("category");
RAMDirectory directory;
TCHAR* values[] = { _T("1"), _T("2"), _T("3"), _T("4"), NULL};
try {
WhitespaceAnalyzer a;
IndexWriter* writer = _CLNEW IndexWriter(&directory, &a, true);
for (size_t i = 0; values[i]!=NULL; i++) {
Document* doc = _CLNEW Document();
doc->add(*_CLNEW Field(FIELD, values[i], Field::STORE_YES | Field::INDEX_TOKENIZED));
writer->addDocument(doc);
_CLLDELETE(doc);
}
writer->close();
_CLLDELETE(writer);
BooleanQuery* booleanQuery1 = _CLNEW BooleanQuery();
Term *t = _CLNEW Term(FIELD, _T("1"));
booleanQuery1->add(_CLNEW TermQuery(t), true, BooleanClause::SHOULD);
_CLDECDELETE(t);
t = _CLNEW Term(FIELD, _T("2"));
booleanQuery1->add(_CLNEW TermQuery(t), true, BooleanClause::SHOULD);
_CLDECDELETE(t);
BooleanQuery* query = _CLNEW BooleanQuery();
query->add(booleanQuery1, true, BooleanClause::MUST);
t = _CLNEW Term(FIELD, _T("9"));
query->add(_CLNEW TermQuery(t), true, BooleanClause::MUST_NOT);
_CLDECDELETE(t);
IndexSearcher *indexSearcher = _CLNEW IndexSearcher(&directory);
Hits *hits = indexSearcher->search(query);
CLUCENE_ASSERT(2 == hits->length()); // Number of matched documents
_CLLDELETE(hits);
_CLLDELETE(indexSearcher);
_CLLDELETE(query);
}
catch (CLuceneError& e) {
CuFail(tc, e.twhat());
}
}
示例14: TermQuery
void
CLuceneIndexReader::getChildren(const std::string& parent,
std::map<std::string, time_t>& children) {
children.clear();
// force a fresh reader. This is important because the function
// getChildren is essential for updating the index
if ( !checkReader(true) ) {
return;
}
// build a query
Term* t = Private::createKeywordTerm(Private::parentlocation(),
parent);
Query* q = _CLNEW TermQuery(t);
_CLDECDELETE(t);
IndexSearcher searcher(reader);
Hits* hits = 0;
int nhits = 0;
try {
hits = searcher.search(q);
nhits = hits->length();
} catch (CLuceneError& err) {
fprintf(stderr, "could not query: %s\n", err.what());
}
const TCHAR* mtime = mapId(Private::mtime());
for (int i = 0; i < nhits; ++i) {
Document* d = &hits->doc(i);
const TCHAR* v = d->get(mtime);
// check that mtime is defined for this document
if (v) {
time_t mtime = atoi(wchartoutf8( v ).c_str());
v = d->get(Private::systemlocation());
if (v) {
children[wchartoutf8( v )] = mtime;
}
}
}
if (hits) {
_CLDELETE(hits);
}
searcher.close();
_CLDELETE(q);
}
示例15: merge
void Cluster::merge(Cluster* anotherCluster){
//Merge the hits
Hits::iterator i = hits.end();
Hits a;
a.push_back(Hit(0,0,0,0));
anotherCluster->get_hits()->splice(i,hits);
//Reset cluster properties
checkIsAtEdge = false;
size = 0;
width = 0;
length = 0;
tot = 0;
centreOfCharge.first = -1;
centreOfCharge.second = -1;
nMissingHits = -1;
}