public override void Run()
 {
     try
     {
         iw.Commit();
         IndexCommit ic = sdp.Snapshot();
         foreach (string name in ic.FileNames)
         {
             //distribute, and backup
             //System.out.println(names);
             assertTrue(SlowFileExists(dir, name));
         }
     }
     catch (Exception e) when(e.IsException())
     {
         throw RuntimeException.Create(e);
     }
 }
 private static Dictionary GetDictionary()
 {
     try
     {
         Type type = typeof(UkrainianMorfologikAnalyzer);
         // LUCENENET NOTE: In Lucene, this was downloaded from Maven as a dependency
         // (see https://search.maven.org/search?q=a:morfologik-ukrainian-search). However, we are embedding the file in .NET.
         // Since it doesn't appear to be updated frequently, this should be okay.
         string dictFile = "ukrainian.dict";
         using var dictStream     = type.FindAndGetManifestResourceStream(dictFile);
         using var metadataStream = type.FindAndGetManifestResourceStream(DictionaryMetadata.GetExpectedMetadataFileName(dictFile));
         return(Dictionary.Read(dictStream, metadataStream));
     }
     catch (Exception e) when(e.IsIOException())
     {
         throw RuntimeException.Create(e);
     }
 }
Exemplo n.º 3
0
        public virtual void Collect(int doc)
        {
            Explanation exp; // LUCENENET: IDE0059: Remove unnecessary value assignment

            doc = doc + @base;
            try
            {
                exp = s.Explain(q, doc);
            }
            catch (Exception e) when(e.IsIOException())
            {
                throw RuntimeException.Create("exception in hitcollector of [[" + d + "]] for #" + doc, e);
            }

            Assert.IsNotNull(exp, "Explanation of [[" + d + "]] for #" + doc + " is null");
            CheckHits.VerifyExplanation(d, doc, scorer.GetScore(), deep, exp);
            Assert.IsTrue(exp.IsMatch, "Explanation of [[" + d + "]] for #" + doc + " does not indicate match: " + exp.ToString());
        }
Exemplo n.º 4
0
        protected virtual SearchResults executeQuery(Query query, int numDocs)
        {
            try
            {
                TopDocs topDocs = indexSearcher.Search(query, numDocs);

                IList <SearchResult> results = new JCG.List <SearchResult>();
                foreach (ScoreDoc scoreDoc in topDocs.ScoreDocs)
                {
                    results.Add(new SearchResult(scoreDoc.Score, indexSearcher.Doc(scoreDoc.Doc)));
                }
                return(new SearchResults(topDocs.TotalHits, results));
            }
            catch (Exception ioe) when(ioe.IsIOException())
            {
                throw RuntimeException.Create("IOException thrown while executing query", ioe);
            }
        }
Exemplo n.º 5
0
                public override object?ObjectVal(int docId)
                {
                    if (!FillBytes(docId))
                    {
                        return(null);
                    }
                    BinaryReader dataInput = new BinaryReader(
                        new MemoryStream(bytesRef.Bytes, bytesRef.Offset, bytesRef.Length));

                    try
                    {
                        return(outerInstance.binaryCodec.ReadShape(dataInput));
                    }
                    catch (Exception e) when(e.IsIOException())
                    {
                        throw RuntimeException.Create(e);
                    }
                }
Exemplo n.º 6
0
            private static CharArraySet LoadDefaultStopSet() // LUCENENET: Avoid static constructors (see https://github.com/apache/lucenenet/pull/224#issuecomment-469284006)
            {
                try
                {
                    return(WordlistLoader.GetSnowballWordSet(
                               IOUtils.GetDecodingReader(typeof(SnowballFilter), DEFAULT_STOPWORD_FILE, Encoding.UTF8),
#pragma warning disable 612, 618
                               LuceneVersion.LUCENE_CURRENT));

#pragma warning restore 612, 618
                }
                catch (Exception ex) when(ex.IsIOException())
                {
                    // default set should always be present as it is part of the
                    // distribution (JAR)
                    throw RuntimeException.Create("Unable to load default stopword set", ex);
                }
            }
