Permalink
Browse files

Fixed compilation issue with Generics

Added the new method at ActivityRangeFacetHandler to support relevance
  • Loading branch information...
1 parent 7f77313 commit 96b94cd6606e9f39eda4288f225c4c9c88cbc5b0 vzhabiuk committed Jun 19, 2012
@@ -450,7 +450,7 @@ public static SenseiSystemInfo buildFacets(JSONObject schemaObj, SenseiPluginReg
+ facet, e);
}
}
- facets.addAll((Collection<? extends FacetHandler<?>>) pluggableSearchEngineManager.createFacetHandlers());
+ facets.addAll(pluggableSearchEngineManager.createFacetHandlers());
// uid facet handler to be added by default
UIDFacetHandler uidHandler = new UIDFacetHandler(UID_FACET_NAME);
facets.add(uidHandler);
@@ -6,6 +6,7 @@
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -54,15 +55,18 @@
private CustomIndexingPipeline _customIndexingPipeline = null;
- private final PluggableSearchEngineManager pluggableSearchEngineManager;
+
- private Set<String> nonLuceneFields;
-
- public DefaultJsonSchemaInterpreter(SenseiSchema schema, PluggableSearchEngineManager pluggableSearchEngineManager) throws ConfigurationException{
+ private Set<String> nonLuceneFields = new HashSet<String>();
+ public DefaultJsonSchemaInterpreter(SenseiSchema schema) throws ConfigurationException {
+ this(schema, null);
+ }
+ public DefaultJsonSchemaInterpreter(SenseiSchema schema, PluggableSearchEngineManager pluggableSearchEngineManager) throws ConfigurationException {
_schema = schema;
- this.pluggableSearchEngineManager = pluggableSearchEngineManager;
- nonLuceneFields = pluggableSearchEngineManager.getFieldNames();
+ if (pluggableSearchEngineManager != null) {
+ nonLuceneFields.addAll(pluggableSearchEngineManager.getFieldNames());
+ }
entries = _schema.getFieldDefMap().entrySet();
_uidField = _schema.getUidField();
_delField = _schema.getDeleteField();
@@ -15,12 +15,15 @@
import org.json.JSONException;
import org.json.JSONObject;
+import proj.zoie.api.DocIDMapper;
+import proj.zoie.api.IndexReaderFactory;
import proj.zoie.api.Zoie;
import proj.zoie.api.ZoieIndexReader;
import proj.zoie.api.ZoieMultiReader;
import proj.zoie.api.ZoieSegmentReader;
import proj.zoie.hourglass.impl.HourglassListener;
+import com.browseengine.bobo.api.BoboIndexReader;
import com.browseengine.bobo.facets.FacetHandler;
import com.senseidb.conf.SenseiConfParams;
import com.senseidb.conf.SenseiSchema;
@@ -34,6 +37,9 @@
import com.senseidb.plugin.SenseiPluginRegistry;
import com.senseidb.search.node.SenseiCore;
import com.senseidb.search.plugin.PluggableSearchEngine;
+import com.yammer.metrics.Metrics;
+import com.yammer.metrics.core.Counter;
+import com.yammer.metrics.core.MetricName;
/**
* Wrapper around all the activity indexes within the Sensei node. It is the entry point to the activity engine.
@@ -48,11 +54,12 @@
public static final String EVENT_TYPE_ONLY_ACTIVITY = "activity-update";
private BaseActivityFilter activityFilter;
private ShardingStrategy shardingStrategy;
- private SenseiCore senseiCore;
+ private SenseiCore senseiCore;
+ private Counter skippedBecauseOfNotFoundUIDCounter;
public CompositeActivityManager() {
-
+ skippedBecauseOfNotFoundUIDCounter = Metrics.newCounter(new MetricName(getClass(), "skippedBecauseOfNotFoundUID"));
}
@@ -134,6 +141,10 @@ public JSONObject acceptEvent(JSONObject event, String version) {
}
ActivityFilteredResult activityFilteredResult = activityFilter.filter(event, senseiSchema, shardingStrategy, senseiCore);
for (long uid : activityFilteredResult.getActivityValues().keySet()) {
+ if (defaultUid != uid && !isUidPresent(uid)) {
+ skippedBecauseOfNotFoundUIDCounter.inc();
+ continue;
+ }
activityValues.update(uid, version, activityFilteredResult.getActivityValues().get(uid));
}
return activityFilteredResult.getFilteredObject();
@@ -143,6 +154,32 @@ public JSONObject acceptEvent(JSONObject event, String version) {
}
+ private boolean isUidPresent(long uid) {
+ /*if (activityValues.uidToArrayIndex.containsKey(uid)) {
+ return true;
+ }
+ for (int partition : senseiCore.getPartitions()) {
+ IndexReaderFactory<ZoieIndexReader<BoboIndexReader>> zoie = senseiCore.getIndexReaderFactory(partition);
+ List<ZoieIndexReader<BoboIndexReader>> indexReaders = null;
+ try {
+ indexReaders = zoie.getIndexReaders();
+ for (ZoieIndexReader<BoboIndexReader> indexReader : indexReaders) {
+ if (indexReader.getDocIDMaper().getDocID(uid) != DocIDMapper.NOT_FOUND) {
+ return true;
+ }
+ }
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ } finally {
+ if (indexReaders != null) {
+ zoie.returnIndexReaders(indexReaders);
+ }
+ }
+ }*/
+ return true;
+ }
+
+
public CompositeActivityValues getActivityValues() {
return activityValues;
}
@@ -232,9 +269,9 @@ public void setSenseiCore(SenseiCore senseiCore) {
@Override
- public List<FacetHandler> createFacetHandlers() {
+ public List<FacetHandler<?>> createFacetHandlers() {
Set<String> facets = getFacetNames();
- List<FacetHandler> ret = new ArrayList<FacetHandler>();
+ List<FacetHandler<?>> ret = new ArrayList<FacetHandler<?>>();
for (FacetDefinition facet : senseiSchema.getFacets()) {
if (!facets.contains(facet.name)) {
continue;
@@ -54,8 +54,10 @@
protected UpdateBatch<Update> updateBatch = new UpdateBatch<Update>();
protected volatile Metadata metadata;
private volatile boolean closed;
+ private Counter reclaimedDocumentsCounter;
+ private Counter currentDocumentsCounter;
private Counter deletedDocumentsCounter;
- private Counter inserteddDocumentsCounter;
+ private Counter insertedDocumentsCounter;
protected CompositeActivityValues() {
}
@@ -69,8 +71,10 @@ public void init(int count) {
for (int i = 0; i < 1024; i++) {
locks[i] = new ReentrantReadWriteLock();
}
- deletedDocumentsCounter = Metrics.newCounter(new MetricName(MetricsConstants.Domain,"deletedDocs","deletedDocs" ,"CompositeActivityStorage"));
- inserteddDocumentsCounter = Metrics.newCounter(new MetricName(MetricsConstants.Domain,"insertedDocs","insertedDocs" ,"CompositeActivityStorage"));
+ reclaimedDocumentsCounter = Metrics.newCounter(new MetricName(getClass(), "reclaimedActivityDocs"));
+ currentDocumentsCounter = Metrics.newCounter(new MetricName(getClass(), "currentActivityDocs"));
+ deletedDocumentsCounter = Metrics.newCounter(new MetricName(getClass(), "deletedActivityDocs"));
+ insertedDocumentsCounter = Metrics.newCounter(new MetricName(getClass(), "insertedActivityDocs"));
}
public ReadWriteLock getLock(long uid) {
return locks[(int) (uid % locks.length)];
@@ -100,6 +104,7 @@ public void update(long uid, final String version, Map<String, Object> map) {
if (uidToArrayIndex.containsKey(uid)) {
index = uidToArrayIndex.get(uid);
} else {
+ insertedDocumentsCounter.inc();
boolean deletedDocsPresent = false;
synchronized (deletedIndexes) {
if (deletedIndexes.size() > 0) {
@@ -179,6 +184,7 @@ public void delete(long... uids) {
if (!uidToArrayIndex.containsKey(uid)) {
continue;
}
+ deletedDocumentsCounter.inc();
int index = uidToArrayIndex.remove(uid);
for (ActivityValues activityIntValues : intValuesMap.values()) {
activityIntValues.delete(index);
@@ -246,7 +252,7 @@ public String getVersion() {
return lastVersion;
}
/**
- * flushes pening updates to disk
+ * flushes pending updates to disk
*/
public synchronized void flush() {
if (closed) {
@@ -262,10 +268,10 @@ public synchronized void flush() {
final int count;
synchronized (deletedIndexes) {
count = uidToArrayIndex.size() + deletedIndexes.size();
- inserteddDocumentsCounter.clear();
- inserteddDocumentsCounter.inc(uidToArrayIndex.size());
- deletedDocumentsCounter.clear();
- deletedDocumentsCounter.inc( uidToArrayIndex.size());
+ currentDocumentsCounter.clear();
+ currentDocumentsCounter.inc(uidToArrayIndex.size());
+ reclaimedDocumentsCounter.clear();
+ reclaimedDocumentsCounter.inc( deletedIndexes.size());
logger.info("Flush compositeActivityValues. Documents = " + uidToArrayIndex.size() + ", Deletes = " + deletedIndexes.size());
}
executor.submit(new Runnable() {
@@ -305,8 +311,8 @@ public static CompositeActivityValues readFromFile(String indexDirPath, List<Str
Metadata metadata = new Metadata(indexDirPath);
metadata.init();
CompositeActivityValues ret = persistentColumnManager.getActivityDataFromFile(metadata);
- ret.deletedDocumentsCounter.inc(ret.deletedIndexes.size());
- ret.inserteddDocumentsCounter.inc(ret.uidToArrayIndex.size());
+ ret.reclaimedDocumentsCounter.inc(ret.deletedIndexes.size());
+ ret.currentDocumentsCounter.inc(ret.uidToArrayIndex.size());
logger.info("Init compositeActivityValues. Documents = " + ret.uidToArrayIndex.size() + ", Deletes = " +ret.deletedIndexes.size());
ret.metadata = metadata;
ret.versionComparator = versionComparator;
@@ -109,6 +109,13 @@ public FacetCountCollectorSource getFacetCountCollectorSource(BrowseSelection se
final int[] indexes = (int[]) ((BoboIndexReader)reader).getFacetData(_name);
return indexes[id] != -1 ? new Object[] {activityIntValues.getValue(indexes[id])} : EMPTY_OBJ_ARR;
}
+
+ public int getActivityValue(int[] facetData, int id) {
+ if (id < 0 || id >= facetData.length) {
+ return Integer.MIN_VALUE;
+ }
+ return facetData[id] != -1 ?activityIntValues.fieldValues[facetData[id]] : Integer.MIN_VALUE;
+ }
@Override
public String[] getFieldValues(BoboIndexReader reader, int id) {
final int[] indexes = (int[]) ((BoboIndexReader)reader).getFacetData(_name);
@@ -21,7 +21,7 @@
public boolean acceptEventsForAllPartitions();
public Set<String> getFieldNames();
public Set<String> getFacetNames();
- public List<FacetHandler> createFacetHandlers();
+ public List<FacetHandler<?>> createFacetHandlers();
public void onDelete(IndexReader indexReader, long... uids);
public void close();
}
@@ -2,6 +2,7 @@
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collection;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
@@ -183,8 +184,8 @@ public void setSenseiCore(SenseiCore senseiCore) {
return ret;
}
- public List<FacetHandler> createFacetHandlers() {
- List<FacetHandler> ret = new ArrayList<FacetHandler>();
+ public List<FacetHandler<?>> createFacetHandlers() {
+ List<FacetHandler<?>> ret = new ArrayList<FacetHandler<?>>();
for (PluggableSearchEngine pluggableSearchEngine : pluggableEngines) {
ret.addAll(pluggableSearchEngine.createFacetHandlers());
}

0 comments on commit 96b94cd

Please sign in to comment.