Beispiel #1
0
 private QueryPhraseMap GetOrNewMap(HashMap<String, QueryPhraseMap> subMap, String term)
 {
     QueryPhraseMap map = subMap.Get(term);
     if (map == null)
     {
         map = new QueryPhraseMap(fieldQuery);
         subMap.Put(term,map);
     }
     return map;
 }
Beispiel #2
0
        public void TestQueryPhraseMap2PhrasesFields()
        {
            BooleanQuery query = new BooleanQuery();

            query.Add(Pq(F1, "a", "b"), Occur.SHOULD);
            query.Add(Pq(2F, F2, "c", "d"), Occur.SHOULD);

            // phraseHighlight = true, fieldMatch = true
            FieldQuery fq = new FieldQuery(query, true, true);
            HashMap <String, QueryPhraseMap> map = fq.rootMaps;

            Assert.AreEqual(2, map.Count);
            Assert.Null(map.Get(null));

            // "a b"
            Assert.NotNull(map.Get(F1));
            QueryPhraseMap qpm = map.Get(F1);

            Assert.AreEqual(1, qpm.subMap.Count);
            Assert.NotNull(qpm.subMap.Get("a"));
            QueryPhraseMap qpm2 = qpm.subMap.Get("a");

            Assert.IsFalse(qpm2.terminal);
            Assert.AreEqual(1, qpm2.subMap.Count);
            Assert.NotNull(qpm2.subMap.Get("b"));
            QueryPhraseMap qpm3 = qpm2.subMap.Get("b");

            Assert.IsTrue(qpm3.terminal);
            Assert.AreEqual(1F, qpm3.boost);

            // "c d"^2
            Assert.NotNull(map.Get(F2));
            qpm = map.Get(F2);
            Assert.AreEqual(1, qpm.subMap.Count);
            Assert.NotNull(qpm.subMap.Get("c"));
            qpm2 = qpm.subMap.Get("c");
            Assert.IsFalse(qpm2.terminal);
            Assert.AreEqual(1, qpm2.subMap.Count);
            Assert.NotNull(qpm2.subMap.Get("d"));
            qpm3 = qpm2.subMap.Get("d");
            Assert.IsTrue(qpm3.terminal);
            Assert.AreEqual(2F, qpm3.boost);

            // phraseHighlight = true, fieldMatch = false
            fq  = new FieldQuery(query, true, false);
            map = fq.rootMaps;
            Assert.AreEqual(1, map.Count);
            Assert.Null(map.Get(F1));
            Assert.Null(map.Get(F2));
            Assert.NotNull(map.Get(null));
            qpm = map.Get(null);
            Assert.AreEqual(2, qpm.subMap.Count);

            // "a b"
            Assert.NotNull(qpm.subMap.Get("a"));
            qpm2 = qpm.subMap.Get("a");
            Assert.IsFalse(qpm2.terminal);
            Assert.AreEqual(1, qpm2.subMap.Count);
            Assert.NotNull(qpm2.subMap.Get("b"));
            qpm3 = qpm2.subMap.Get("b");
            Assert.IsTrue(qpm3.terminal);
            Assert.AreEqual(1F, qpm3.boost);

            // "c d"^2
            Assert.NotNull(qpm.subMap.Get("c"));
            qpm2 = qpm.subMap.Get("c");
            Assert.IsFalse(qpm2.terminal);
            Assert.AreEqual(1, qpm2.subMap.Count);
            Assert.NotNull(qpm2.subMap.Get("d"));
            qpm3 = qpm2.subMap.Get("d");
            Assert.IsTrue(qpm3.terminal);
            Assert.AreEqual(2F, qpm3.boost);
        }
