Exemplo n.º 1
0
 private bool isFrequent(Term term)
 {
     try {
         return(dict.reader.docFreq(term) >= minNumDocs);
     } catch (IOException e) {
         throw new java.lang.RuntimeException(e);
     }
 }
Exemplo n.º 2
0
            public bool hasNext()
            {
                if (hasNextCalled)
                {
                    return(actualTerm != null);
                }
                hasNextCalled = true;

                do
                {
                    actualTerm = termEnum.term();
                    actualFreq = termEnum.docFreq();

                    // if there are no words return false
                    if (actualTerm == null)
                    {
                        return(false);
                    }

                    string currentField = actualTerm.field();

                    // if the next word doesn't have the same field return false
                    if (currentField != dict.field) // intern'd comparison
                    {
                        actualTerm = null;
                        return(false);
                    }

                    // got a valid term, does it pass the threshold?
                    if (isFrequent(actualTerm))
                    {
                        return(true);
                    }

                    // term not up to threshold
                    try {
                        termEnum.next();
                    } catch (IOException e) {
                        throw new java.lang.RuntimeException(e);
                    }
                } while (true);
            }
        //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
        //ORIGINAL LINE: public void testLimitTokenCountIndexWriter() throws java.io.IOException
        public virtual void testLimitTokenCountIndexWriter()
        {
            foreach (bool consumeAll in new bool[] {true, false})
            {
              Directory dir = newDirectory();
              int limit = TestUtil.Next(random(), 50, 101000);
              MockAnalyzer mock = new MockAnalyzer(random());

              // if we are consuming all tokens, we can use the checks,
              // otherwise we can't
              mock.EnableChecks = consumeAll;
              Analyzer a = new LimitTokenCountAnalyzer(mock, limit, consumeAll);

              IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, a));

              Document doc = new Document();
              StringBuilder b = new StringBuilder();
              for (int i = 1;i < limit;i++)
              {
            b.Append(" a");
              }
              b.Append(" x");
              b.Append(" z");
              doc.add(newTextField("field", b.ToString(), Field.Store.NO));
              writer.addDocument(doc);
              writer.close();

              IndexReader reader = DirectoryReader.open(dir);
              Term t = new Term("field", "x");
              assertEquals(1, reader.docFreq(t));
              t = new Term("field", "z");
              assertEquals(0, reader.docFreq(t));
              reader.close();
              dir.close();
            }
        }