コード例 #1
0
void test_virtually_virtual_new_return_overloaded()
{
	Query *pq = new NameQuery("Rike");
	NameQuery* pnq2 = static_cast<NameQuery *> (pq->clone());
	// there is no need to do the static_cast as you saw before. 
	//
	NameQuery* pnq3 = pnq2->clone();

}
コード例 #2
0
void test_virtually_virtual_new()
{
	Query *pq = new NameQuery("Rike");
	// so this is not working as the 
	// Query::clone() returns Qeury
	//NameQuery * pq2 = pq->clone();
	NameQuery *pnq2 = static_cast<NameQuery *> (pq->clone());
	// but why this is needed of the static cast?
	NameQuery *pnq3 = static_cast<NameQuery *>(pnq2->clone());
}
コード例 #3
0
Query* BooleanQuery::rewrite(Searcher *inSearcher)
{
	size_t size = clauses.size();

	// Optimize 1-clause queries
	if (size == 1) {
		BooleanClause* c = clauses[0];
		// Just return clause
		if (!c->prohibited) {
			// Rewrite first
			Query* query = c->query->rewrite(inSearcher);
			// If the query doesn't actually get re-written, then return a clone
			// (because the BooleanQuery will register different to the returned query)
			if (query == c->query)
				query = query->clone();
			// Incorporate boost
			if (getBoost() != 1.0f) {
				query->setBoost(getBoost() * query->getBoost());
			}
			return query;
		}
	}

	// Recursively rewrite
	BooleanQuery* clone = NULL;
	for (uint32_t i = 0 ; i < size; i++) {
		BooleanClause* c = clauses[i];
		Query* query = c->query->rewrite(inSearcher);
		if (query != c->query) {
			// Clause rewrote: must clone
			if (clone == NULL)
				clone = static_cast<BooleanQuery *>(this->clone());
			// todo: check if delete query should be on...
			// in fact we should try and get rid of these for compatibility sake
			clone->clauses.set(i, _CLNEW BooleanClause(query, true, c->required, c->prohibited));
		}
	}
	if (clone != NULL) {
		return clone; // Some clauses rewrote
	}
	else
		return this; // No clauses rewrote
}