コード例 #1
0
 /// <summary>
 /// OBS this implementation can only provide values for properties of type <seealso cref="string"/>.
 /// Other property types will still be counted as distinct, but {@code client} won't receive <seealso cref="Value"/>
 /// instances for those. </summary>
 /// <param name="client"> <seealso cref="IndexProgressor.NodeValueClient"/> to get initialized with this progression. </param>
 /// <param name="propertyAccessor"> <seealso cref="NodePropertyAccessor"/> for reading property values. </param>
 /// <param name="needsValues"> whether or not to load string values. </param>
 public override void DistinctValues(Org.Neo4j.Storageengine.Api.schema.IndexProgressor_NodeValueClient client, NodePropertyAccessor propertyAccessor, bool needsValues)
 {
     try
     {
         IndexQuery[]            noQueries       = new IndexQuery[0];
         BridgingIndexProgressor multiProgressor = new BridgingIndexProgressor(client, _descriptor.schema().PropertyIds);
         Fields fields = MultiFields.getFields(IndexSearcher.IndexReader);
         foreach (ValueEncoding valueEncoding in ValueEncoding.values())
         {
             Terms terms = fields.terms(valueEncoding.key());
             if (terms != null)
             {
                 System.Func <BytesRef, Value> valueMaterializer = valueEncoding == ValueEncoding.String && needsValues ? term => Values.stringValue(term.utf8ToString()) : term => null;
                 TermsEnum termsIterator = terms.GetEnumerator();
                 if (valueEncoding == ValueEncoding.Number)
                 {
                     termsIterator = NumericUtils.filterPrefixCodedLongs(termsIterator);
                 }
                 multiProgressor.Initialize(_descriptor, new LuceneDistinctValuesProgressor(termsIterator, client, valueMaterializer), noQueries, IndexOrder.NONE, needsValues);
             }
         }
         client.Initialize(_descriptor, multiProgressor, noQueries, IndexOrder.NONE, needsValues);
     }
     catch (IOException e)
     {
         throw new UncheckedIOException(e);
     }
 }
コード例 #2
0
ファイル: HighFreqTerms.cs プロジェクト: zfxsss/lucenenet
        /// <summary>
        /// Returns TermStats[] ordered by the specified comparator
        /// </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static TermStats[] getHighFreqTerms(org.apache.lucene.index.IndexReader reader, int numTerms, String field, java.util.Comparator<TermStats> comparator) throws Exception
        public static TermStats[] getHighFreqTerms(IndexReader reader, int numTerms, string field, IComparer <TermStats> comparator)
        {
            TermStatsQueue tiq = null;

            if (field != null)
            {
                Fields fields = MultiFields.getFields(reader);
                if (fields == null)
                {
                    throw new Exception("field " + field + " not found");
                }
                Terms terms = fields.terms(field);
                if (terms != null)
                {
                    TermsEnum termsEnum = terms.iterator(null);
                    tiq = new TermStatsQueue(numTerms, comparator);
                    tiq.fill(field, termsEnum);
                }
            }
            else
            {
                Fields fields = MultiFields.getFields(reader);
                if (fields == null)
                {
                    throw new Exception("no fields found for this index");
                }
                tiq = new TermStatsQueue(numTerms, comparator);
                foreach (string fieldName in fields)
                {
                    Terms terms = fields.terms(fieldName);
                    if (terms != null)
                    {
                        tiq.fill(fieldName, terms.iterator(null));
                    }
                }
            }

            TermStats[] result = new TermStats[tiq.size()];
            // we want highest first so we read the queue and populate the array
            // starting at the end and work backwards
            int count = tiq.size() - 1;

            while (tiq.size() != 0)
            {
                result[count] = tiq.pop();
                count--;
            }
            return(result);
        }