List of usage examples for org.apache.lucene.util BytesRef length
int length
To view the source code for org.apache.lucene.util BytesRef length.
Click Source Link
From source file:org.fastcatsearch.ir.filter.function.ExcludeFilter.java
License:Apache License
/** * ?? false .BOOSTING?? ? true .//from w ww. j a va 2 s . c o m * */ @Override public boolean filtering(RankInfo rankInfo, DataRef dataRef) throws IOException { while (dataRef.next()) { BytesRef bytesRef = dataRef.bytesRef(); for (int j = 0; j < patternCount; j++) { BytesRef patternBuf = patternList[j]; int plen = patternBuf.length; // ? ?? ? match ??. if (plen > bytesRef.length()) { continue; } if (plen > 0) { boolean isMatch = true; if (!patternBuf.bytesEquals(bytesRef, plen)) { isMatch = false; } if (isMatch) { // ? ? ? ? ? ?, // ?? ? ?. // ?? ?? ? ??. for (int bufInx = plen; bufInx < bytesRef.length(); bufInx++) { if (bytesRef.bytes[bufInx] != 0) { isMatch = false; break; } } // ? isMatch?? . if (isMatch) { // false . , boost true. if (isBoostFunction) { // boosting? ?? true return true; } else { //? false return false; } } // ? ??. // ? ??. } } } // for (int j = 0; j < patternCount; j++) { } // ? true. if (isBoostFunction) { // boost? ? . rankInfo.addScore(boostScore); if (rankInfo.isExplain()) { rankInfo.explain(fieldIndexId, boostScore, "EXCLUDE_BOOST_FILTER"); } } return true; }
From source file:org.fastcatsearch.ir.filter.function.MatchFilter.java
License:Apache License
@Override public boolean filtering(RankInfo rankInfo, DataRef dataRef) throws IOException { while (dataRef.next()) { BytesRef bytesRef = dataRef.bytesRef(); for (int j = 0; j < patternCount; j++) { BytesRef patternBuf = patternList[j]; int plen = patternBuf.length; // Match? ? ?? ? match??. ? . if (plen > bytesRef.length()) { continue; }//from w w w. j a v a2s. com if (plen > 0) { boolean isMatch = true; if (!patternBuf.bytesEquals(bytesRef, plen)) { isMatch = false; } // // prefix ??. // if (isMatch) { // ? ? ? ? ? ?, // ?? ? ?. // ?? ?? ? ??. for (int bufInx = plen; bufInx < bytesRef.length(); bufInx++) { if (bytesRef.bytes[bufInx] != 0) { isMatch = false; break; } } // ? isMatch?? . if (isMatch) { if (isBoostFunction) { // boost? ? . rankInfo.addScore(boostScore); if (rankInfo.isExplain()) { rankInfo.explain(fieldIndexId, boostScore, "MATCH_BOOST_FILTER"); } } return true; } // ? ??. // ? ??. } } } // for (int j = 0; j < patternCount; j++) { } return isBoostFunction; }
From source file:org.fastcatsearch.ir.filter.function.PrefixFilter.java
License:Apache License
@Override public boolean filtering(RankInfo rankInfo, DataRef dataRef) throws IOException { while (dataRef.next()) { BytesRef bytesRef = dataRef.bytesRef(); for (int j = 0; j < patternCount; j++) { BytesRef patternBuf = patternList[j]; int plen = patternBuf.length; // Prefix?? ? ?? ? match??. ? . if (plen > bytesRef.length()) { continue; }/*from w w w .j a v a 2 s . c om*/ if (plen > 0) { if (patternBuf.bytesEquals(bytesRef, plen)) { if (isBoostFunction) { // boost? ? . rankInfo.addScore(boostScore); if (rankInfo.isExplain()) { rankInfo.explain(fieldIndexId, boostScore, "PREFIX_BOOST_FILTER"); } } return true; } // ? ??. // ? ??. } } // for (int j = 0; j < patternCount; j++) { } return isBoostFunction; }
From source file:org.fastcatsearch.ir.filter.function.SectionFilter.java
License:Apache License
@Override public boolean filtering(RankInfo rankInfo, DataRef dataRef) throws IOException { while (dataRef.next()) { BytesRef bytesRef = dataRef.bytesRef(); for (int j = 0; j < patternCount; j++) { BytesRef patternBuf1 = patternList[j]; BytesRef patternBuf2 = endPatternList[j]; //??? ? ?? ??? ? ?? . //? : // ? MSB ? ? ? . ? ? ? (?? ? ? ? ? ) // 1. ? ? : ? ? //? : // 1. ? ? : ? ? // 2. ? : ? ?, ? ? . ? ? ? if (fieldSetting.isNumericField()) { if ((patternBuf1 == null || compareNumeric(bytesRef, bytesRef.length(), patternBuf1, patternBuf1.length()) >= 0) && (patternBuf2 == null || compareNumeric(bytesRef, bytesRef.length(), patternBuf2, patternBuf2.length()) <= 0)) { if (isBoostFunction) { //boost? ? . rankInfo.addScore(boostScore); if (rankInfo.isExplain()) { rankInfo.explain(fieldIndexId, boostScore, "SECTION_BOOST_FILTER"); }/*w w w . jav a 2 s . c o m*/ } return true; } } else { if (compareString(bytesRef, bytesRef.length(), patternBuf1, patternBuf1.length()) >= 0 && compareString(bytesRef, bytesRef.length(), patternBuf2, patternBuf2.length()) <= 0 ) { if (isBoostFunction) { //boost? ? . rankInfo.addScore(boostScore); if (rankInfo.isExplain()) { rankInfo.explain(fieldIndexId, boostScore, "SECTION_BOOST_FILTER"); } } return true; } } } //for } return isBoostFunction; }
From source file:org.fastcatsearch.ir.filter.function.SuffixFilter.java
License:Apache License
@Override public boolean filtering(RankInfo rankInfo, DataRef dataRef) throws IOException { while (dataRef.next()) { BytesRef bytesRef = dataRef.bytesRef(); for (int j = 0; j < patternCount; j++) { BytesRef patternBuf = patternList[j]; int plen = patternBuf.length; //Prefix?? ? ?? ? match??. ? . if (plen > bytesRef.length()) { continue; }//from w ww. ja v a 2 s . c om if (plen > 0) { if (byteEqualsReverse(patternBuf, bytesRef)) { if (isBoostFunction) { //boost? ? . rankInfo.addScore(boostScore); if (rankInfo.isExplain()) { rankInfo.explain(fieldIndexId, boostScore, "SUFFIX_BOOST_FILTER"); } } return true; } // ? ??. //? ??. } } // for (int j = 0; j < patternCount; j++) { } return isBoostFunction; }
From source file:org.fastcatsearch.ir.filter.function.SuffixFilter.java
License:Apache License
private boolean byteEqualsReverse(BytesRef patternBuf, BytesRef dataBuf) { //) fieldSize 5? dataBuf? ABC ABC00 . //0? ?? ?. ?. int dataLastOffset = 0; for (dataLastOffset = dataBuf.length() - 1; dataLastOffset >= 0; dataLastOffset--) { if (dataBuf.get(dataLastOffset) != 0) { break; }//from www. ja v a 2 s .c o m } if (dataLastOffset < 0) { // ??. return false; } //? . int offset = patternBuf.length() - 1; for (int k = 0; k < patternBuf.length(); k++) { if (patternBuf.get(offset - k) != dataBuf.get(dataLastOffset - k)) { return false; } } return true; }
From source file:org.fastcatsearch.ir.io.MappedFileBaseByteHashSet.java
License:Apache License
public boolean add(BytesRef key) { try {// ww w . j a v a 2 s .c o m int hashValue = (Math.abs(key.hashCode()) % (bucketSize - 1)) + 1; //0? . int prev = 0; int id = readBucket(hashValue); logger.trace("------------------"); logger.trace("key[{}] hash[{}] bucket[{}]", key, hashValue, id); while (id > 0) { if (isTheSame(key, id)) { //?? false. logger.trace("Dup entry!"); return false; } prev = id; id = readNextIndex(id); } int idx = newIndex(); logger.trace("Index[{}] {}", idx, key); int offset = newKeyPos(idx); buf.position(offset); logger.trace("write {} at {}", key, offset); for (int i = 0; i < key.length(); i++) { buf.put(key.get(i)); } if (prev > 0) { writeNextIndex(prev, idx); logger.trace("writeNext prev[{}], id[{}]", prev, idx); } else { writeBucket(hashValue, idx); logger.trace("writeBucket hash[{}], id[{}]", hashValue, idx); } return true; } catch (Exception e) { logger.error("", e); return false; } }