List of usage examples for org.apache.lucene.util BytesRef bytesEquals
public boolean bytesEquals(BytesRef other)
From source file:org.pageseeder.flint.lucene.search.Terms.java
License:Apache License
/** * Loads all the fuzzy terms in the list of terms given the reader. * * @param reader Index reader to use./*from w w w .ja va 2 s . co m*/ * @param values The list of terms to load. * @param term The term to use. * * @throws IOException If an error is thrown by the fuzzy term enumeration. */ public static void fuzzy(IndexReader reader, List<String> values, Term term, int minSimilarity) throws IOException { AttributeSource atts = new AttributeSource(); Fields fields = MultiFields.getFields(reader); org.apache.lucene.index.Terms terms = fields == null ? null : fields.terms(term.field()); if (terms == null) return; FuzzyTermsEnum fuzzy = new FuzzyTermsEnum(terms, atts, term, minSimilarity, 0, false); BytesRef val; BytesRef searched = term.bytes(); while ((val = fuzzy.next()) != null) { if (!searched.bytesEquals(val)) values.add(val.utf8ToString()); } }
From source file:org.pageseeder.flint.lucene.search.Terms.java
License:Apache License
/** * Loads all the fuzzy terms in the list of terms given the reader. * * @param reader Index reader to use.//from w ww. ja va 2 s . c o m * @param bucket Where to store the terms. * @param term The term to use. * * @throws IOException If an error is thrown by the fuzzy term enumeration. */ @Beta public static void fuzzy(IndexReader reader, Bucket<Term> bucket, Term term, int minSimilarity) throws IOException { AttributeSource atts = new AttributeSource(); Fields fields = MultiFields.getFields(reader); org.apache.lucene.index.Terms terms = fields == null ? null : fields.terms(term.field()); if (terms == null) return; FuzzyTermsEnum fuzzy = new FuzzyTermsEnum(terms, atts, term, minSimilarity, 0, true); BytesRef val; BytesRef searched = term.bytes(); while ((val = fuzzy.next()) != null) { if (!searched.bytesEquals(val)) { Term t = new Term(term.field(), BytesRef.deepCopyOf(val)); bucket.add(t, reader.docFreq(t)); } } }
From source file:spimedb.SpimeDB.java
License:Apache License
private boolean deepEquals(Document a, Document b) { List<IndexableField> af = (a.getFields()); List<IndexableField> bf = (b.getFields()); int size = af.size(); if (bf.size() != size) return false; for (int i = 0; i < size; i++) { if (!af.get(i).name().equals(bf.get(i).name())) return false; IndexableField afi = af.get(i);//from w ww .j av a 2 s . co m IndexableField bfi = bf.get(i); { String asv = afi.stringValue(); String bsv = afi.stringValue(); if (asv != null && bsv != null && asv.equals(bsv)) continue; else if (asv != null ^ bsv != null) return false; //one is null the other isnt } { BytesRef ab = afi.binaryValue(); BytesRef bb = bfi.binaryValue(); if (ab != null && bb != null && ab.bytesEquals(bb)) continue; else if (ab != null ^ bb != null) return false; //one is null the other isnt } { String as = afi.toString(); String bs = bfi.toString(); if (as.equals(bs)) continue; //HACK int ai = as.indexOf('<'); as = ai != -1 ? as.substring(ai) : ""; int bi = bs.indexOf('<'); bs = bi != -1 ? bs.substring(bi) : ""; if (!as.equals(bs)) return false; } } return true; }