public QueryResultKey(Query query, List<Query> filters, Sort sort, int nc_flags) { this.query = query; this.sort = sort; this.filters = filters; this.nc_flags = nc_flags; int h = query.hashCode(); if (filters != null) h ^= filters.hashCode(); sfields = (this.sort !=null) ? this.sort.getSort() : defaultSort; for (SortField sf : sfields) { // mix the bits so that sortFields are position dependent // so that a,b won't hash to the same value as b,a h ^= (h << 8) | (h >>> 25); // reversible hash if (sf.getField() != null) h += sf.getField().hashCode(); h += sf.getType(); if (sf.getReverse()) h=~h; if (sf.getLocale()!=null) h+=sf.getLocale().hashCode(); if (sf.getFactory()!=null) h+=sf.getFactory().hashCode(); } hc = h; }
public boolean equals(Object o) { if (o==this) return true; if (!(o instanceof QueryResultKey)) return false; QueryResultKey other = (QueryResultKey)o; // fast check of the whole hash code... most hash tables will only use // some of the bits, so if this is a hash collision, it's still likely // that the full cached hash code will be different. if (this.hc != other.hc) return false; // check for the thing most likely to be different (and the fastest things) // first. if (this.sfields.length != other.sfields.length) return false; if (!this.query.equals(other.query)) return false; if (!isEqual(this.filters, other.filters)) return false; for (int i=0; i<sfields.length; i++) { SortField sf1 = this.sfields[i]; SortField sf2 = other.sfields[i]; if (sf1.getType() != sf2.getType()) return false; if (sf1.getReverse() != sf2.getReverse()) return false; if (!isEqual(sf1.getField(),sf2.getField())) return false; if (!isEqual(sf1.getLocale(), sf2.getLocale())) return false; if (!isEqual(sf1.getFactory(), sf2.getFactory())) return false; // NOTE: the factory must be identical!!! use singletons! } return true; }
/** * Creates a hit queue sorted by the given list of fields. * @param reader Index to use. * @param fields Field names, in priority order (highest priority first). Cannot be <code>null</code> or empty. * @param size The number of hits to retain. Must be greater than zero. * @throws IOException */ FieldSortedHitQueue (IndexReader reader, SortField[] fields, int size) throws IOException { final int n = fields.length; comparators = new ScoreDocComparator[n]; this.fields = new SortField[n]; for (int i=0; i<n; ++i) { 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); }
/** * Creates a hit queue sorted by the given list of fields. * @param reader Index to use. * @param fields Fieldable names, in priority order (highest priority first). Cannot be <code>null</code> or empty. * @param size The number of hits to retain. Must be greater than zero. * @throws IOException */ public FieldSortedHitQueue (IndexReader reader, SortField[] fields, int size) throws IOException { final int n = fields.length; comparators = new ScoreDocComparator[n]; this.fields = new SortField[n]; for (int i=0; i<n; ++i) { 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); }
/** * Creates a hit queue sorted by the given list of fields. * @param reader Index to use. * @param fields Fieldable names, in priority order (highest priority first). Cannot be <code>null</code> or empty. * @param size The number of hits to retain. Must be greater than zero. * @throws IOException */ public FieldSortedHitQueue (IndexReader reader, SortField[] fields, int size) throws IOException { final int n = fields.length; comparators = new ScoreDocComparator[n]; this.fields = new SortField[n]; for (int i=0; i<n; ++i) { 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); }