the-algorithm/src/java/com/twitter/search/earlybird/search/facets/TweetSearchFacetCountIteratorFactory.java
twitter-team ef4c5eb65e Twitter Recommendation Algorithm
Please note we have force-pushed a new initial commit in order to remove some publicly-available Twitter user information. Note that this process may be required in the future.
2023-03-31 17:36:31 -05:00

42 lines
1.6 KiB
Java

package com.twitter.search.earlybird.search.facets;
import java.io.IOException;
import com.google.common.base.Preconditions;
import com.twitter.search.common.schema.base.Schema;
import com.twitter.search.common.schema.earlybird.EarlybirdFieldConstants.EarlybirdFieldConstant;
import com.twitter.search.core.earlybird.facets.CSFFacetCountIterator;
import com.twitter.search.core.earlybird.facets.FacetCountIterator;
import com.twitter.search.core.earlybird.facets.FacetCountIteratorFactory;
import com.twitter.search.core.earlybird.index.EarlybirdIndexSegmentAtomicReader;
/**
* Factory of {@link FacetCountIterator} instances for tweet search.
* It provides a special iterator for the retweets facet.
*/
public final class TweetSearchFacetCountIteratorFactory extends FacetCountIteratorFactory {
public static final TweetSearchFacetCountIteratorFactory FACTORY =
new TweetSearchFacetCountIteratorFactory();
private TweetSearchFacetCountIteratorFactory() {
}
@Override
public FacetCountIterator getFacetCountIterator(
EarlybirdIndexSegmentAtomicReader reader,
Schema.FieldInfo fieldInfo) throws IOException {
Preconditions.checkNotNull(reader);
Preconditions.checkNotNull(fieldInfo);
Preconditions.checkArgument(fieldInfo.getFieldType().isUseCSFForFacetCounting());
String facetName = fieldInfo.getFieldType().getFacetName();
if (EarlybirdFieldConstant.RETWEETS_FACET.equals(facetName)) {
return new RetweetFacetCountIterator(reader, fieldInfo);
} else {
return new CSFFacetCountIterator(reader, fieldInfo);
}
}
}