📄 fieldsortedhitqueue.cs
字号:
/*
* 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 IndexReader = Lucene.Net.Index.IndexReader;
using PriorityQueue = Lucene.Net.Util.PriorityQueue;
namespace Lucene.Net.Search
{
/// <summary> Expert: A hit queue for sorting by hits by terms in more than one field.
/// Uses <code>FieldCache.DEFAULT</code> for maintaining internal term lookup tables.
///
/// <p>Created: Dec 8, 2003 12:56:03 PM
///
/// </summary>
/// <author> Tim Jones (Nacimiento Software)
/// </author>
/// <since> lucene 1.4
/// </since>
/// <version> $Id: FieldSortedHitQueue.java 477084 2006-11-20 07:10:04Z otis $
/// </version>
/// <seealso cref="Searcher#Search(Query,Filter,int,Sort)">
/// </seealso>
/// <seealso cref="FieldCache">
/// </seealso>
public class FieldSortedHitQueue : PriorityQueue
{
internal class AnonymousClassCache : FieldCacheImpl.Cache
{
protected internal override System.Object CreateValue(IndexReader reader, System.Object entryKey)
{
FieldCacheImpl.Entry entry = (FieldCacheImpl.Entry) entryKey;
System.String fieldname = entry.field;
int type = entry.type;
System.Globalization.CultureInfo locale = entry.locale;
SortComparatorSource factory = (SortComparatorSource) entry.custom;
ScoreDocComparator comparator;
switch (type)
{
case SortField.AUTO:
comparator = Lucene.Net.Search.FieldSortedHitQueue.ComparatorAuto(reader, fieldname);
break;
case SortField.INT:
comparator = Lucene.Net.Search.FieldSortedHitQueue.comparatorInt(reader, fieldname);
break;
case SortField.FLOAT:
comparator = Lucene.Net.Search.FieldSortedHitQueue.comparatorFloat(reader, fieldname);
break;
case SortField.STRING:
if (locale != null)
comparator = Lucene.Net.Search.FieldSortedHitQueue.comparatorStringLocale(reader, fieldname, locale);
else
comparator = Lucene.Net.Search.FieldSortedHitQueue.comparatorString(reader, fieldname);
break;
case SortField.CUSTOM:
comparator = factory.NewComparator(reader, fieldname);
break;
default:
throw new System.SystemException("unknown field type: " + type);
}
return comparator;
}
}
private class AnonymousClassScoreDocComparator : ScoreDocComparator
{
public AnonymousClassScoreDocComparator(int[] fieldOrder)
{
InitBlock(fieldOrder);
}
private void InitBlock(int[] fieldOrder)
{
this.fieldOrder = fieldOrder;
}
private int[] fieldOrder;
public int Compare(ScoreDoc i, ScoreDoc j)
{
int fi = fieldOrder[i.doc];
int fj = fieldOrder[j.doc];
if (fi < fj)
return - 1;
if (fi > fj)
return 1;
return 0;
}
public virtual System.IComparable SortValue(ScoreDoc i)
{
return (System.Int32) fieldOrder[i.doc];
}
public virtual int SortType()
{
return SortField.INT;
}
}
private class AnonymousClassScoreDocComparator1 : ScoreDocComparator
{
public AnonymousClassScoreDocComparator1(float[] fieldOrder)
{
InitBlock(fieldOrder);
}
private void InitBlock(float[] fieldOrder)
{
this.fieldOrder = fieldOrder;
}
private float[] fieldOrder;
public int Compare(ScoreDoc i, ScoreDoc j)
{
float fi = fieldOrder[i.doc];
float fj = fieldOrder[j.doc];
if (fi < fj)
return - 1;
if (fi > fj)
return 1;
return 0;
}
public virtual System.IComparable SortValue(ScoreDoc i)
{
return (float) fieldOrder[i.doc];
}
public virtual int SortType()
{
return SortField.FLOAT;
}
}
private class AnonymousClassScoreDocComparator2 : ScoreDocComparator
{
public AnonymousClassScoreDocComparator2(Lucene.Net.Search.StringIndex index)
{
InitBlock(index);
}
private void InitBlock(Lucene.Net.Search.StringIndex index)
{
this.index = index;
}
private Lucene.Net.Search.StringIndex index;
public int Compare(ScoreDoc i, ScoreDoc j)
{
int fi = index.order[i.doc];
int fj = index.order[j.doc];
if (fi < fj)
return - 1;
if (fi > fj)
return 1;
return 0;
}
public virtual System.IComparable SortValue(ScoreDoc i)
{
return index.lookup[index.order[i.doc]];
}
public virtual int SortType()
{
return SortField.STRING;
}
}
private class AnonymousClassScoreDocComparator3 : ScoreDocComparator
{
public AnonymousClassScoreDocComparator3(System.String[] index, System.Globalization.CompareInfo collator)
{
InitBlock(index, collator);
}
private void InitBlock(System.String[] index, System.Globalization.CompareInfo collator)
{
this.index = index;
this.collator = collator;
}
private System.String[] index;
private System.Globalization.CompareInfo collator;
public int Compare(ScoreDoc i, ScoreDoc j)
{
System.String is_Renamed = index[i.doc];
System.String js = index[j.doc];
if ((System.Object) is_Renamed == (System.Object) js)
{
return 0;
}
else if (is_Renamed == null)
{
return - 1;
}
else if (js == null)
{
return 1;
}
else
{
return collator.Compare(is_Renamed.ToString(), js.ToString());
}
}
public virtual System.IComparable SortValue(ScoreDoc i)
{
return index[i.doc];
}
public virtual int SortType()
{
return SortField.STRING;
}
}
/// <summary> Creates a hit queue sorted by the given list of fields.</summary>
/// <param name="reader"> Index to use.
/// </param>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -