Java tutorial
/* * Copyright 2013 Websquared, Inc. * * 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. */ package org.fastcatsearch.ir.search; import org.apache.lucene.util.BytesRef; import org.fastcatsearch.ir.io.FixedMaxPriorityQueue; /** * ? ? ?. * docNo ?? ?. * ? heap? pop ??. * @author swsong * */ public class DefaultRanker extends FixedMaxPriorityQueue<HitElement> { public DefaultRanker(int maxSize) { super(maxSize); } @Override public boolean push(HitElement e) { if (e.getBundleKey() != null) { BytesRef bundleKey = e.getBundleKey(); for (int i = 1; i <= size; i++) { if (bundleKey.equals(((HitElement) heap[i]).getBundleKey())) { /* * ?? bundle ? ?? ? ? ?. */ if (compare(e, (HitElement) heap[i]) < 0) { // ? . // . replaceEl(i, e); // break; return true; } // logger.debug("Do no push > {}", e.docNo()); return false; } } } //bundle? ?? bundle? push. return super.push(e); } @Override protected int compare(HitElement one, HitElement two) { return one.compareTo(two); // // . // // . // if(one.segmentSequence() != two.segmentSequence()){ // return two.segmentSequence() - one.segmentSequence(); // } // return two.docNo() - one.docNo() ; } }