本文整理汇总了C#中Lucene.Net.Search.SortField类的典型用法代码示例。如果您正苦于以下问题:C# SortField类的具体用法?C# SortField怎么用?C# SortField使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SortField类属于Lucene.Net.Search命名空间,在下文中一共展示了SortField类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FieldSortedHitQueue
/// <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 <c>null</c> 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);
}
示例2: ParseSort
public Sort ParseSort(string sortSpec)
{
if (sortSpec == null || sortSpec.Length == 0) return null;
string[] parts = sortSep.Split(sortSpec.Trim());
if (parts.Length == 0) return null;
SortField[] lst = new SortField[parts.Length];
for (int i = 0; i < parts.Length; i++)
{
string part = parts[i].Trim();
bool top = true;
int idx = part.IndexOf(' ');
if (idx > 0)
{
string order = part.Substring(idx + 1).Trim();
if ("desc".Equals(order) || "top".Equals(order))
{
top = true;
}
else if ("asc".Equals(order) || "bottom".Equals(order))
{
top = false;
}
else
{
throw new ArgumentException("Unknown sort order: " + order);
}
part = part.Substring(0, idx).Trim();
}
else
{
throw new ArgumentException("Missing sort order.");
}
if ("score".Equals(part))
{
if (top)
{
// If thre is only one thing in the list, just do the regular thing...
if (parts.Length == 1)
{
return null; // do normal scoring...
}
lst[i] = SortField.FIELD_SCORE;
}
else
{
lst[i] = new SortField(null, SortField.SCORE, true);
}
}
else
{
lst[i] = new SortField(part, SortField.STRING, top);
}
}
return new Sort(lst);
}
示例3: GetHitsByFiled
private Hits GetHitsByFiled(string filedname,Analyzer analyzer, string searchStr, IndexSearcher searcher)
{
MultiFieldQueryParser parser = new MultiFieldQueryParser(Lucene.Net.Util.Version.LUCENE_CURRENT, new string[] { filedname}, analyzer);
Query query = parser.Parse(searchStr);
Sort sort = new Sort();
SortField f = new SortField("publish_time", SortField.STRING, true);//按照publish_time字段排序,true表示降序
sort.SetSort(f);
Hits hits = searcher.Search(query, sort);
return hits;
}
示例4: SetFields
/// <summary> Allows redefinition of sort fields if they are <code>null</code>.
/// This is to handle the case using ParallelMultiSearcher where the
/// original list contains AUTO and we don't know the actual sort
/// type until the values come back. The fields can only be set once.
/// This method is thread safe.
/// </summary>
/// <param name="">fields
/// </param>
internal virtual void SetFields(SortField[] fields)
{
lock (this)
{
if (this.fields == null)
{
this.fields = fields;
this.collators = HasCollators(fields);
}
}
}
示例5: ApplySort
public void ApplySort(SortField[] sorts)
{
if (sorts == null)
{
_req.ClearSort();
}
else
{
_req.Sort = sorts;
}
}
示例6: FieldValueHitQueue
// prevent instantiation and extension.
private FieldValueHitQueue(SortField[] fields)
{
// When we get here, fields.length is guaranteed to be > 0, therefore no
// need to check it again.
// All these are required by this class's API - need to return arrays.
// Therefore even in the case of a single comparator, create an array
// anyway.
this.fields = fields;
int numComparators = fields.Length;
comparators = new FieldComparator[numComparators];
reverseMul = new int[numComparators];
}
示例7: InternalBrowseHitCollector
public InternalBrowseHitCollector(BoboBrowser boboBrowser, SortField[] sort, int offset, int count, bool fetchStoredFields)
{
this.boboBrowser = boboBrowser;
reader = boboBrowser.GetIndexReader();
sortFields = QueryUtils.convertSort(sort, reader);
this.offset = offset;
this.count = count;
this.numHits = offset + count;
hitQueue = new SortedHitQueue(this.boboBrowser, sortFields, offset + count);
totalHits = 0;
this.fetchStoredFields = fetchStoredFields;
this.reverseMul = (from s in sortFields select s.Reverse ? -1 : 1).ToArray();
}
示例8: MultiTopDocsSortedHitCollector
public MultiTopDocsSortedHitCollector(MultiBoboBrowser multiBrowser, SortField[] sort, int offset, int count,
bool fetchStoredFields)
{
this.sort = sort;
this.offset = offset;
this.count = count;
this.multiBrowser = multiBrowser;
IBrowsable[] subBrowsers = this.multiBrowser.getSubBrowsers();
subCollectors = new TopDocsSortedHitCollector[subBrowsers.Length];
for (int i = 0; i < subBrowsers.Length; ++i)
{
subCollectors[i] = subBrowsers[i].GetSortedHitCollector(sort, 0, this.offset + this.count, fetchStoredFields);
}
starts = this.multiBrowser.getStarts();
totalCount = 0;
}
示例9: OneComparatorFieldValueHitQueue
public OneComparatorFieldValueHitQueue(SortField[] fields, int size):base(fields)
{
if (fields.Length == 0)
{
throw new System.ArgumentException("Sort must contain at least one field");
}
SortField field = fields[0];
// AUTO is resolved before we are called
System.Diagnostics.Debug.Assert(field.GetType() != SortField.AUTO);
comparator = field.GetComparator(size, 0);
oneReverseMul = field.reverse?- 1:1;
comparators[0] = comparator;
reverseMul[0] = oneReverseMul;
Initialize(size);
}
示例10: GetNonFacetComparatorSource
private static DocComparatorSource GetNonFacetComparatorSource(SortField sf)
{
string fieldname = sf.Field;
CultureInfo locale = sf.Locale;
if (locale != null)
{
return new DocComparatorSource.StringLocaleComparatorSource(fieldname, locale);
}
int type = sf.Type;
switch (type)
{
case SortField.INT:
return new DocComparatorSource.IntDocComparatorSource(fieldname);
case SortField.FLOAT:
return new DocComparatorSource.FloatDocComparatorSource(fieldname);
case SortField.LONG:
return new DocComparatorSource.LongDocComparatorSource(fieldname);
case SortField.DOUBLE:
return new DocComparatorSource.LongDocComparatorSource(fieldname);
case SortField.BYTE:
return new DocComparatorSource.ByteDocComparatorSource(fieldname);
case SortField.SHORT:
return new DocComparatorSource.ShortDocComparatorSource(fieldname);
case SortField.CUSTOM:
throw new InvalidOperationException("lucene custom sort no longer supported: " + fieldname);
case SortField.STRING:
return new DocComparatorSource.StringOrdComparatorSource(fieldname);
case SortField.STRING_VAL:
return new DocComparatorSource.StringValComparatorSource(fieldname);
default:
throw new InvalidOperationException("Illegal sort type: " + type + ", for field: " + fieldname);
}
}
示例11: NAppIndexReader
public NAppIndexReader(Configuration.ConfigManager config)
{
// TODO: Use Central place to retrieve default setting of Index Full Path
indexFullPath = config.GetSetting(SettingKeys.Index_Directory, System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Index"));
indexFullPath = System.IO.Path.GetFullPath(indexFullPath);
directory = FSDirectory.Open(new System.IO.DirectoryInfo(indexFullPath));
analyzer = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29);
var sortFields = new SortField[2];
sortFields[0] = new SortField(FieldKeys.LogName, SortField.STRING);
sortFields[1] = new SortField(FieldKeys.LogID, SortField.LONG);
logNameIDSort = new Sort(sortFields);
textQueryFields = new string[]{
FieldKeys.Service,
FieldKeys.Method,
FieldKeys.Detail_Desc,
FieldKeys.Detail_Parm,
};
}
示例12: FieldSortedHitQueue
/// <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>
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);
}
示例13: convertSort
public static SortField[] convertSort(SortField[] sortSpec, BoboIndexReader idxReader)
{
SortField[] retVal = DEFAULT_SORT;
if (sortSpec != null && sortSpec.Length > 0)
{
List<SortField> sortList = new List<SortField>(sortSpec.Length + 1);
bool relevanceSortAdded = false;
for (int i = 0; i < sortSpec.Length; ++i)
{
if (SortField.FIELD_DOC.Equals(sortSpec[i]))
{
sortList.Add(SortField.FIELD_DOC);
}
else if (SortField.FIELD_SCORE.Equals(sortSpec[i]))
{
sortList.Add(SortField.FIELD_SCORE);
relevanceSortAdded = true;
}
else
{
string fieldname = sortSpec[i].Field;
if (fieldname != null)
{
SortField sf = sortSpec[i];
sortList.Add(sf);
}
}
}
if (!relevanceSortAdded)
{
sortList.Add(SortField.FIELD_SCORE);
}
retVal = sortList.ToArray();
}
return retVal;
}
示例14: Create
/// <summary> Creates a hit queue sorted by the given list of fields.
///
/// <p/><b>NOTE</b>: The instances returned by this method
/// pre-allocate a full array of length <code>numHits</code>.
///
/// </summary>
/// <param name="fields">SortField array we are sorting by 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 static FieldValueHitQueue Create(SortField[] fields, int size)
{
if (fields.Length == 0)
{
throw new System.ArgumentException("Sort must contain at least one field");
}
if (fields.Length == 1)
{
return new OneComparatorFieldValueHitQueue(fields, size);
}
else
{
return new MultiComparatorsFieldValueHitQueue(fields, size);
}
}
示例15: MultiComparatorsFieldValueHitQueue
public MultiComparatorsFieldValueHitQueue(SortField[] fields, int size):base(fields)
{
int numComparators = comparators.Length;
for (int i = 0; i < numComparators; ++i)
{
SortField field = fields[i];
// AUTO is resolved before we are called
System.Diagnostics.Debug.Assert(field.GetType() != SortField.AUTO);
reverseMul[i] = field.reverse?- 1:1;
comparators[i] = field.GetComparator(size, i);
}
Initialize(size);
}