public void TestSearchPhraseSlop() { // "a b c"~0 Query query = pqF("a", "b", "c"); // phraseHighlight = true, fieldMatch = true FieldQuery fq = new FieldQuery(query, true, true); // "a b c" w/ position-gap = 2 List <TermInfo> phraseCandidate = new List <TermInfo>(); phraseCandidate.Add(new TermInfo("a", 0, 1, 0, 1)); phraseCandidate.Add(new TermInfo("b", 2, 3, 2, 1)); phraseCandidate.Add(new TermInfo("c", 4, 5, 4, 1)); assertNull(fq.SearchPhrase(F, phraseCandidate)); // "a b c"~1 query = pqF(1F, 1, "a", "b", "c"); // phraseHighlight = true, fieldMatch = true fq = new FieldQuery(query, true, true); // "a b c" w/ position-gap = 2 assertNotNull(fq.SearchPhrase(F, phraseCandidate)); // "a b c" w/ position-gap = 3 phraseCandidate.Clear(); phraseCandidate.Add(new TermInfo("a", 0, 1, 0, 1)); phraseCandidate.Add(new TermInfo("b", 2, 3, 3, 1)); phraseCandidate.Add(new TermInfo("c", 4, 5, 6, 1)); assertNull(fq.SearchPhrase(F, phraseCandidate)); }
public void TestSearchPhrase() { Query query = pqF("a", "b", "c"); // phraseHighlight = true, fieldMatch = true FieldQuery fq = new FieldQuery(query, true, true); // "a" List <TermInfo> phraseCandidate = new List <TermInfo>(); phraseCandidate.Add(new TermInfo("a", 0, 1, 0, 1)); assertNull(fq.SearchPhrase(F, phraseCandidate)); // "a b" phraseCandidate.Add(new TermInfo("b", 2, 3, 1, 1)); assertNull(fq.SearchPhrase(F, phraseCandidate)); // "a b c" phraseCandidate.Add(new TermInfo("c", 4, 5, 2, 1)); assertNotNull(fq.SearchPhrase(F, phraseCandidate)); assertNull(fq.SearchPhrase("x", phraseCandidate)); // phraseHighlight = true, fieldMatch = false fq = new FieldQuery(query, true, false); // "a b c" assertNotNull(fq.SearchPhrase(F, phraseCandidate)); assertNotNull(fq.SearchPhrase("x", phraseCandidate)); // phraseHighlight = false, fieldMatch = true fq = new FieldQuery(query, false, true); // "a" phraseCandidate.Clear(); phraseCandidate.Add(new TermInfo("a", 0, 1, 0, 1)); assertNotNull(fq.SearchPhrase(F, phraseCandidate)); // "a b" phraseCandidate.Add(new TermInfo("b", 2, 3, 1, 1)); assertNull(fq.SearchPhrase(F, phraseCandidate)); // "a b c" phraseCandidate.Add(new TermInfo("c", 4, 5, 2, 1)); assertNotNull(fq.SearchPhrase(F, phraseCandidate)); assertNull(fq.SearchPhrase("x", phraseCandidate)); }
private void defgMultiTermQueryTest(Query query) { FieldQuery fq = new FieldQuery(query, reader, true, true); QueryPhraseMap qpm = fq.GetFieldTermMap(F, "defg"); assertNotNull(qpm); assertNull(fq.GetFieldTermMap(F, "dog")); List <TermInfo> phraseCandidate = new List <TermInfo>(); phraseCandidate.Add(new TermInfo("defg", 0, 12, 0, 1)); assertNotNull(fq.SearchPhrase(F, phraseCandidate)); }
/// <summary> /// a constructor. /// </summary> /// <param name="fieldTermStack"><see cref="FieldTermStack"/> object</param> /// <param name="fieldQuery"><see cref="FieldQuery"/> object</param> /// <param name="phraseLimit">maximum size of phraseList</param> public FieldPhraseList(FieldTermStack fieldTermStack, FieldQuery fieldQuery, int phraseLimit) { string field = fieldTermStack.FieldName; List <TermInfo> phraseCandidate = new List <TermInfo>(); QueryPhraseMap currMap = null; QueryPhraseMap nextMap = null; while (!fieldTermStack.IsEmpty && (phraseList.Count < phraseLimit)) { phraseCandidate.Clear(); TermInfo ti = null; TermInfo first = null; first = ti = fieldTermStack.Pop(); currMap = fieldQuery.GetFieldTermMap(field, ti.Text); while (currMap == null && ti.Next != first) { ti = ti.Next; currMap = fieldQuery.GetFieldTermMap(field, ti.Text); } // if not found, discard top TermInfo from stack, then try next element if (currMap == null) { continue; } // if found, search the longest phrase phraseCandidate.Add(ti); while (true) { first = ti = fieldTermStack.Pop(); nextMap = null; if (ti != null) { nextMap = currMap.GetTermMap(ti.Text); while (nextMap == null && ti.Next != first) { ti = ti.Next; nextMap = currMap.GetTermMap(ti.Text); } } if (ti == null || nextMap == null) { if (ti != null) { fieldTermStack.Push(ti); } if (currMap.IsValidTermOrPhrase(phraseCandidate)) { AddIfNoOverlap(new WeightedPhraseInfo(phraseCandidate, currMap.Boost, currMap.TermOrPhraseNumber)); } else { while (phraseCandidate.Count > 1) { //fieldTermStack.Push(phraseCandidate.Last.Value); //phraseCandidate.RemoveLast(); TermInfo last = phraseCandidate[phraseCandidate.Count - 1]; phraseCandidate.Remove(last); fieldTermStack.Push(last); currMap = fieldQuery.SearchPhrase(field, phraseCandidate); if (currMap != null) { AddIfNoOverlap(new WeightedPhraseInfo(phraseCandidate, currMap.Boost, currMap.TermOrPhraseNumber)); break; } } } break; } else { phraseCandidate.Add(ti); currMap = nextMap; } } } }