当前位置: 首页>>代码示例>>C#>>正文


C# IndexReader.GetFieldNames方法代码示例

本文整理汇总了C#中Lucene.Net.Index.IndexReader.GetFieldNames方法的典型用法代码示例。如果您正苦于以下问题:C# IndexReader.GetFieldNames方法的具体用法?C# IndexReader.GetFieldNames怎么用?C# IndexReader.GetFieldNames使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Lucene.Net.Index.IndexReader的用法示例。


在下文中一共展示了IndexReader.GetFieldNames方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetSearchFields

				/// <summary>
				/// Returns a list of fields to search on
				/// </summary>
				/// <returns></returns>
				protected static string[] GetSearchFields(IndexReader reader)
				{
						//exclude the special index fields
						return reader.GetFieldNames(IndexReader.FieldOption.ALL)
								.Where(x => !x.StartsWith(LuceneIndexer.SpecialFieldPrefix))
								.ToArray();
				}
开发者ID:uniquelau,项目名称:vdb.UmbracoExtensions,代码行数:11,代码来源:LuceneSearcher.cs

示例2: TryLoad

        public bool TryLoad(string path, IndexLoadOptions options)
        {
            try
            {
                _directory = FSDirectory.Open(path);
                _reader = IndexReader.Open(_directory, options.ReadOnly);

                if (options.ForceUnlock && _directory.FileExists(IndexWriter.WRITE_LOCK_NAME))
                {
                    _directory.ClearLock(IndexWriter.WRITE_LOCK_NAME);
                }

                var fields = _reader.GetFieldNames(IndexReader.FieldOption.ALL);
                _numFields = fields.Count;

                CountTerms();

                foreach (var file in _directory.ListAll())
                {
                    try
                    {
                        string fpath = Path.Combine(_directory.Directory.ToString(), file);

                        if (_lastModified == null)
                            _lastModified = File.GetLastWriteTimeUtc(fpath);
                        else
                        {
                            var mod = File.GetLastWriteTimeUtc(fpath);
                            if (mod > _lastModified.Value)
                                _lastModified = mod;
                        }
                    }
                    catch
                    {
                        // ignore
                    }
                }

                _loaded = true;
                return true;
            }
            catch
            {
                _directory = null;
                _reader = null;
                _numFields = 0;
                _numTerms = 0;
                _loaded = false;
                _lastModified = null;
                return false;
            }
        }
开发者ID:paulirwin,项目名称:Luke.Net,代码行数:52,代码来源:IndexService.cs

示例3: GetDocIdSet

        public override DocIdSet GetDocIdSet(IndexReader reader)
        {
            var result = new FixedBitSet(reader.MaxDoc);
            var fields = reader.GetFieldNames(IndexReader.FieldOption.ALL);

            if (fields == null || fields.Count == 0)
            {
                return result;
            }

            String lastField = null;
            TermsEnumCompatibility termsEnum = null;
            foreach (Term term in terms)
            {
                if (!term.Field.Equals(lastField))
                {
                    var termsC = new TermsEnumCompatibility(reader, term.Field);
                    if (termsC.Term() == null)
                    {
                        return result;
                    }
                    termsEnum = termsC;
                    lastField = term.Field;
                }

                if (terms != null)
                {
                    // TODO this check doesn't make sense, decide which variable its supposed to be for
                    Debug.Assert(termsEnum != null);
                    if (termsEnum.SeekCeil(term.Text) == TermsEnumCompatibility.SeekStatus.FOUND)
                    {
                        termsEnum.Docs(result);
                    }
                }
            }
            return result;
        }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:37,代码来源:TermsFilter.cs