Exemplo n.º 7
0
 private static ISet <string> LoadDefaultStopTagSet() // LUCENENET: Avoid static constructors (see https://github.com/apache/lucenenet/pull/224#issuecomment-469284006)
 {
     try
     {
         CharArraySet tagset            = LoadStopwordSet(false, typeof(JapaneseAnalyzer), "stoptags.txt", "#");
         var          DEFAULT_STOP_TAGS = new JCG.HashSet <string>();
         foreach (string element in tagset)
         {
             DEFAULT_STOP_TAGS.Add(element);
         }
         return(DEFAULT_STOP_TAGS);
     }
     catch (Exception ex) when(ex.IsIOException())
     {
         // default set should always be present as it is part of the distribution (JAR)
         throw RuntimeException.Create("Unable to load default stoptag set", ex);
     }
 }
Exemplo n.º 8
0
 public override long LookupTerm(BytesRef key)
 {
     try
     {
         if (te.SeekCeil(key) == SeekStatus.FOUND)
         {
             return(te.Ord);
         }
         else
         {
             return(-te.Ord - 1);
         }
     }
     catch (Exception e) when(e.IsIOException())
     {
         throw RuntimeException.Create(e);
     }
 }
            internal static readonly CharArraySet DEFAULT_STOP_SET = LoadDefaultSet(); // LUCENENET: Avoid static constructors (see https://github.com/apache/lucenenet/pull/224#issuecomment-469284006)

            private static CharArraySet LoadDefaultSet()
            {
                try
                {
                    return(WordlistLoader.GetSnowballWordSet(IOUtils.GetDecodingReader(typeof(UkrainianMorfologikAnalyzer),
                                                                                       DEFAULT_STOPWORD_FILE, Encoding.UTF8),
#pragma warning disable 612, 618
                                                             LuceneVersion.LUCENE_CURRENT));

#pragma warning restore 612, 618
                }
                catch (Exception ex) when(ex.IsIOException())
                {
                    // default set should always be present as it is part of the
                    // distribution (JAR)
                    throw RuntimeException.Create("Unable to load default stopword set", ex);
                }
            }
Exemplo n.º 10
0
            public override void Run()
            {
                try
                {
                    LineFileDocs docs    = new LineFileDocs(Random, DefaultCodecSupportsDocValues);
                    int          numDocs = 0;
                    while (J2N.Time.NanoTime() < outerInstance.endTimeNanos)
                    {
                        int       what = Random.Next(3);
                        NodeState node = outerInstance.m_nodes[Random.Next(outerInstance.m_nodes.Length)];
                        if (numDocs == 0 || what == 0)
                        {
                            node.Writer.AddDocument(docs.NextDoc());
                            numDocs++;
                        }
                        else if (what == 1)
                        {
                            node.Writer.UpdateDocument(new Term("docid", "" + Random.Next(numDocs)), docs.NextDoc());
                            numDocs++;
                        }
                        else
                        {
                            node.Writer.DeleteDocuments(new Term("docid", "" + Random.Next(numDocs)));
                        }
                        // TODO: doc blocks too

                        if (Random.Next(17) == 12)
                        {
                            node.Writer.Commit();
                        }

                        if (Random.Next(17) == 12)
                        {
                            outerInstance.m_nodes[Random.Next(outerInstance.m_nodes.Length)].Reopen();
                        }
                    }
                }
                catch (Exception t) when(t.IsThrowable())
                {
                    Console.WriteLine("FAILED:");
                    Console.Out.WriteLine(t.StackTrace);
                    throw RuntimeException.Create(t);
                }
            }
Exemplo n.º 11
0
 /// <summary>
 /// NOTE: This was intVal() in Lucene
 /// </summary>
 public override int Int32Val(int doc)
 {
     try
     {
         terms.Get(doc, @ref);
         if (termsEnum.SeekExact(@ref))
         {
             return(termsEnum.DocFreq);
         }
         else
         {
             return(0);
         }
     }
     catch (Exception e) when(e.IsIOException())
     {
         throw RuntimeException.Create("caught exception in function " + outerInstance.GetDescription() + " : doc=" + doc, e);
     }
 }
