<commit_before>//
//  CLuceneSearchResults.mm
//  BRFullTextSearch
//
//  Created by Matt on 7/1/13.
//  Copyright (c) 2013 Blue Rocket. Distributable under the terms of the Apache License, Version 2.0.
//

#import "CLuceneSearchResults.h"

#import "CLucene.h"
#import "CLuceneSearchResult.h"
#import "NSString+CLuceneAdditions.h"

using namespace lucene::document;
using namespace lucene::search;

@implementation CLuceneSearchResults {
	std::auto_ptr<Hits> hits;
	std::auto_ptr<Sort> sort;
	std::auto_ptr<Query> query;
	std::tr1::shared_ptr<Searcher> searcher;
}

- (id)initWithHits:(std::auto_ptr<lucene::search::Hits>)theHits
			  sort:(std::auto_ptr<lucene::search::Sort>)theSort
			 query:(std::auto_ptr<lucene::search::Query>)theQuery
		  searcher:(std::tr1::shared_ptr<lucene::search::Searcher>)theSearcher {
	if ( (self = [super init]) ) {
		hits = theHits;
		sort = theSort;
		query = theQuery;
		searcher = theSearcher;
	}
	return self;
}

- (NSUInteger)count {
	return (NSUInteger)hits->length();
}

- (id<BRSearchResult>)resultAtIndex:(NSUInteger)index {
	Document &doc = hits->doc(index);
	return [[[CLuceneSearchResult searchResultClassForDocument:doc] alloc] initWithHits:hits.get() index:index];
}

- (void)iterateWithBlock:(BRSearchServiceSearchResultsIterator)iterator {
	BOOL stop = NO;
	int32_t i;
	size_t len;
	for ( i = 0, len = hits->length(); i < len && stop == NO; i++ ) {
		@autoreleasepool {
			Document &doc = hits->doc(i);
			CLuceneSearchResult *result = [[[CLuceneSearchResult searchResultClassForDocument:doc] alloc] initWithHits:hits.get() index:i];
			iterator(i, result, &stop);
		}
	}
}

- (NSArray *)resultsGroupedByField:(NSString *)fieldName {
	NSMutableArray *result = [NSMutableArray new];
	NSMutableArray *currGroup = nil;
	id lastValue = nil;
	int32_t i;<commit_msg>Fix compiler warnings on casts.<commit_after>//
//  CLuceneSearchResults.mm
//  BRFullTextSearch
//
//  Created by Matt on 7/1/13.
//  Copyright (c) 2013 Blue Rocket. Distributable under the terms of the Apache License, Version 2.0.
//

#import "CLuceneSearchResults.h"

#import "CLucene.h"
#import "CLuceneSearchResult.h"
#import "NSString+CLuceneAdditions.h"

using namespace lucene::document;
using namespace lucene::search;

@implementation CLuceneSearchResults {
	std::auto_ptr<Hits> hits;
	std::auto_ptr<Sort> sort;
	std::auto_ptr<Query> query;
	std::tr1::shared_ptr<Searcher> searcher;
}

- (id)initWithHits:(std::auto_ptr<lucene::search::Hits>)theHits
			  sort:(std::auto_ptr<lucene::search::Sort>)theSort
			 query:(std::auto_ptr<lucene::search::Query>)theQuery
		  searcher:(std::tr1::shared_ptr<lucene::search::Searcher>)theSearcher {
	if ( (self = [super init]) ) {
		hits = theHits;
		sort = theSort;
		query = theQuery;
		searcher = theSearcher;
	}
	return self;
}

- (NSUInteger)count {
	return (NSUInteger)hits->length();
}

- (id<BRSearchResult>)resultAtIndex:(NSUInteger)index {
	int32_t luceneIndex = (int32_t)index;
	Document &doc = hits->doc(luceneIndex);
	return [[[CLuceneSearchResult searchResultClassForDocument:doc] alloc] initWithHits:hits.get() index:luceneIndex];
}

- (void)iterateWithBlock:(BRSearchServiceSearchResultsIterator)iterator {
	BOOL stop = NO;
	int32_t i;
	size_t len;
	for ( i = 0, len = hits->length(); i < len && stop == NO; i++ ) {
		@autoreleasepool {
			Document &doc = hits->doc(i);
			CLuceneSearchResult *result = [[[CLuceneSearchResult searchResultClassForDocument:doc] alloc] initWithHits:hits.get() index:i];
			iterator(i, result, &stop);
		}
	}
}

- (NSArray *)resultsGroupedByField:(NSString *)fieldName {
	NSMutableArray *result = [NSMutableArray new];
	NSMutableArray *currGroup = nil;
	id lastValue = nil;
	int32_t i;
{'fraction_non_alphanumeric': 0.147194361615614, 'fraction_numerical': 0.010300894551368935, 'mean_word_length': 5.577540106951871, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3818689', 'n_tokens_mistral': 1426, 'n_tokens_neox': 1335, 'n_words': 256}