private static Document NewDocument() { Document doc = new Document(); doc.add(new StringField("test", System.Guid.randomUUID().ToString(), Field.Store.YES)); return(doc); }
/// <summary> /// Set up a new index in RAM with three test phrases and the supplied Analyzer. /// </summary> /// <exception cref="Exception"> if an error occurs with index writer or searcher </exception> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: @Override public void setUp() throws Exception public override void setUp() { base.setUp(); analyzer = new ShingleAnalyzerWrapper(new MockAnalyzer(random(), MockTokenizer.WHITESPACE, false), 2); directory = newDirectory(); IndexWriter writer = new IndexWriter(directory, new IndexWriterConfig(TEST_VERSION_CURRENT, analyzer)); Document doc; doc = new Document(); doc.add(new TextField("content", "please divide this sentence into shingles", Field.Store.YES)); writer.addDocument(doc); doc = new Document(); doc.add(new TextField("content", "just another test sentence", Field.Store.YES)); writer.addDocument(doc); doc = new Document(); doc.add(new TextField("content", "a sentence which contains no test", Field.Store.YES)); writer.addDocument(doc); writer.close(); reader = DirectoryReader.open(directory); searcher = newSearcher(reader); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void stringWithMaximumLengthShouldBeAllowed() internal virtual void StringWithMaximumLengthShouldBeAllowed() { string longestString = RandomStringUtils.randomAscii(IndexWriter.MAX_TERM_LENGTH); Document document = documentRepresentingProperties(( long )123, longestString); assertEquals(longestString, document.getField(string.key(0)).stringValue()); }
/// <summary> /// Set up a new index in RAM with three test phrases and the supplied Analyzer. /// </summary> /// <exception cref="Exception"> if an error occurs with index writer or searcher </exception> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: @Override public void setUp() throws Exception public override void setUp() { base.setUp(); analyzer = new ShingleAnalyzerWrapper(new MockAnalyzer(random(), MockTokenizer.WHITESPACE, false), 2); directory = newDirectory(); IndexWriter writer = new IndexWriter(directory, new IndexWriterConfig(TEST_VERSION_CURRENT, analyzer)); Document doc; doc = new Document(); doc.add(new TextField("content", "please divide this sentence into shingles", Field.Store.YES)); writer.addDocument(doc); doc = new Document(); doc.add(new TextField("content", "just another test sentence", Field.Store.YES)); writer.addDocument(doc); doc = new Document(); doc.add(new TextField("content", "a sentence which contains no test", Field.Store.YES)); writer.addDocument(doc); writer.close(); reader = DirectoryReader.open(directory); searcher = newSearcher(reader); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: protected void doCollect(int doc) throws java.io.IOException, org.neo4j.internal.kernel.api.exceptions.KernelException, org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException protected internal virtual void DoCollect(int doc) { Document document = Reader.document(doc); long nodeId = LuceneDocumentStructure.getNodeId(document); Value value = Accessor.getNodePropertyValue(nodeId, _propertyKeyId); DuplicateCheckStrategy.checkForDuplicate(value, nodeId); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void shouldBuildDocumentRepresentingStringProperty() internal virtual void ShouldBuildDocumentRepresentingStringProperty() { // given Document document = documentRepresentingProperties(( long )123, "hello"); // then assertEquals("123", document.get(NODE_ID_KEY)); assertEquals("hello", document.get(string.key(0))); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void shouldBuildDocumentRepresentingNumberProperty() internal virtual void ShouldBuildDocumentRepresentingNumberProperty() { // given Document document = documentRepresentingProperties(( long )123, 12); // then assertEquals("123", document.get(NODE_ID_KEY)); assertEquals(12.0, document.getField(Number.key(0)).numericValue().doubleValue(), 0.001); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void shouldBuildDocumentRepresentingBoolProperty() internal virtual void ShouldBuildDocumentRepresentingBoolProperty() { // given Document document = documentRepresentingProperties(( long )123, true); // then assertEquals("123", document.get(NODE_ID_KEY)); assertEquals("true", document.get(Bool.key(0))); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void shouldBuildDocumentRepresentingMultipleStringProperties() internal virtual void ShouldBuildDocumentRepresentingMultipleStringProperties() { // given string[] values = new string[] { "hello", "world" }; Document document = documentRepresentingProperties(123, values); // then assertEquals("123", document.get(NODE_ID_KEY)); assertThat(document.get(string.key(0)), equalTo(values[0])); assertThat(document.get(string.key(1)), equalTo(values[1])); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void shouldBuildDocumentRepresentingMultiplePropertiesOfDifferentTypes() internal virtual void ShouldBuildDocumentRepresentingMultiplePropertiesOfDifferentTypes() { // given object[] values = new object[] { "hello", 789 }; Document document = documentRepresentingProperties(123, values); // then assertEquals("123", document.get(NODE_ID_KEY)); assertThat(document.get(string.key(0)), equalTo("hello")); assertThat(document.get(Number.key(1)), equalTo("789.0")); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void shouldBuildDocumentRepresentingArrayProperty() internal virtual void ShouldBuildDocumentRepresentingArrayProperty() { // given Document document = documentRepresentingProperties((long)123, new object[] { new int?[] { 1, 2, 3 } }); // then assertEquals("123", document.get(NODE_ID_KEY)); assertEquals("D1.0|2.0|3.0|", document.get(Array.key(0))); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: protected void doCollect(int doc) throws java.io.IOException, org.neo4j.internal.kernel.api.exceptions.KernelException, org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException protected internal override void DoCollect(int doc) { Document document = Reader.document(doc); long nodeId = LuceneDocumentStructure.getNodeId(document); Value[] values = new Value[_propertyKeyIds.Length]; for (int i = 0; i < values.Length; i++) { values[i] = Accessor.getNodePropertyValue(nodeId, _propertyKeyIds[i]); } DuplicateCheckStrategy.checkForDuplicate(values, nodeId); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: @Override public void setUp() throws Exception public override void setUp() { base.setUp(); directory = newDirectory(); IndexWriter writer = new IndexWriter(directory, new IndexWriterConfig(TEST_VERSION_CURRENT, new SimpleAnalyzer(TEST_VERSION_CURRENT))); Document doc = new Document(); doc.add(new StringField("partnum", "Q36", Field.Store.YES)); doc.add(new TextField("description", "Illidium Space Modulator", Field.Store.YES)); writer.addDocument(doc); writer.close(); reader = DirectoryReader.open(directory); searcher = newSearcher(reader); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: @Override public void setUp() throws Exception public override void setUp() { base.setUp(); directory = newDirectory(); IndexWriter writer = new IndexWriter(directory, new IndexWriterConfig(TEST_VERSION_CURRENT, new SimpleAnalyzer(TEST_VERSION_CURRENT))); Document doc = new Document(); doc.add(new StringField("partnum", "Q36", Field.Store.YES)); doc.add(new TextField("description", "Illidium Space Modulator", Field.Store.YES)); writer.addDocument(doc); writer.close(); reader = DirectoryReader.open(directory); searcher = newSearcher(reader); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: @Override public void setUp() throws Exception public override void setUp() { base.setUp(); dir = new RAMDirectory(); appAnalyzer = new MockAnalyzer(random(), MockTokenizer.WHITESPACE, false); IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, appAnalyzer)); int numDocs = 200; for (int i = 0; i < numDocs; i++) { Document doc = new Document(); string variedFieldValue = variedFieldValues[i % variedFieldValues.Length]; string repetitiveFieldValue = repetitiveFieldValues[i % repetitiveFieldValues.Length]; doc.add(new TextField("variedField", variedFieldValue, Field.Store.YES)); doc.add(new TextField("repetitiveField", repetitiveFieldValue, Field.Store.YES)); writer.addDocument(doc); } writer.close(); reader = DirectoryReader.open(dir); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void testIndexWriter_LUCENE4656() throws java.io.IOException public virtual void testIndexWriter_LUCENE4656() { Directory directory = newDirectory(); IndexWriter writer = new IndexWriter(directory, newIndexWriterConfig(TEST_VERSION_CURRENT, null)); TokenStream ts = new EmptyTokenStream(); assertFalse(ts.hasAttribute(typeof(TermToBytesRefAttribute))); Document doc = new Document(); doc.add(new StringField("id", "0", Field.Store.YES)); doc.add(new TextField("description", ts)); // this should not fail because we have no TermToBytesRefAttribute writer.addDocument(doc); assertEquals(1, writer.numDocs()); writer.close(); directory.close(); }
/* * public void testPerFieldAnalyzer() throws Exception { * PerFieldAnalyzerWrapper analyzer = new PerFieldAnalyzerWrapper(new SimpleAnalyzer(TEST_VERSION_CURRENT)); * analyzer.addAnalyzer("partnum", new KeywordAnalyzer()); * * QueryParser queryParser = new QueryParser(TEST_VERSION_CURRENT, "description", analyzer); * Query query = queryParser.parse("partnum:Q36 AND SPACE"); * * ScoreDoc[] hits = searcher.search(query, null, 1000).scoreDocs; * assertEquals("Q36 kept as-is", * "+partnum:Q36 +space", query.toString("description")); * assertEquals("doc found!", 1, hits.length); * } */ //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void testMutipleDocument() throws Exception public virtual void testMutipleDocument() { RAMDirectory dir = new RAMDirectory(); IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new KeywordAnalyzer())); Document doc = new Document(); doc.add(new TextField("partnum", "Q36", Field.Store.YES)); writer.addDocument(doc); doc = new Document(); doc.add(new TextField("partnum", "Q37", Field.Store.YES)); writer.addDocument(doc); writer.close(); IndexReader reader = DirectoryReader.open(dir); DocsEnum td = TestUtil.docs(random(), reader, "partnum", new BytesRef("Q36"), MultiFields.getLiveDocs(reader), null, 0); assertTrue(td.nextDoc() != DocIdSetIterator.NO_MORE_DOCS); td = TestUtil.docs(random(), reader, "partnum", new BytesRef("Q37"), MultiFields.getLiveDocs(reader), null, 0); assertTrue(td.nextDoc() != DocIdSetIterator.NO_MORE_DOCS); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: @Override public void setUp() throws Exception public override void setUp() { base.setUp(); dir = new RAMDirectory(); appAnalyzer = new MockAnalyzer(random(), MockTokenizer.WHITESPACE, false); IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, appAnalyzer)); int numDocs = 200; for (int i = 0; i < numDocs; i++) { Document doc = new Document(); string variedFieldValue = variedFieldValues[i % variedFieldValues.Length]; string repetitiveFieldValue = repetitiveFieldValues[i % repetitiveFieldValues.Length]; doc.add(new TextField("variedField", variedFieldValue, Field.Store.YES)); doc.add(new TextField("repetitiveField", repetitiveFieldValue, Field.Store.YES)); writer.addDocument(doc); } writer.close(); reader = DirectoryReader.open(dir); }
/// <summary> /// tests reuse with Pulsing1(Pulsing2(Standard)) </summary> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void testNestedPulsing() throws Exception public virtual void testNestedPulsing() { // we always run this test with pulsing codec. Codec cp = TestUtil.alwaysPostingsFormat(new NestedPulsingPostingsFormat()); BaseDirectoryWrapper dir = newDirectory(); RandomIndexWriter iw = new RandomIndexWriter(random(), dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())).setCodec(cp)); Document doc = new Document(); doc.add(new TextField("foo", "a b b c c c d e f g g g h i i j j k l l m m m", Field.Store.NO)); // note: the reuse is imperfect, here we would have 4 enums (lost reuse when we get an enum for 'm') // this is because we only track the 'last' enum we reused (not all). // but this seems 'good enough' for now. iw.addDocument(doc); DirectoryReader ir = iw.Reader; iw.close(); AtomicReader segment = getOnlySegmentReader(ir); DocsEnum reuse = null; IDictionary<DocsEnum, bool?> allEnums = new IdentityHashMap<DocsEnum, bool?>(); TermsEnum te = segment.terms("foo").iterator(null); while (te.next() != null) { reuse = te.docs(null, reuse, DocsEnum.FLAG_NONE); allEnums[reuse] = true; } assertEquals(4, allEnums.Count); allEnums.Clear(); DocsAndPositionsEnum posReuse = null; te = segment.terms("foo").iterator(null); while (te.next() != null) { posReuse = te.docsAndPositions(null, posReuse); allEnums[posReuse] = true; } assertEquals(4, allEnums.Count); ir.close(); dir.close(); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void testIndexWriter_LUCENE4656() throws java.io.IOException public virtual void testIndexWriter_LUCENE4656() { Directory directory = newDirectory(); IndexWriter writer = new IndexWriter(directory, newIndexWriterConfig(TEST_VERSION_CURRENT, null)); TokenStream ts = new EmptyTokenStream(); assertFalse(ts.hasAttribute(typeof(TermToBytesRefAttribute))); Document doc = new Document(); doc.add(new StringField("id", "0", Field.Store.YES)); doc.add(new TextField("description", ts)); // this should not fail because we have no TermToBytesRefAttribute writer.addDocument(doc); assertEquals(1, writer.numDocs()); writer.close(); directory.close(); }
//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(); } }
internal virtual DocumentContext GetDocument(EntityId entityId, bool allowCreate) { long id = entityId.Id(); DocumentContext context = Documents.get(id); if (context != null) { return(context); } Document document = LuceneDataSource.FindDocument(IndexType, Searcher.Searcher, id); if (document != null) { context = new DocumentContext(document, true, id); Documents.put(id, context); } else if (allowCreate) { context = new DocumentContext(IndexType.NewDocument(entityId), false, id); Documents.put(id, context); } return(context); }
/// <summary> /// a variant, that uses pulsing, but uses a high TF to force pass thru to the underlying codec /// </summary> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void test10kNotPulsed() throws Exception public virtual void test10kNotPulsed() { // we always run this test with pulsing codec. int freqCutoff = TestUtil.Next(random(), 1, 10); Codec cp = TestUtil.alwaysPostingsFormat(new Pulsing41PostingsFormat(freqCutoff)); File f = createTempDir("10knotpulsed"); BaseDirectoryWrapper dir = newFSDirectory(f); dir.CheckIndexOnClose = false; // we do this ourselves explicitly RandomIndexWriter iw = new RandomIndexWriter(random(), dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())).setCodec(cp)); Document document = new Document(); FieldType ft = new FieldType(TextField.TYPE_STORED); switch (TestUtil.Next(random(), 0, 2)) { case 0: ft.IndexOptions = IndexOptions.DOCS_ONLY; break; case 1: ft.IndexOptions = IndexOptions.DOCS_AND_FREQS; break; default: ft.IndexOptions = IndexOptions.DOCS_AND_FREQS_AND_POSITIONS; break; } Field field = newField("field", "", ft); document.add(field); NumberFormat df = new DecimalFormat("00000", new DecimalFormatSymbols(Locale.ROOT)); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final int freq = freqCutoff + 1; int freq = freqCutoff + 1; for (int i = 0; i < 10050; i++) { StringBuilder sb = new StringBuilder(); for (int j = 0; j < freq; j++) { sb.Append(df.format(i)); sb.Append(' '); // whitespace } field.StringValue = sb.ToString(); iw.addDocument(document); } IndexReader ir = iw.Reader; iw.close(); TermsEnum te = MultiFields.getTerms(ir, "field").iterator(null); DocsEnum de = null; for (int i = 0; i < 10050; i++) { string expected = df.format(i); assertEquals(expected, te.next().utf8ToString()); de = TestUtil.docs(random(), te, null, de, DocsEnum.FLAG_NONE); assertTrue(de.nextDoc() != DocIdSetIterator.NO_MORE_DOCS); assertEquals(DocIdSetIterator.NO_MORE_DOCS, de.nextDoc()); } ir.close(); TestUtil.checkIndex(dir); dir.close(); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void test10kPulsed() throws Exception public virtual void test10kPulsed() { // we always run this test with pulsing codec. Codec cp = TestUtil.alwaysPostingsFormat(new Pulsing41PostingsFormat(1)); File f = createTempDir("10kpulsed"); BaseDirectoryWrapper dir = newFSDirectory(f); dir.CheckIndexOnClose = false; // we do this ourselves explicitly RandomIndexWriter iw = new RandomIndexWriter(random(), dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())).setCodec(cp)); Document document = new Document(); FieldType ft = new FieldType(TextField.TYPE_STORED); switch (TestUtil.Next(random(), 0, 2)) { case 0: ft.IndexOptions = IndexOptions.DOCS_ONLY; break; case 1: ft.IndexOptions = IndexOptions.DOCS_AND_FREQS; break; default: ft.IndexOptions = IndexOptions.DOCS_AND_FREQS_AND_POSITIONS; break; } Field field = newField("field", "", ft); document.add(field); NumberFormat df = new DecimalFormat("00000", new DecimalFormatSymbols(Locale.ROOT)); for (int i = 0; i < 10050; i++) { field.StringValue = df.format(i); iw.addDocument(document); } IndexReader ir = iw.Reader; iw.close(); TermsEnum te = MultiFields.getTerms(ir, "field").iterator(null); DocsEnum de = null; for (int i = 0; i < 10050; i++) { string expected = df.format(i); assertEquals(expected, te.next().utf8ToString()); de = TestUtil.docs(random(), te, null, de, DocsEnum.FLAG_NONE); assertTrue(de.nextDoc() != DocIdSetIterator.NO_MORE_DOCS); assertEquals(DocIdSetIterator.NO_MORE_DOCS, de.nextDoc()); } ir.close(); TestUtil.checkIndex(dir); dir.close(); }
// LUCENE-1448 // TODO: instead of testing it this way, we can test // with BaseTokenStreamTestCase now... //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void testEndOffsetPositionWithTeeSinkTokenFilter() throws Exception public virtual void testEndOffsetPositionWithTeeSinkTokenFilter() { Directory dir = newDirectory(); Analyzer analyzer = new MockAnalyzer(random(), MockTokenizer.WHITESPACE, false); IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, analyzer)); Document doc = new Document(); TokenStream tokenStream = analyzer.tokenStream("field", "abcd "); TeeSinkTokenFilter tee = new TeeSinkTokenFilter(tokenStream); TokenStream sink = tee.newSinkTokenStream(); FieldType ft = new FieldType(TextField.TYPE_NOT_STORED); ft.StoreTermVectors = true; ft.StoreTermVectorOffsets = true; ft.StoreTermVectorPositions = true; Field f1 = new Field("field", tee, ft); Field f2 = new Field("field", sink, ft); doc.add(f1); doc.add(f2); w.addDocument(doc); w.close(); IndexReader r = DirectoryReader.open(dir); Terms vector = r.getTermVectors(0).terms("field"); assertEquals(1, vector.size()); TermsEnum termsEnum = vector.iterator(null); termsEnum.next(); assertEquals(2, termsEnum.totalTermFreq()); DocsAndPositionsEnum positions = termsEnum.docsAndPositions(null, null); assertTrue(positions.nextDoc() != DocIdSetIterator.NO_MORE_DOCS); assertEquals(2, positions.freq()); positions.nextPosition(); assertEquals(0, positions.startOffset()); assertEquals(4, positions.endOffset()); positions.nextPosition(); assertEquals(8, positions.startOffset()); assertEquals(12, positions.endOffset()); assertEquals(DocIdSetIterator.NO_MORE_DOCS, positions.nextDoc()); r.close(); dir.close(); }
/* public void testPerFieldAnalyzer() throws Exception { PerFieldAnalyzerWrapper analyzer = new PerFieldAnalyzerWrapper(new SimpleAnalyzer(TEST_VERSION_CURRENT)); analyzer.addAnalyzer("partnum", new KeywordAnalyzer()); QueryParser queryParser = new QueryParser(TEST_VERSION_CURRENT, "description", analyzer); Query query = queryParser.parse("partnum:Q36 AND SPACE"); ScoreDoc[] hits = searcher.search(query, null, 1000).scoreDocs; assertEquals("Q36 kept as-is", "+partnum:Q36 +space", query.toString("description")); assertEquals("doc found!", 1, hits.length); } */ //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void testMutipleDocument() throws Exception public virtual void testMutipleDocument() { RAMDirectory dir = new RAMDirectory(); IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new KeywordAnalyzer())); Document doc = new Document(); doc.add(new TextField("partnum", "Q36", Field.Store.YES)); writer.addDocument(doc); doc = new Document(); doc.add(new TextField("partnum", "Q37", Field.Store.YES)); writer.addDocument(doc); writer.close(); IndexReader reader = DirectoryReader.open(dir); DocsEnum td = TestUtil.docs(random(), reader, "partnum", new BytesRef("Q36"), MultiFields.getLiveDocs(reader), null, 0); assertTrue(td.nextDoc() != DocIdSetIterator.NO_MORE_DOCS); td = TestUtil.docs(random(), reader, "partnum", new BytesRef("Q37"), MultiFields.getLiveDocs(reader), null, 0); assertTrue(td.nextDoc() != DocIdSetIterator.NO_MORE_DOCS); }
/// <summary> /// Make sure we skip wicked long terms. /// </summary> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void testWickedLongTerm() throws java.io.IOException public virtual void testWickedLongTerm() { RAMDirectory dir = new RAMDirectory(); IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new ClassicAnalyzer(TEST_VERSION_CURRENT))); char[] chars = new char[IndexWriter.MAX_TERM_LENGTH]; Arrays.fill(chars, 'x'); Document doc = new Document(); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final String bigTerm = new String(chars); string bigTerm = new string(chars); // This produces a too-long term: string contents = "abc xyz x" + bigTerm + " another term"; doc.add(new TextField("content", contents, Field.Store.NO)); writer.addDocument(doc); // Make sure we can add another normal document doc = new Document(); doc.add(new TextField("content", "abc bbb ccc", Field.Store.NO)); writer.addDocument(doc); writer.close(); IndexReader reader = IndexReader.open(dir); // Make sure all terms < max size were indexed assertEquals(2, reader.docFreq(new Term("content", "abc"))); assertEquals(1, reader.docFreq(new Term("content", "bbb"))); assertEquals(1, reader.docFreq(new Term("content", "term"))); assertEquals(1, reader.docFreq(new Term("content", "another"))); // Make sure position is still incremented when // massive term is skipped: DocsAndPositionsEnum tps = MultiFields.getTermPositionsEnum(reader, MultiFields.getLiveDocs(reader), "content", new BytesRef("another")); assertTrue(tps.nextDoc() != DocIdSetIterator.NO_MORE_DOCS); assertEquals(1, tps.freq()); assertEquals(3, tps.nextPosition()); // Make sure the doc that has the massive term is in // the index: assertEquals("document with wicked long term should is not in the index!", 2, reader.numDocs()); reader.close(); // Make sure we can add a document with exactly the // maximum length term, and search on that term: doc = new Document(); doc.add(new TextField("content", bigTerm, Field.Store.NO)); ClassicAnalyzer sa = new ClassicAnalyzer(TEST_VERSION_CURRENT); sa.MaxTokenLength = 100000; writer = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, sa)); writer.addDocument(doc); writer.close(); reader = IndexReader.open(dir); assertEquals(1, reader.docFreq(new Term("content", bigTerm))); reader.close(); dir.close(); }
public abstract void Enhance(Document document);
internal DocumentContext(Document document, bool exists, long entityId) { this.Document = document; this.Exists = exists; this.EntityId = entityId; }
// TODO: this is a basic test. this thing is complicated, add more //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void testSophisticatedReuse() throws Exception public virtual void testSophisticatedReuse() { // we always run this test with pulsing codec. Codec cp = TestUtil.alwaysPostingsFormat(new Pulsing41PostingsFormat(1)); Directory dir = newDirectory(); RandomIndexWriter iw = new RandomIndexWriter(random(), dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())).setCodec(cp)); Document doc = new Document(); doc.add(new TextField("foo", "a b b c c c d e f g g h i i j j k", Field.Store.NO)); iw.addDocument(doc); DirectoryReader ir = iw.Reader; iw.close(); AtomicReader segment = getOnlySegmentReader(ir); DocsEnum reuse = null; IDictionary<DocsEnum, bool?> allEnums = new IdentityHashMap<DocsEnum, bool?>(); TermsEnum te = segment.terms("foo").iterator(null); while (te.next() != null) { reuse = te.docs(null, reuse, DocsEnum.FLAG_NONE); allEnums[reuse] = true; } assertEquals(2, allEnums.Count); allEnums.Clear(); DocsAndPositionsEnum posReuse = null; te = segment.terms("foo").iterator(null); while (te.next() != null) { posReuse = te.docsAndPositions(null, posReuse); allEnums[posReuse] = true; } assertEquals(2, allEnums.Count); ir.close(); dir.close(); }
public override void Enhance(Document document) { // Nothing to enhance here }
public override void Enhance(Document document) { document.add(new StringField(LuceneExplicitIndex.KEY_START_NODE_ID, "" + StartNode, Store.YES)); document.add(new StringField(LuceneExplicitIndex.KEY_END_NODE_ID, "" + EndNode, Store.YES)); }