Exemplo n.º 12
0
        public override TokenStream Create(TokenStream input)
        {
            SnowballProgram program;

            try
            {
                program = (SnowballProgram)Activator.CreateInstance(stemClass);
            }
            catch (Exception e) when(e.IsException())
            {
                throw RuntimeException.Create("Error instantiating stemmer for language " + language + "from class " + stemClass, e);
            }

            if (protectedWords != null)
            {
                input = new SetKeywordMarkerFilter(input, protectedWords);
            }
            return(new SnowballFilter(input, program));
        }
Exemplo n.º 13
0
        /// <summary>
        /// Read custom rules from a file, and create a <see cref="RuleBasedCollator"/>.
        /// The file cannot support comments, as # might be in the rules!
        /// </summary>
        private Collator CreateFromRules(string fileName, IResourceLoader loader)
        {
            Stream input = null;

            try
            {
                input = loader.OpenResource(fileName);
                string rules = ToUTF8String(input);
                return(new RuleBasedCollator(rules));
            }
            catch (Exception e) when(e.IsException())
            {
                // io error or invalid rules
                throw RuntimeException.Create(e);
            }
            finally
            {
                IOUtils.DisposeWhileHandlingException(input);
            }
        }
Exemplo n.º 14
0
 public override void Run()
 {
     try
     {
         int n = task.RunAndMaybeStats(outerInstance.letChildReport);
         if (outerInstance.anyExhaustibleTasks)
         {
             outerInstance.UpdateExhausted(task);
         }
         count += n;
     }
     catch (NoMoreDataException)
     {
         outerInstance.exhausted = true;
     }
     catch (Exception e) when(e.IsException())
     {
         throw RuntimeException.Create(e);
     }
 }
            public override void Get(long id, BytesRef result)
            {
                long address = bytes.offset + id * bytes.maxLength;

                try
                {
                    data.Seek(address);
                    // NOTE: we could have one buffer, but various consumers (e.g. FieldComparerSource)
                    // assume "they" own the bytes after calling this!
                    var buffer = new byte[bytes.maxLength];
                    data.ReadBytes(buffer, 0, buffer.Length);
                    result.Bytes  = buffer;
                    result.Offset = 0;
                    result.Length = buffer.Length;
                }
                catch (Exception e) when(e.IsIOException())
                {
                    throw RuntimeException.Create(e);
                }
            }
Exemplo n.º 16
0
        public override Field[] CreateIndexableFields(IShape shape)
        {
            int          bufSize    = Math.Max(128, (int)(this.indexLastBufSize * 1.5)); //50% headroom over last
            MemoryStream byteStream = new MemoryStream(bufSize);
            BytesRef     bytesRef   = new BytesRef();                                    //receiver of byteStream's bytes

            try
            {
                m_ctx.BinaryCodec.WriteShape(new BinaryWriter(byteStream), shape);

                //this is a hack to avoid redundant byte array copying by byteStream.toByteArray()
                byteStream.WriteTo(new OutputStreamAnonymousClass(bytesRef));
            }
            catch (Exception e) when(e.IsIOException())
            {
                throw RuntimeException.Create(e);
            }
            this.indexLastBufSize = bytesRef.Length;//cache heuristic
            return(new Field[] { new BinaryDocValuesField(FieldName, bytesRef) });
        }
Exemplo n.º 17
0
 private void OpenFile()
 {
     try
     {
         if (reader != null)
         {
             reader.Dispose();
         }
         Stream @is = StreamUtils.GetInputStream(file);
         reader = new StreamReader(@is, m_encoding);
         if (skipHeaderLine)
         {
             reader.ReadLine(); // skip one line - the header line - already handled that info
         }
     }
     catch (Exception e) when(e.IsIOException())
     {
         throw RuntimeException.Create(e);
     }
 }
Exemplo n.º 18
0
 public virtual int CompareTo(OffsetsEnum other)
 {
     try
     {
         int off      = dp.StartOffset;
         int otherOff = other.dp.StartOffset;
         if (off == otherOff)
         {
             return(id - other.id);
         }
         else
         {
             return(off.CompareTo(otherOff));
         }
     }
     catch (Exception e) when(e.IsIOException())
     {
         throw RuntimeException.Create(e);
     }
 }