示例4: AddStopWords

 /*
    * Automatically adds stop words for all fields with terms exceeding the maxDocFreqPercent
    *
    * @param reader        The {@link IndexReader} which will be consulted to identify potential stop words that
    *                      exceed the required document frequency
    * @param maxPercentDocs The maximum percentage (between 0.0 and 1.0) of index documents which
    *                      contain a term, after which the word is considered to be a stop word.
    * @return The number of stop words identified.
    * @throws IOException
    */
 public int AddStopWords(IndexReader reader, float maxPercentDocs)
 {
     int numStopWords = 0;
     ICollection<String> fieldNames = reader.GetFieldNames(IndexReader.FieldOption.INDEXED);
     for (IEnumerator<String> iter = fieldNames.GetEnumerator(); iter.MoveNext();) {
       String fieldName = iter.Current;
       numStopWords += AddStopWords(reader, fieldName, maxPercentDocs);
     }
     return numStopWords;
 }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:20,代码来源:QueryAutoStopWordAnalyzer.cs

示例5: Add

		/// <summary>Add an IndexReader whose stored fields will not be returned.  This can
		/// accellerate search when stored fields are only needed from a subset of
		/// the IndexReaders.
		/// 
		/// </summary>
		/// <throws>  IllegalArgumentException if not all indexes contain the same number </throws>
		/// <summary>     of documents
		/// </summary>
		/// <throws>  IllegalArgumentException if not all indexes have the same value </throws>
		/// <summary>     of {@link IndexReader#MaxDoc()}
		/// </summary>
		/// <throws>  IOException if there is a low-level IO error </throws>
		public virtual void  Add(IndexReader reader, bool ignoreStoredFields)
		{
			
			EnsureOpen();
			if (readers.Count == 0)
			{
				this.maxDoc = reader.MaxDoc();
				this.numDocs = reader.NumDocs();
				this.hasDeletions = reader.HasDeletions();
			}
			
			if (reader.MaxDoc() != maxDoc)
			// check compatibility
				throw new System.ArgumentException("All readers must have same maxDoc: " + maxDoc + "!=" + reader.MaxDoc());
			if (reader.NumDocs() != numDocs)
				throw new System.ArgumentException("All readers must have same numDocs: " + numDocs + "!=" + reader.NumDocs());
			
			System.Collections.Generic.ICollection<string> fields = reader.GetFieldNames(IndexReader.FieldOption.ALL);
			readerToFields[reader] = fields;
			System.Collections.IEnumerator i = fields.GetEnumerator();
			while (i.MoveNext())
			{
				// update fieldToReader map
				System.String field = (System.String) i.Current;
				if (fieldToReader[field] == null)
					fieldToReader[field] = reader;
			}
			
			if (!ignoreStoredFields)
				storedFieldReaders.Add(reader); // add to storedFieldReaders
			readers.Add(reader);
			
			if (incRefReaders)
			{
				reader.IncRef();
			}
			decrefOnClose.Add(incRefReaders);
		}
开发者ID:VirtueMe,项目名称:ravendb,代码行数:50,代码来源:ParallelReader.cs

示例6: Add

		/// <summary>Add an IndexReader whose stored fields will not be returned.  This can
		/// accellerate search when stored fields are only needed from a subset of
		/// the IndexReaders.
		/// 
		/// </summary>
		/// <throws>  IllegalArgumentException if not all indexes contain the same number </throws>
		/// <summary>     of documents
		/// </summary>
		/// <throws>  IllegalArgumentException if not all indexes have the same value </throws>
		/// <summary>     of <see cref="IndexReader.MaxDoc" />
		/// </summary>
		/// <throws>  IOException if there is a low-level IO error </throws>
		public virtual void  Add(IndexReader reader, bool ignoreStoredFields)
		{
			
			EnsureOpen();
			if (readers.Count == 0)
			{
				this.maxDoc = reader.MaxDoc;
				this.numDocs = reader.NumDocs();
				this.hasDeletions = reader.HasDeletions;
			}
			
			if (reader.MaxDoc != maxDoc)
			// check compatibility
				throw new System.ArgumentException("All readers must have same maxDoc: " + maxDoc + "!=" + reader.MaxDoc);
			if (reader.NumDocs() != numDocs)
				throw new System.ArgumentException("All readers must have same numDocs: " + numDocs + "!=" + reader.NumDocs());
			
			ICollection<string> fields = reader.GetFieldNames(IndexReader.FieldOption.ALL);
			readerToFields[reader] = fields;
			foreach(var field in fields)
			{
				// update fieldToReader map
                // Do a containskey firt to mimic java behavior
				if (!fieldToReader.ContainsKey(field) || fieldToReader[field] == null)
					fieldToReader[field] = reader;
			}
			
			if (!ignoreStoredFields)
				storedFieldReaders.Add(reader); // add to storedFieldReaders
			readers.Add(reader);
			
			if (incRefReaders)
			{
				reader.IncRef();
			}
			decrefOnClose.Add(incRefReaders);
		}
