Exemplo n.º 1
0
        /// <summary> Creates a hit queue sorted by the given list of fields.</summary>
        /// <param name="reader"> Index to use.
        /// </param>
        /// <param name="fields">Fieldable names, in priority order (highest priority first).  Cannot be <code>null</code> or empty.
        /// </param>
        /// <param name="size"> The number of hits to retain.  Must be greater than zero.
        /// </param>
        /// <throws>  IOException </throws>
        public FieldSortedHitQueue(IndexReader reader, SortField[] fields, int size)
        {
            int n = fields.Length;

            comparators = new ScoreDocComparator[n];
            this.fields = new SortField[n];
            for (int i = 0; i < n; ++i)
            {
                System.String fieldname = fields[i].GetField();
                comparators[i] = GetCachedComparator(reader, fieldname, fields[i].GetType(), fields[i].GetParser(), fields[i].GetLocale(), fields[i].GetFactory());
                // new SortField instances must only be created when auto-detection is in use
                if (fields[i].GetType() == SortField.AUTO)
                {
                    if (comparators[i].SortType() == SortField.STRING)
                    {
                        this.fields[i] = new SortField(fieldname, fields[i].GetLocale(), fields[i].GetReverse());
                    }
                    else
                    {
                        this.fields[i] = new SortField(fieldname, comparators[i].SortType(), fields[i].GetReverse());
                    }
                }
                else
                {
                    System.Diagnostics.Debug.Assert(comparators [i].SortType() == fields [i].GetType());
                    this.fields[i] = fields[i];
                }
            }
            Initialize(size);
        }
Exemplo n.º 2
0
        internal static ScoreDocComparator GetCachedComparator(IndexReader reader, System.String fieldname, int type, System.Globalization.CultureInfo locale, SortComparatorSource factory)
        {
            if (type == SortField.DOC)
            {
                return(Lucene.Net.Search.ScoreDocComparator_Fields.INDEXORDER);
            }
            if (type == SortField.SCORE)
            {
                return(Lucene.Net.Search.ScoreDocComparator_Fields.RELEVANCE);
            }
            ScoreDocComparator comparator = Lookup(reader, fieldname, type, locale, factory);

            if (comparator == null)
            {
                switch (type)
                {
                case SortField.AUTO:
                    comparator = ComparatorAuto(reader, fieldname);
                    break;

                case SortField.INT:
                    comparator = ComparatorInt(reader, fieldname);
                    break;

                case SortField.FLOAT:
                    comparator = ComparatorFloat(reader, fieldname);
                    break;

                case SortField.STRING:
                    if (locale != null)
                    {
                        comparator = ComparatorStringLocale(reader, fieldname, locale);
                    }
                    else
                    {
                        comparator = ComparatorString(reader, fieldname);
                    }
                    break;

                case SortField.CUSTOM:
                    comparator = factory.NewComparator(reader, fieldname);
                    break;

                default:
                    throw new System.SystemException("unknown field type: " + type);
                }
                Store(reader, fieldname, type, locale, factory, comparator);
            }
            return(comparator);
        }