Beispiel #3
0
        public void TestQueryPhraseMap1Phrase()
        {
            Query query = PqF("a", "b");

            // phraseHighlight = true, fieldMatch = true
            FieldQuery fq = new FieldQuery(query, true, true);
            HashMap <String, QueryPhraseMap> map = fq.rootMaps;

            Assert.AreEqual(1, map.Count);
            Assert.Null(map.Get(null));
            Assert.NotNull(map.Get(F));
            QueryPhraseMap qpm = map.Get(F);

            Assert.AreEqual(1, qpm.subMap.Count);
            Assert.NotNull(qpm.subMap.Get("a"));
            QueryPhraseMap qpm2 = qpm.subMap.Get("a");

            Assert.IsFalse(qpm2.terminal);
            Assert.AreEqual(1, qpm2.subMap.Count);
            Assert.NotNull(qpm2.subMap.Get("b"));
            QueryPhraseMap qpm3 = qpm2.subMap.Get("b");

            Assert.IsTrue(qpm3.terminal);
            Assert.AreEqual(1F, qpm3.boost);

            // phraseHighlight = true, fieldMatch = false
            fq  = new FieldQuery(query, true, false);
            map = fq.rootMaps;
            Assert.AreEqual(1, map.Count);
            Assert.Null(map.Get(F));
            Assert.NotNull(map.Get(null));
            qpm = map.Get(null);
            Assert.AreEqual(1, qpm.subMap.Count);
            Assert.NotNull(qpm.subMap.Get("a"));
            qpm2 = qpm.subMap.Get("a");
            Assert.IsFalse(qpm2.terminal);
            Assert.AreEqual(1, qpm2.subMap.Count);
            Assert.NotNull(qpm2.subMap.Get("b"));
            qpm3 = qpm2.subMap.Get("b");
            Assert.IsTrue(qpm3.terminal);
            Assert.AreEqual(1F, qpm3.boost);

            // phraseHighlight = false, fieldMatch = true
            fq  = new FieldQuery(query, false, true);
            map = fq.rootMaps;
            Assert.AreEqual(1, map.Count);
            Assert.Null(map.Get(null));
            Assert.NotNull(map.Get(F));
            qpm = map.Get(F);
            Assert.AreEqual(2, qpm.subMap.Count);
            Assert.NotNull(qpm.subMap.Get("a"));
            qpm2 = qpm.subMap.Get("a");
            Assert.IsTrue(qpm2.terminal);
            Assert.AreEqual(1F, qpm2.boost);
            Assert.AreEqual(1, qpm2.subMap.Count);
            Assert.NotNull(qpm2.subMap.Get("b"));
            qpm3 = qpm2.subMap.Get("b");
            Assert.IsTrue(qpm3.terminal);
            Assert.AreEqual(1F, qpm3.boost);

            Assert.NotNull(qpm.subMap.Get("b"));
            qpm2 = qpm.subMap.Get("b");
            Assert.IsTrue(qpm2.terminal);
            Assert.AreEqual(1F, qpm2.boost);

            // phraseHighlight = false, fieldMatch = false
            fq  = new FieldQuery(query, false, false);
            map = fq.rootMaps;
            Assert.AreEqual(1, map.Count);
            Assert.Null(map.Get(F));
            Assert.NotNull(map.Get(null));
            qpm = map.Get(null);
            Assert.AreEqual(2, qpm.subMap.Count);
            Assert.NotNull(qpm.subMap.Get("a"));
            qpm2 = qpm.subMap.Get("a");
            Assert.IsTrue(qpm2.terminal);
            Assert.AreEqual(1F, qpm2.boost);
            Assert.AreEqual(1, qpm2.subMap.Count);
            Assert.NotNull(qpm2.subMap.Get("b"));
            qpm3 = qpm2.subMap.Get("b");
            Assert.IsTrue(qpm3.terminal);
            Assert.AreEqual(1F, qpm3.boost);

            Assert.NotNull(qpm.subMap.Get("b"));
            qpm2 = qpm.subMap.Get("b");
            Assert.IsTrue(qpm2.terminal);
            Assert.AreEqual(1F, qpm2.boost);

            // boost != 1
            query = PqF(2, "a", "b");
            // phraseHighlight = false, fieldMatch = false
            fq   = new FieldQuery(query, false, false);
            map  = fq.rootMaps;
            qpm  = map.Get(null);
            qpm2 = qpm.subMap.Get("a");
            Assert.AreEqual(2F, qpm2.boost);
            qpm3 = qpm2.subMap.Get("b");
            Assert.AreEqual(2F, qpm3.boost);
            qpm2 = qpm.subMap.Get("b");
            Assert.AreEqual(2F, qpm2.boost);
        }
Beispiel #4
0
 public QueryPhraseMap GetTermMap(String term)
 {
     return(subMap.Get(term));
 }