/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ using System; using NUnit.Framework; using WhitespaceAnalyzer = Lucene.Net.Analysis.WhitespaceAnalyzer; using IndexSearcher = Lucene.Net.Search.IndexSearcher; using TermQuery = Lucene.Net.Search.TermQuery; using Hits = Lucene.Net.Search.Hits; using Directory = Lucene.Net.Store.Directory; using IndexInput = Lucene.Net.Store.IndexInput; using IndexOutput = Lucene.Net.Store.IndexOutput; using RAMDirectory = Lucene.Net.Store.RAMDirectory; using Document = Lucene.Net.Documents.Document; using Field = Lucene.Net.Documents.Field; namespace Lucene.Net.Index { /* Verify we can read the pre-2.1 file format, do searches against it, and add documents to it.*/ [TestFixture] public class TestIndexFileDeleter { [Test] public virtual void TestDeleteLeftoverFiles() { Directory dir = new RAMDirectory(); IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true); int i; for (i = 0; i < 35; i++) { AddDoc(writer, i); } writer.SetUseCompoundFile(false); for (; i < 45; i++) { AddDoc(writer, i); } writer.Close(); // Delete one doc so we get a .del file: IndexReader reader = IndexReader.Open(dir); Term searchTerm = new Term("id", "7"); int delCount = reader.DeleteDocuments(searchTerm); Assert.AreEqual(1, delCount, "didn't delete the right number of documents"); // Set one norm so we get a .s0 file: reader.SetNorm(21, "content", (float) 1.5); reader.Close(); // Now, artificially create an extra .del file & extra // .s0 file: System.String[] files = dir.List(); /* for(int i=0;i 0) { s += "\n "; } s += l[i]; } return s; } public virtual void CopyFile(Directory dir, System.String src, System.String dest) { IndexInput in_Renamed = dir.OpenInput(src); IndexOutput out_Renamed = dir.CreateOutput(dest); byte[] b = new byte[1024]; long remainder = in_Renamed.Length(); while (remainder > 0) { int len = (int) System.Math.Min(b.Length, remainder); in_Renamed.ReadBytes(b, 0, len); out_Renamed.WriteBytes(b, len); remainder -= len; } } private void AddDoc(IndexWriter writer, int id) { Lucene.Net.Documents.Document doc = new Lucene.Net.Documents.Document(); doc.Add(new Field("content", "aaa", Field.Store.NO, Field.Index.TOKENIZED)); doc.Add(new Field("id", System.Convert.ToString(id), Field.Store.YES, Field.Index.UN_TOKENIZED)); writer.AddDocument(doc); } public static bool ArrayEquals(System.Array array1, System.Array array2) { bool result = false; if ((array1 == null) && (array2 == null)) result = true; else if ((array1 != null) && (array2 != null)) { if (array1.Length == array2.Length) { int length = array1.Length; result = true; for (int index = 0; index < length; index++) { if (!(array1.GetValue(index).Equals(array2.GetValue(index)))) { result = false; break; } } } } return result; } } }