SortComparator.cs :  » Search-Engines » dotLucene » Lucene » Net » Search » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Search Engines » dotLucene 
dotLucene » Lucene » Net » Search » SortComparator.cs
/*
 * Copyright 2004 The Apache Software Foundation
 * 
 * Licensed 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 IndexReaderLucene.Net.Index.IndexReader;

namespace Lucene.Net.Search{
  
  /// <summary> Abstract base class for sorting hits returned by a Query.
  /// 
  /// <p>This class should only be used if the other SortField
  /// types (SCORE, DOC, STRING, INT, FLOAT) do not provide an
  /// adequate sorting.  It maintains an internal cache of values which
  /// could be quite large.  The cache is an array of Comparable,
  /// one for each document in the index.  There is a distinct
  /// Comparable for each unique term in the field - if
  /// some documents have the same term in the field, the cache
  /// array will have entries which reference the same Comparable.
  /// 
  /// <p>Created: Apr 21, 2004 5:08:38 PM
  /// 
  /// </summary>
  /// <author>   Tim Jones
  /// </author>
  /// <version>  $Id: SortComparator.java 150541 2004-09-29 15:09:02Z goller $
  /// </version>
  /// <since>   1.4
  /// </since>
  [Serializable]
  public abstract class SortComparator : SortComparatorSource
  {
    private class AnonymousClassScoreDocComparator : ScoreDocComparator
    {
      public AnonymousClassScoreDocComparator(System.IComparable[] cachedValues, SortComparator enclosingInstance)
      {
        InitBlock(cachedValues, enclosingInstance);
      }
      private void  InitBlock(System.IComparable[] cachedValues, SortComparator enclosingInstance)
      {
        this.cachedValues = cachedValues;
        this.enclosingInstance = enclosingInstance;
      }
      private System.IComparable[] cachedValues;
      private SortComparator enclosingInstance;
      public SortComparator Enclosing_Instance
      {
        get
        {
          return enclosingInstance;
        }
        
      }
      
      public virtual int Compare(ScoreDoc i, ScoreDoc j)
      {
        return cachedValues[i.doc].CompareTo(cachedValues[j.doc]);
      }
      
      public virtual System.IComparable SortValue(ScoreDoc i)
      {
        return cachedValues[i.doc];
      }
      
      public virtual int SortType()
      {
        return SortField.CUSTOM;
      }
    }
    
    // inherit javadocs
    public virtual ScoreDocComparator NewComparator(IndexReader reader, System.String fieldname)
    {
      System.String field = String.Intern(fieldname);
      System.IComparable[] cachedValues = Lucene.Net.Search.FieldCache_Fields.DEFAULT.GetCustom(reader, field, this);
      
      return new AnonymousClassScoreDocComparator(cachedValues, this);
    }
    
    /// <summary> Returns an object which, when sorted according to natural order,
    /// will order the Term values in the correct order.
    /// <p>For example, if the Terms contained integer values, this method
    /// would return <code>new Integer(termtext)</code>.  Note that this
    /// might not always be the most efficient implementation - for this
    /// particular example, a better implementation might be to make a
    /// ScoreDocLookupComparator that uses an internal lookup table of int.
    /// </summary>
    /// <param name="termtext">The textual value of the term.
    /// </param>
    /// <returns> An object representing <code>termtext</code> that sorts according to the natural order of <code>termtext</code>.
    /// </returns>
    /// <seealso cref="Comparable">
    /// </seealso>
    /// <seealso cref="ScoreDocComparator">
    /// </seealso>
    public /*protected internal*/ abstract System.IComparable GetComparable(System.String termtext);
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.