Example #1
0
        public override void Process <T1>(IndexEntryUpdate <T1> update)
        {
            long nodeId = update.EntityId;

            try
            {
                switch (update.UpdateMode())
                {
                case ADDED:
                    Added(update);
                    _writer.updateDocument(LuceneDocumentStructure.newTermForChangeOrRemove(nodeId), LuceneDocumentStructure.documentRepresentingProperties(nodeId, update.Values()));
                    break;

                case CHANGED:
                    Changed(update);
                    _writer.updateDocument(LuceneDocumentStructure.newTermForChangeOrRemove(nodeId), LuceneDocumentStructure.documentRepresentingProperties(nodeId, update.Values()));
                    break;

                case REMOVED:
                    Removed(update);
                    _writer.deleteDocuments(LuceneDocumentStructure.newTermForChangeOrRemove(nodeId));
                    break;

                default:
                    throw new System.InvalidOperationException("Unknown update mode " + Arrays.ToString(update.Values()));
                }
            }
            catch (IOException e)
            {
                throw new UncheckedIOException(e);
            }
        }
Example #2
0
        public override long CountIndexedNodes(long nodeId, int[] propertyKeyIds, params Value[] propertyValues)
        {
            Query nodeIdQuery = new TermQuery(LuceneDocumentStructure.newTermForChangeOrRemove(nodeId));
            Query valueQuery  = LuceneDocumentStructure.newSeekQuery(propertyValues);

            BooleanQuery.Builder nodeIdAndValueQuery = (new BooleanQuery.Builder()).setDisableCoord(true);
            nodeIdAndValueQuery.add(nodeIdQuery, BooleanClause.Occur.MUST);
            nodeIdAndValueQuery.add(valueQuery, BooleanClause.Occur.MUST);
            try
            {
                TotalHitCountCollector collector = new TotalHitCountCollector();
                IndexSearcher.search(nodeIdAndValueQuery.build(), collector);
                // A <label,propertyKeyId,nodeId> tuple should only match at most a single propertyValue
                return(collector.TotalHits);
            }
            catch (IOException e)
            {
                throw new Exception(e);
            }
        }