Пример #1
0
double Soprano::Index::CLuceneIndex::getScore( const Soprano::Node& resource, lucene::search::Query* query )
{
    QMutexLocker lock( &d->mutex );

    clearError();
    try {
        // rewrite the query
        lucene::index::Term queryTerm( idFieldName().data(), TString( d->getId( resource ) ).data() );
        lucene::search::TermQuery idQuery( &queryTerm );
        lucene::search::BooleanQuery combinedQuery;
        combinedQuery.add( &idQuery, true, false );
        combinedQuery.add( query, true, false );

        // fetch the score when the URI matches the original query
        lucene::search::TopDocs* docs = static_cast<lucene::search::Searchable*>( d->getIndexSearcher() )->_search( &combinedQuery, 0, 1 );
        double r = -1.0;
        if ( docs->totalHits > 0 ) {
#ifdef CL_VERSION_19_OR_GREATER
            r = docs->scoreDocs[0].score;
#else
            r = docs->scoreDocs[0]->score;
#endif
        }
        _CLDELETE( docs );
        return r;
    }
    catch( CLuceneError& err ) {
        qDebug() << "search failed: " << err.what();
        setError( exceptionToError( err ) );
        return 0.0;
    }
}
Пример #2
0
double QueryTermScorer::getTokenScore() {
    String termText(termAtt->term());

    WeightedTermPtr queryTerm(termsToFind.get(termText));
    if (!queryTerm) {
        return 0.0;    // not a query term - return
    }

    // found a query term - is it unique in this doc?
    if (!uniqueTermsInFragment.contains(termText)) {
        totalScore += queryTerm->getWeight();;
        uniqueTermsInFragment.add(termText);
    }

    return queryTerm->getWeight();
}