SloppyPhraseMatcher(PhraseQuery.PostingsAndFreq[] postings, int slop, float matchCost, boolean captureLeadMatch) { super(approximation(postings), matchCost); this.slop = slop; this.numPostings = postings.length; this.captureLeadMatch = captureLeadMatch; pq = new PhraseQueue(postings.length); phrasePositions = new PhrasePositions[postings.length]; for (int i = 0; i < postings.length; ++i) { phrasePositions[i] = new PhrasePositions(postings[i].postings, postings[i].position, i, postings[i].terms); } }
return false; PhrasePositions pp = pq.pop(); assert pp != null; // if the pq is not full, then positioned == false captureLead(pp); matchLength = end - pp.position; int next = pq.top().position; while (advancePP(pp)) { if (hasRpts && !advanceRpts(pp)) { pq.add(pp); if (matchLength <= slop) { return true; pp = pq.pop(); next = pq.top().position; assert pp != null; // if the pq is not full, then positioned == false matchLength = end - pp.position;
protected final float phraseFreq() throws IOException { pq.clear(); int end = 0; for (PhrasePositions pp = first; pp != null; pp = pp.next) { if (pp.position > end) end = pp.position; pq.put(pp); // build pq from list boolean done = false; do { PhrasePositions pp = (PhrasePositions) pq.pop(); int start = pp.position; int next = ((PhrasePositions) pq.top()).position; for (int pos = start; pos <= next; pos = pp.position) { pq.put(pp); // restore pq } while (!done);
private PhrasePositions flip(PhrasePositions pp, PhrasePositions pp2) { int n=0; PhrasePositions pp3; //pop until finding pp2 while ((pp3=(PhrasePositions)pq.pop()) != pp2) { tmpPos[n++] = pp3; } //insert back all but pp2 for (n--; n>=0; n--) { pq.insert(tmpPos[n]); } //insert pp back pq.put(pp); return pp2; }
pq.clear(); for (PhrasePositions pp = first; pp != null; pp = pp.next) { pp.firstPosition(); if (pp.position > end) end = pp.position; pq.put(pp); // build pq from list pq.clear(); for (PhrasePositions pp = first; pp != null; pp = pp.next) { if (pp.position > end) end = pp.position; pq.put(pp); // build pq from list tmpPos = new PhrasePositions[pq.size()];
PhraseQueue(int size) { initialize(size); }
protected final float phraseFreq() throws IOException { // sort list with pq for (PhrasePositions pp = first; pp != null; pp = pp.next) { pp.firstPosition(); pq.put(pp); // build pq from list } pqToList(); // rebuild list from pq int freq = 0; do { // find position w/ all terms while (first.position < last.position) { // scan forward in first do { if (!first.nextPosition()) return (float)freq; } while (first.position < last.position); firstToLast(); } freq++; // all equal: a match } while (last.nextPosition()); return (float)freq; } }
private PhrasePositions flip(PhrasePositions pp, PhrasePositions pp2) { int n=0; PhrasePositions pp3; //pop until finding pp2 while ((pp3=(PhrasePositions)pq.pop()) != pp2) { tmpPos[n++] = pp3; } //insert back all but pp2 for (n--; n>=0; n--) { pq.insert(tmpPos[n]); } //insert pp back pq.put(pp); return pp2; }
pq.clear(); for (PhrasePositions pp = first; pp != null; pp = pp.next) { pp.firstPosition(); if (pp.position > end) end = pp.position; pq.put(pp); // build pq from list pq.clear(); for (PhrasePositions pp = first; pp != null; pp = pp.next) { if (pp.position > end) end = pp.position; pq.put(pp); // build pq from list tmpPos = new PhrasePositions[pq.size()];
PhraseQueue(int size) { initialize(size); }
return false; PhrasePositions pp = pq.pop(); assert pp != null; // if the pq is not full, then positioned == false captureLead(pp); matchLength = end - pp.position; int next = pq.top().position; while (advancePP(pp)) { if (hasRpts && !advanceRpts(pp)) { pq.add(pp); if (matchLength <= slop) { return true; pp = pq.pop(); next = pq.top().position; assert pp != null; // if the pq is not full, then positioned == false matchLength = end - pp.position;