开发者ID:modulexcite,项目名称:Xamarin-Lucene.Net,代码行数:49,代码来源:ParallelReader.cs

示例7: AssertIndexEquals

		public static void  AssertIndexEquals(IndexReader index1, IndexReader index2)
		{
			Assert.AreEqual(index1.NumDocs(), index2.NumDocs(), "IndexReaders have different values for numDocs.");
			Assert.AreEqual(index1.MaxDoc, index2.MaxDoc, "IndexReaders have different values for maxDoc.");
			Assert.AreEqual(index1.HasDeletions, index2.HasDeletions, "Only one IndexReader has deletions.");
			Assert.AreEqual(index1.IsOptimized(), index2.IsOptimized(), "Only one index is optimized.");
			
			// check field names
			System.Collections.Generic.ICollection<string> fieldsNames1 = index1.GetFieldNames(FieldOption.ALL);
			System.Collections.Generic.ICollection<string> fieldsNames2 = index1.GetFieldNames(FieldOption.ALL);

            System.Collections.Generic.ICollection<IFieldable> fields1 = null;
            System.Collections.Generic.ICollection<IFieldable> fields2 = null;

            Assert.AreEqual(fieldsNames1.Count, fieldsNames2.Count, "IndexReaders have different numbers of fields.");
            System.Collections.IEnumerator it1 = fieldsNames1.GetEnumerator();
            System.Collections.IEnumerator it2 = fieldsNames2.GetEnumerator();
			while (it1.MoveNext() && it2.MoveNext())
			{
				Assert.AreEqual((System.String) it1.Current, (System.String) it2.Current, "Different field names.");
			}
			
			// check norms
            it1 = fieldsNames1.GetEnumerator();
			while (it1.MoveNext())
			{
				System.String curField = (System.String) it1.Current;
				byte[] norms1 = index1.Norms(curField);
				byte[] norms2 = index2.Norms(curField);
				if (norms1 != null && norms2 != null)
				{
					Assert.AreEqual(norms1.Length, norms2.Length);
					for (int i = 0; i < norms1.Length; i++)
					{
						Assert.AreEqual(norms1[i], norms2[i], "Norm different for doc " + i + " and field '" + curField + "'.");
					}
				}
				else
				{
					Assert.AreSame(norms1, norms2);
				}
			}
			
			// check deletions
			for (int i = 0; i < index1.MaxDoc; i++)
			{
				Assert.AreEqual(index1.IsDeleted(i), index2.IsDeleted(i), "Doc " + i + " only deleted in one index.");
			}
			
			// check stored fields
			for (int i = 0; i < index1.MaxDoc; i++)
			{
				if (!index1.IsDeleted(i))
				{
					Document doc1 = index1.Document(i);
					Document doc2 = index2.Document(i);
					fields1 = doc1.GetFields();
					fields2 = doc2.GetFields();
					Assert.AreEqual(fields1.Count, fields2.Count, "Different numbers of fields for doc " + i + ".");
					it1 = fields1.GetEnumerator();
					it2 = fields2.GetEnumerator();
					while (it1.MoveNext() && it2.MoveNext())
					{
						Field curField1 = (Field) it1.Current;
						Field curField2 = (Field) it2.Current;
						Assert.AreEqual(curField1.Name, curField2.Name, "Different fields names for doc " + i + ".");
						Assert.AreEqual(curField1.StringValue, curField2.StringValue, "Different field values for doc " + i + ".");
					}
				}
			}
			
			// check dictionary and posting lists
			TermEnum enum1 = index1.Terms();
			TermEnum enum2 = index2.Terms();
			TermPositions tp1 = index1.TermPositions();
			TermPositions tp2 = index2.TermPositions();
			while (enum1.Next())
			{
				Assert.IsTrue(enum2.Next());
				Assert.AreEqual(enum1.Term, enum2.Term, "Different term in dictionary.");
				tp1.Seek(enum1.Term);
				tp2.Seek(enum1.Term);
				while (tp1.Next())
				{
					Assert.IsTrue(tp2.Next());
					Assert.AreEqual(tp1.Doc, tp2.Doc, "Different doc id in postinglist of term " + enum1.Term + ".");
					Assert.AreEqual(tp1.Freq, tp2.Freq, "Different term frequence in postinglist of term " + enum1.Term + ".");
					for (int i = 0; i < tp1.Freq; i++)
					{
						Assert.AreEqual(tp1.NextPosition(), tp2.NextPosition(), "Different positions in postinglist of term " + enum1.Term + ".");
					}
				}
			}
		}
开发者ID:raol,项目名称:lucene.net,代码行数:94,代码来源:TestIndexReader.cs

示例8: GetFieldNames

		private static string[] GetFieldNames(IndexReader indexReader)
		{
			var fields = indexReader.GetFieldNames(IndexReader.FieldOption.INDEXED);
			return fields
				.Where(x => x != Constants.DocumentIdFieldName && x != Constants.ReduceKeyFieldName)
				.ToArray();
		}
开发者ID:randacc,项目名称:ravendb,代码行数:7,代码来源:MoreLikeThisQueryRunner.cs

示例9: Add

		/// <summary>Add an IndexReader whose stored fields will not be returned.  This can
		/// accellerate search when stored fields are only needed from a subset of
		/// the IndexReaders.
		/// 
		/// </summary>
		/// <throws>  IllegalArgumentException if not all indexes contain the same number  </throws>
		/// <summary>     of documents
		/// </summary>
		/// <throws>  IllegalArgumentException if not all indexes have the same value  </throws>
		/// <summary>     of {@link IndexReader#MaxDoc()}
		/// </summary>
		public virtual void  Add(IndexReader reader, bool ignoreStoredFields)
		{
			
			if (readers.Count == 0)
			{
				this.maxDoc = reader.MaxDoc();
				this.numDocs = reader.NumDocs();
				this.hasDeletions = reader.HasDeletions();
			}
			
			if (reader.MaxDoc() != maxDoc)
			// check compatibility
				throw new System.ArgumentException("All readers must have same maxDoc: " + maxDoc + "!=" + reader.MaxDoc());
			if (reader.NumDocs() != numDocs)
				throw new System.ArgumentException("All readers must have same numDocs: " + numDocs + "!=" + reader.NumDocs());
			
			System.Collections.IEnumerator i = reader.GetFieldNames(IndexReader.FieldOption.ALL).GetEnumerator();
			while (i.MoveNext())
			{
                System.Collections.DictionaryEntry fi = (System.Collections.DictionaryEntry) i.Current;

				// update fieldToReader map
				System.String field = fi.Key.ToString();
				if (fieldToReader[field] == null)
					fieldToReader[field] = reader;
			}
			
			if (!ignoreStoredFields)
				storedFieldReaders.Add(reader); // add to storedFieldReaders
			readers.Add(reader);
		}
开发者ID:ArsenShnurkov,项目名称:beagle-1,代码行数:42,代码来源:ParallelReader.cs


注:本文中的Lucene.Net.Index.IndexReader.GetFieldNames方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。