Exemplo n.º 19
0
        /**
         * Do the measurements.
         */
        private BenchmarkResult Measure(Func <int> callable)
        {
            double NANOS_PER_MS = 1000000;

            try
            {
                JCG.List <double> times = new JCG.List <double>();
                for (int i = 0; i < warmup + rounds; i++)
                {
                    long start = J2N.Time.NanoTime();
                    guard = Convert.ToInt32(callable());
                    times.Add((J2N.Time.NanoTime() - start) / NANOS_PER_MS);
                }
                return(new BenchmarkResult(times, warmup, rounds));
            }
            catch (Exception e) when(e.IsException())
            {
                e.printStackTrace();
                throw RuntimeException.Create(e);
            }
        }
Exemplo n.º 20
0
        public Type FindType(string cname)
        {
            try
            {
                // LUCENENET TODO: Apparently the second parameter of FindClass was used
                // to determine what assembly a class is in (which makes this function pretty much
                // pointless). Need to evaluate whether it makes sense to pass a "relative" type here
                // to identify the correct assembly, since we can just pass a string to do the same.
                if (cname.Contains(","))
                {
                    // Assume we have an assembly qualified name
                    return(Type.GetType(cname));
                }

                return(this.clazz.Assembly.GetType(cname, true));
            }
            catch (Exception e) when(e.IsException())
            {
                throw RuntimeException.Create("Cannot load class: " + cname, e);
            }
        }
Exemplo n.º 21
0
 public override int DoLogic()
 {
     try
     {
         CultureInfo locale = RunData.Locale;
         if (locale == null)
         {
             throw RuntimeException.Create(
                       "Locale must be set with the NewLocale task!");
         }
         Analyzer analyzer = CreateAnalyzer(locale, impl);
         RunData.Analyzer = analyzer;
         Console.WriteLine("Changed Analyzer to: "
                           + analyzer.GetType().Name + "(" + locale + ")");
     }
     catch (Exception e) when(e.IsException())
     {
         throw RuntimeException.Create("Error creating Analyzer: impl=" + impl, e);
     }
     return(1);
 }
Exemplo n.º 22
0
        public override double DoubleVal(int document)
        {
            try
            {
                if (Debugging.AssertsEnabled)
                {
                    Debugging.Assert(document == scorer.DocID);
                }

#if NETSTANDARD2_1_OR_GREATER || NET5_0_OR_GREATER
                return(scorer.GetScore());
#else
                // LUCENENET specific: The intermediate cast to decimal is required here to prevent us from losing precision on x86 .NET Framework with optimizations enabled
                return((double)(decimal)scorer.GetScore());
#endif
            }
            catch (Exception exception) when(exception.IsIOException())
            {
                throw RuntimeException.Create(exception);
            }
        }
Exemplo n.º 23
0
            public override void Run()
            {
                try
                {
                    long count = 0;
                    long miss  = 0;
                    long hit   = 0;
                    int  limit = objs.Length;

                    while (true)
                    {
                        CloneableObject obj = objs[(int)((count / 2) % limit)];
                        object          v   = c.Get(obj);
                        if (v == null)
                        {
                            c.Put(new CloneableObject(obj), obj);
                            miss++;
                        }
                        else
                        {
                            Assert.True(obj == v);
                            hit++;
                        }
                        if ((++count % 10000) == 0)
                        {
                            if (DateTime.Now.CompareTo(endTime) > 0)
                            {
                                break;
                            }
                        }
                    }

                    outerInstance.AddResults(miss, hit);
                }
                catch (Exception t) when(t.IsThrowable())
                {
                    failed = true;
                    throw RuntimeException.Create(t);
                }
            }
Exemplo n.º 24
0
            protected override void DoMerge(MergePolicy.OneMerge merge)
            {
                try
                {
                    // Stall all incoming merges until we see
                    // maxMergeCount:
                    int count = runningMergeCount.IncrementAndGet();
                    try
                    {
                        Assert.IsTrue(count <= maxMergeCount, "count=" + count + " vs maxMergeCount=" + maxMergeCount);
                        enoughMergesWaiting.Signal();

                        // Stall this merge until we see exactly
                        // maxMergeCount merges waiting
                        while (true)
                        {
                            // wait for 10 milliseconds
                            if (enoughMergesWaiting.Wait(new TimeSpan(0, 0, 0, 0, 10)) || failed)
                            {
                                break;
                            }
                        }
                        // Then sleep a bit to give a chance for the bug
                        // (too many pending merges) to appear:
                        Thread.Sleep(20);
                        base.DoMerge(merge);
                    }
                    finally
                    {
                        runningMergeCount.DecrementAndGet();
                    }
                }
                catch (Exception t) when(t.IsThrowable())
                {
                    failed.Value = (true);
                    m_writer.MergeFinish(merge);
                    // LUCENENET NOTE: ThreadJob takes care of propagating the exception to the calling thread
                    throw RuntimeException.Create(t);
                }
            }
Exemplo n.º 25
0
            public override void LookupOrd(long ord, BytesRef result)
            {
                try
                {
                    if (ord < 0 || ord >= _field.NumValues)
                    {
                        throw new IndexOutOfRangeException("ord must be 0 .. " + (_field.NumValues - 1) + "; got " + ord);
                    }

                    _input.Seek(_field.DataStartFilePointer + ord * (9 + _field.Pattern.Length + _field.MaxLength));
                    SimpleTextUtil.ReadLine(_input, _scratch);
                    // LUCENENET specific - use wrapper BytesRefFormatter struct to defer building the string unless string.Format() is called
                    if (Debugging.AssertsEnabled)
                    {
                        Debugging.Assert(StringHelper.StartsWith(_scratch, SimpleTextDocValuesWriter.LENGTH), "got {0} in={1}", new BytesRefFormatter(_scratch, BytesRefFormat.UTF8), _input);
                    }
                    int len;
                    try
                    {
                        // LUCNENENET: .NET doesn't have a way to specify a pattern with integer, but all of the standard ones are built in.
                        len = int.Parse(Encoding.UTF8.GetString(_scratch.Bytes, _scratch.Offset + SimpleTextDocValuesWriter.LENGTH.Length,
                                                                _scratch.Length - SimpleTextDocValuesWriter.LENGTH.Length), NumberStyles.Integer, CultureInfo.InvariantCulture);
                    }
                    catch (Exception pe) when(pe.IsParseException())
                    {
                        var e = new CorruptIndexException("failed to parse int length (resource=" + _input + ")", pe);

                        throw e;
                    }

                    result.Bytes  = new byte[len];
                    result.Offset = 0;
                    result.Length = len;
                    _input.ReadBytes(result.Bytes, 0, len);
                }
                catch (Exception ioe) when(ioe.IsIOException())
                {
                    throw RuntimeException.Create(ioe);
                }
            }
Exemplo n.º 26
0
        public override bool Exists(int doc)
        {
            try
            {
                if (doc < lastDocRequested)
                {
                    if (noMatches)
                    {
                        return(false);
                    }
                    scorer    = weight.GetScorer(readerContext, acceptDocs);
                    scorerDoc = -1;
                    if (scorer == null)
                    {
                        noMatches = true;
                        return(false);
                    }
                }
                lastDocRequested = doc;

                if (scorerDoc < doc)
                {
                    scorerDoc = scorer.Advance(doc);
                }

                if (scorerDoc > doc)
                {
                    // query doesn't match this document... either because we hit the
                    // end, or because the next doc is after this doc.
                    return(false);
                }

                // a match!
                return(true);
            }
            catch (Exception e) when(e.IsIOException())
            {
                throw RuntimeException.Create("caught exception in QueryDocVals(" + q + ") doc=" + doc, e);
            }
        }
Exemplo n.º 27
0
            public override void Run()
            {
                try
                {
                    long count = 0;
                    long miss  = 0;
                    long hit   = 0;
                    int  limit = objs.Length;

                    while (true)
                    {
                        CloneableObject obj = objs[(int)((count / 2) % limit)];
                        object          v   = c.Get(obj);
                        if (v == null)
                        {
                            c.Put(new CloneableObject(obj), obj);
                            miss++;
                        }
                        else
                        {
                            Assert.True(obj == v);
                            hit++;
                        }
                        if ((++count % 10000) == 0)
                        {
                            if (J2N.Time.NanoTime() / J2N.Time.MillisecondsPerNanosecond > endTime) // LUCENENET: Use NanoTime() rather than CurrentTimeMilliseconds() for more accurate/reliable results
                            {
                                break;
                            }
                        }
                    }

                    outerInstance.AddResults(miss, hit);
                }
                catch (Exception t) when(t.IsThrowable())
                {
                    failed = true;
                    throw RuntimeException.Create(t);
                }
            }