Exemplo n.º 3
0
        /// <summary> Creates a hit queue sorted by the given list of fields.</summary>
        /// <param name="reader"> Index to use.
        /// </param>
        /// <param name="fields">Field names, in priority order (highest priority first).  Cannot be <code>null</code> or empty.
        /// </param>
        /// <param name="size"> The number of hits to retain.  Must be greater than zero.
        /// </param>
        /// <throws>  IOException </throws>
        internal FieldSortedHitQueue(Monodoc.Lucene.Net.Index.IndexReader reader, SortField[] fields, int size)
        {
            int n = fields.Length;

            comparators = new ScoreDocComparator[n];
            this.fields = new SortField[n];
            for (int i = 0; i < n; ++i)
            {
                System.String fieldname = fields[i].GetField();
                comparators[i] = GetCachedComparator(reader, fieldname, fields[i].GetType(), fields[i].GetLocale(), fields[i].GetFactory());
                this.fields[i] = new SortField(fieldname, comparators[i].SortType(), fields[i].GetReverse());
            }
            Initialize(size);
        }
        /// <summary> Creates a hit queue sorted by the given list of fields.</summary>
        /// <param name="reader"> Index to use.
        /// </param>
        /// <param name="fields">Fieldable names, in priority order (highest priority first).  Cannot be <code>null</code> or empty.
        /// </param>
        /// <param name="size"> The number of hits to retain.  Must be greater than zero.
        /// </param>
        /// <throws>  IOException </throws>
        public FieldSortedHitQueue(IndexReader reader, SortField[] fields, int size)
        {
            int n = fields.Length;

            comparators = new ScoreDocComparator[n];
            this.fields = new SortField[n];
            for (int i = 0; i < n; ++i)
            {
                System.String fieldname = fields[i].GetField();
                comparators[i] = GetCachedComparator(reader, fieldname, fields[i].GetType(), fields[i].GetLocale(), fields[i].GetFactory());

                if (comparators[i].SortType() == SortField.STRING)
                {
                    this.fields[i] = new SortField(fieldname, fields[i].GetLocale(), fields[i].GetReverse());
                }
                else
                {
                    this.fields[i] = new SortField(fieldname, comparators[i].SortType(), fields[i].GetReverse());
                }
            }
            Initialize(size);
        }
Exemplo n.º 5
0
 static ScoreDocComparator_Fields()
 {
     RELEVANCE  = new AnonymousClassScoreDocComparator();
     INDEXORDER = new AnonymousClassScoreDocComparator1();
 }
Exemplo n.º 6
0
		/// <summary> Creates a hit queue sorted by the given list of fields.</summary>
		/// <param name="reader"> Index to use.
		/// </param>
		/// <param name="fields">Fieldable names, in priority order (highest priority first).  Cannot be <code>null</code> or empty.
		/// </param>
		/// <param name="size"> The number of hits to retain.  Must be greater than zero.
		/// </param>
		/// <throws>  IOException </throws>
		public FieldSortedHitQueue(IndexReader reader, SortField[] fields, int size)
		{
			int n = fields.Length;
			comparators = new ScoreDocComparator[n];
			this.fields = new SortField[n];
			for (int i = 0; i < n; ++i)
			{
				System.String fieldname = fields[i].GetField();
				comparators[i] = GetCachedComparator(reader, fieldname, fields[i].GetType(), fields[i].GetParser(), fields[i].GetLocale(), fields[i].GetFactory());
				// new SortField instances must only be created when auto-detection is in use
				if (fields[i].GetType() == SortField.AUTO)
				{
					if (comparators[i].SortType() == SortField.STRING)
					{
						this.fields[i] = new SortField(fieldname, fields[i].GetLocale(), fields[i].GetReverse());
					}
					else
					{
						this.fields[i] = new SortField(fieldname, comparators[i].SortType(), fields[i].GetReverse());
					}
				}
				else
				{
					System.Diagnostics.Debug.Assert(comparators [i].SortType() == fields [i].GetType());
					this.fields[i] = fields[i];
				}
			}
			Initialize(size);
		}
Exemplo n.º 7
0
 static ScoreDocComparator_Fields()
 {
     RELEVANCE = new AnonymousClassScoreDocComparator();
     INDEXORDER = new AnonymousClassScoreDocComparator1();
 }
Exemplo n.º 8
0
		/// <summary> Creates a hit queue sorted by the given list of fields.</summary>
		/// <param name="reader"> Index to use.
		/// </param>
		/// <param name="fields">Field names, in priority order (highest priority first).  Cannot be <code>null</code> or empty.
		/// </param>
		/// <param name="size"> The number of hits to retain.  Must be greater than zero.
		/// </param>
		/// <throws>  IOException </throws>
		internal FieldSortedHitQueue(IndexReader reader, SortField[] fields, int size)
		{
			int n = fields.Length;
			comparators = new ScoreDocComparator[n];
			this.fields = new SortField[n];
			for (int i = 0; i < n; ++i)
			{
				System.String fieldname = fields[i].GetField();
				comparators[i] = GetCachedComparator(reader, fieldname, fields[i].GetType(), fields[i].GetLocale(), fields[i].GetFactory());
				this.fields[i] = new SortField(fieldname, comparators[i].SortType(), fields[i].GetReverse());
			}
			Initialize(size);
		}