Exemplo n.º 28
0
        /** Reads the stream, consuming a format that is a tab-separated values of 3 columns:
         * an "id", a "name" and the "shape".  Empty lines and lines starting with a '#' are skipped.
         * The stream is closed.
         */
        public static IEnumerator <SpatialTestData> GetTestData(Stream @in, SpatialContext ctx)
        {
            List <SpatialTestData> results  = new List <SpatialTestData>();
            TextReader             bufInput = new StreamReader(@in, Encoding.UTF8);

            try
            {
                String line;
                while ((line = bufInput.ReadLine()) != null)
                {
                    if (line.Length == 0 || line[0] == '#')
                    {
                        continue;
                    }

                    SpatialTestData data = new SpatialTestData();
                    String[]        vals = line.Split('\t').TrimEnd();
                    if (vals.Length != 3)
                    {
                        throw RuntimeException.Create("bad format; expecting 3 tab-separated values for line: " + line);
                    }
                    data.id   = vals[0];
                    data.name = vals[1];
                    try
                    {
                        data.shape = ctx.ReadShapeFromWkt(vals[2]);
                    }
                    catch (Spatial4n.Core.Exceptions.ParseException e) // LUCENENET: Spatial4n has its own ParseException that is different than the one in Support
                    {
                        throw RuntimeException.Create(e);
                    }
                    results.Add(data);
                }
            }
            finally
            {
                bufInput.Dispose();
            }
            return(results.GetEnumerator());
        }
Exemplo n.º 29
0
            public override void DoWork()
            {
                IndexReader r1 = null, r2 = null;

                UninterruptableMonitor.Enter(@lock);
                try
                {
                    try
                    {
                        r1 = DirectoryReader.Open(dir1);
                        r2 = DirectoryReader.Open(dir2);
                    }
                    catch (Exception e) when(e.IsIOException())
                    {
                        if (!e.Message.Contains("on purpose"))
                        {
                            throw; // LUCENENET: CA2200: Rethrow to preserve stack details (https://docs.microsoft.com/en-us/visualstudio/code-quality/ca2200-rethrow-to-preserve-stack-details)
                        }
                        if (r1 != null)
                        {
                            r1.Dispose();
                        }
                        if (r2 != null)
                        {
                            r2.Dispose();
                        }
                        return;
                    }
                }
                finally
                {
                    UninterruptableMonitor.Exit(@lock);
                }
                if (r1.NumDocs != r2.NumDocs)
                {
                    throw RuntimeException.Create("doc counts differ: r1=" + r1.NumDocs + " r2=" + r2.NumDocs);
                }
                r1.Dispose();
                r2.Dispose();
            }
Exemplo n.º 30
0
        private IEnumerable <BytesRef> GetBytesIterator(int maxDocParam)
        {
            // Use yield return instead of ucsom IEnumerable
            var value = new BytesRef();

            AppendingDeltaPackedInt64Buffer.Iterator lengthsIterator = lengths.GetIterator();
            int       size          = (int)lengths.Count;
            DataInput bytesIterator = bytes.GetDataInput();
            int       maxDoc        = maxDocParam;
            int       upto          = 0;

            while (upto < maxDoc)
            {
                BytesRef v = null;
                if (upto < size)
                {
                    int length = (int)lengthsIterator.Next();
                    value.Grow(length);
                    value.Length = length;
                    try
                    {
                        bytesIterator.ReadBytes(value.Bytes, value.Offset, value.Length);
                    }
                    catch (Exception ioe) when(ioe.IsIOException())
                    {
                        // Should never happen!
                        throw RuntimeException.Create(ioe);
                    }

                    if (docsWithField.Get(upto))
                    {
                        v = value;
                    }
                }

                upto++;
                yield return(v);
            }
        }