Shinsuke Sugaya 8 лет назад
Родитель
Сommit
aed320e25d

+ 136 - 40
src/main/java/org/codelibs/fess/helper/QueryHelper.java

@@ -93,6 +93,8 @@ public class QueryHelper {
 
     protected Set<String> highlightFieldSet = new HashSet<>();
 
+    protected Set<String> notAnalyzedFieldSet;
+
     protected String[] responseFields;
 
     protected String[] cacheResponseFields;
@@ -136,63 +138,146 @@ public class QueryHelper {
     @PostConstruct
     public void init() {
         if (responseFields == null) {
-            responseFields =
-                    new String[] { SCORE_FIELD, fessConfig.getIndexFieldId(), fessConfig.getIndexFieldDocId(),
-                            fessConfig.getIndexFieldBoost(), fessConfig.getIndexFieldContentLength(), fessConfig.getIndexFieldHost(),
-                            fessConfig.getIndexFieldSite(), fessConfig.getIndexFieldLastModified(), fessConfig.getIndexFieldTimestamp(),
-                            fessConfig.getIndexFieldMimetype(), fessConfig.getIndexFieldFiletype(), fessConfig.getIndexFieldCreated(),
-                            fessConfig.getIndexFieldTitle(), fessConfig.getIndexFieldDigest(), fessConfig.getIndexFieldUrl(),
-                            fessConfig.getIndexFieldClickCount(), fessConfig.getIndexFieldFavoriteCount(),
-                            fessConfig.getIndexFieldConfigId(), fessConfig.getIndexFieldLang(), fessConfig.getIndexFieldHasCache() };
+            responseFields = new String[] { SCORE_FIELD, //
+                    fessConfig.getIndexFieldId(), //
+                    fessConfig.getIndexFieldDocId(), //
+                    fessConfig.getIndexFieldBoost(), //
+                    fessConfig.getIndexFieldContentLength(), //
+                    fessConfig.getIndexFieldHost(), //
+                    fessConfig.getIndexFieldSite(), //
+                    fessConfig.getIndexFieldLastModified(), //
+                    fessConfig.getIndexFieldTimestamp(), //
+                    fessConfig.getIndexFieldMimetype(), //
+                    fessConfig.getIndexFieldFiletype(), //
+                    fessConfig.getIndexFieldCreated(), //
+                    fessConfig.getIndexFieldTitle(), //
+                    fessConfig.getIndexFieldDigest(), //
+                    fessConfig.getIndexFieldUrl(), //
+                    fessConfig.getIndexFieldClickCount(), //
+                    fessConfig.getIndexFieldFavoriteCount(), //
+                    fessConfig.getIndexFieldConfigId(), //
+                    fessConfig.getIndexFieldLang(), //
+                    fessConfig.getIndexFieldHasCache() };
         }
         if (cacheResponseFields == null) {
-            cacheResponseFields =
-                    new String[] { SCORE_FIELD, fessConfig.getIndexFieldId(), fessConfig.getIndexFieldDocId(),
-                            fessConfig.getIndexFieldBoost(), fessConfig.getIndexFieldContentLength(), fessConfig.getIndexFieldHost(),
-                            fessConfig.getIndexFieldSite(), fessConfig.getIndexFieldLastModified(), fessConfig.getIndexFieldTimestamp(),
-                            fessConfig.getIndexFieldMimetype(), fessConfig.getIndexFieldFiletype(), fessConfig.getIndexFieldCreated(),
-                            fessConfig.getIndexFieldTitle(), fessConfig.getIndexFieldDigest(), fessConfig.getIndexFieldUrl(),
-                            fessConfig.getIndexFieldClickCount(), fessConfig.getIndexFieldFavoriteCount(),
-                            fessConfig.getIndexFieldConfigId(), fessConfig.getIndexFieldLang(), fessConfig.getIndexFieldCache() };
+            cacheResponseFields = new String[] { SCORE_FIELD, //
+                    fessConfig.getIndexFieldId(), //
+                    fessConfig.getIndexFieldDocId(), //
+                    fessConfig.getIndexFieldBoost(), //
+                    fessConfig.getIndexFieldContentLength(), //
+                    fessConfig.getIndexFieldHost(), //
+                    fessConfig.getIndexFieldSite(), //
+                    fessConfig.getIndexFieldLastModified(), //
+                    fessConfig.getIndexFieldTimestamp(), //
+                    fessConfig.getIndexFieldMimetype(), //
+                    fessConfig.getIndexFieldFiletype(), //
+                    fessConfig.getIndexFieldCreated(), //
+                    fessConfig.getIndexFieldTitle(), //
+                    fessConfig.getIndexFieldDigest(), //
+                    fessConfig.getIndexFieldUrl(), //
+                    fessConfig.getIndexFieldClickCount(), //
+                    fessConfig.getIndexFieldFavoriteCount(), //
+                    fessConfig.getIndexFieldConfigId(), //
+                    fessConfig.getIndexFieldLang(), //
+                    fessConfig.getIndexFieldCache() };
         }
         if (responseDocValuesFields == null) {
-            responseDocValuesFields = new String[] { fessConfig.getIndexFieldClickCount(), fessConfig.getIndexFieldFavoriteCount() };
+            responseDocValuesFields = new String[] {//
+                    fessConfig.getIndexFieldClickCount(), //
+                            fessConfig.getIndexFieldFavoriteCount() };
         }
         if (highlightedFields == null) {
             highlightedFields = new String[] { fessConfig.getIndexFieldContent() };
         }
         if (searchFields == null) {
-            searchFields =
-                    new String[] { INURL_FIELD, fessConfig.getIndexFieldUrl(), fessConfig.getIndexFieldDocId(),
-                            fessConfig.getIndexFieldHost(), fessConfig.getIndexFieldTitle(), fessConfig.getIndexFieldContent(),
-                            fessConfig.getIndexFieldContentLength(), fessConfig.getIndexFieldLastModified(),
-                            fessConfig.getIndexFieldTimestamp(), fessConfig.getIndexFieldMimetype(), fessConfig.getIndexFieldFiletype(),
-                            fessConfig.getIndexFieldLabel(), fessConfig.getIndexFieldSegment(), fessConfig.getIndexFieldClickCount(),
-                            fessConfig.getIndexFieldFavoriteCount(), fessConfig.getIndexFieldLang() };
+            searchFields = new String[] { INURL_FIELD, //
+                    fessConfig.getIndexFieldUrl(), //
+                    fessConfig.getIndexFieldDocId(), //
+                    fessConfig.getIndexFieldHost(), //
+                    fessConfig.getIndexFieldTitle(), //
+                    fessConfig.getIndexFieldContent(), //
+                    fessConfig.getIndexFieldContentLength(), //
+                    fessConfig.getIndexFieldLastModified(), //
+                    fessConfig.getIndexFieldTimestamp(), //
+                    fessConfig.getIndexFieldMimetype(), //
+                    fessConfig.getIndexFieldFiletype(), //
+                    fessConfig.getIndexFieldLabel(), //
+                    fessConfig.getIndexFieldSegment(), //
+                    fessConfig.getIndexFieldClickCount(), //
+                    fessConfig.getIndexFieldFavoriteCount(), //
+                    fessConfig.getIndexFieldLang() };
         }
         if (facetFields == null) {
-            facetFields =
-                    new String[] { fessConfig.getIndexFieldUrl(), fessConfig.getIndexFieldHost(), fessConfig.getIndexFieldTitle(),
-                            fessConfig.getIndexFieldContent(), fessConfig.getIndexFieldContentLength(),
-                            fessConfig.getIndexFieldLastModified(), fessConfig.getIndexFieldTimestamp(),
-                            fessConfig.getIndexFieldMimetype(), fessConfig.getIndexFieldFiletype(), fessConfig.getIndexFieldLabel(),
+            facetFields = new String[] {//
+                    fessConfig.getIndexFieldUrl(), //
+                            fessConfig.getIndexFieldHost(), //
+                            fessConfig.getIndexFieldTitle(), //
+                            fessConfig.getIndexFieldContent(), //
+                            fessConfig.getIndexFieldContentLength(), //
+                            fessConfig.getIndexFieldLastModified(), //
+                            fessConfig.getIndexFieldTimestamp(), //
+                            fessConfig.getIndexFieldMimetype(), //
+                            fessConfig.getIndexFieldFiletype(), //
+                            fessConfig.getIndexFieldLabel(), //
                             fessConfig.getIndexFieldSegment() };
         }
         if (supportedSortFields == null) {
-            supportedSortFields =
-                    new String[] { SCORE_SORT_VALUE, fessConfig.getIndexFieldCreated(), fessConfig.getIndexFieldContentLength(),
-                            fessConfig.getIndexFieldLastModified(), fessConfig.getIndexFieldTimestamp(),
-                            fessConfig.getIndexFieldClickCount(), fessConfig.getIndexFieldFavoriteCount() };
+            supportedSortFields = new String[] { SCORE_SORT_VALUE, //
+                    fessConfig.getIndexFieldCreated(), //
+                    fessConfig.getIndexFieldContentLength(), //
+                    fessConfig.getIndexFieldLastModified(), //
+                    fessConfig.getIndexFieldTimestamp(), //
+                    fessConfig.getIndexFieldClickCount(), //
+                    fessConfig.getIndexFieldFavoriteCount() };
         }
         if (apiResponseFieldSet == null) {
-            setApiResponseFields(new String[] { fessConfig.getResponseFieldContentDescription(), fessConfig.getResponseFieldContentTitle(),
-                    fessConfig.getResponseFieldSitePath(), fessConfig.getResponseFieldUrlLink(), fessConfig.getIndexFieldId(),
-                    fessConfig.getIndexFieldDocId(), fessConfig.getIndexFieldBoost(), fessConfig.getIndexFieldContentLength(),
-                    fessConfig.getIndexFieldHost(), fessConfig.getIndexFieldSite(), fessConfig.getIndexFieldLastModified(),
-                    fessConfig.getIndexFieldTimestamp(), fessConfig.getIndexFieldMimetype(), fessConfig.getIndexFieldFiletype(),
-                    fessConfig.getIndexFieldCreated(), fessConfig.getIndexFieldTitle(), fessConfig.getIndexFieldDigest(),
+            setApiResponseFields(new String[] {//
+            fessConfig.getResponseFieldContentDescription(), //
+                    fessConfig.getResponseFieldContentTitle(), //
+                    fessConfig.getResponseFieldSitePath(), //
+                    fessConfig.getResponseFieldUrlLink(), //
+                    fessConfig.getIndexFieldId(), //
+                    fessConfig.getIndexFieldDocId(), //
+                    fessConfig.getIndexFieldBoost(), //
+                    fessConfig.getIndexFieldContentLength(), //
+                    fessConfig.getIndexFieldHost(), //
+                    fessConfig.getIndexFieldSite(), //
+                    fessConfig.getIndexFieldLastModified(), //
+                    fessConfig.getIndexFieldTimestamp(), //
+                    fessConfig.getIndexFieldMimetype(), //
+                    fessConfig.getIndexFieldFiletype(), //
+                    fessConfig.getIndexFieldCreated(), //
+                    fessConfig.getIndexFieldTitle(), //
+                    fessConfig.getIndexFieldDigest(), //
                     fessConfig.getIndexFieldUrl() });
         }
+        if (notAnalyzedFieldSet == null) {
+            setNotAnalyzedFields(new String[] {//
+            fessConfig.getIndexFieldAnchor(), //
+                    fessConfig.getIndexFieldBoost(), //
+                    fessConfig.getIndexFieldClickCount(), //
+                    fessConfig.getIndexFieldConfigId(), //
+                    fessConfig.getIndexFieldContentLength(), //
+                    fessConfig.getIndexFieldCreated(), //
+                    fessConfig.getIndexFieldDocId(), //
+                    fessConfig.getIndexFieldExpires(), //
+                    fessConfig.getIndexFieldFavoriteCount(), //
+                    fessConfig.getIndexFieldFiletype(), //
+                    fessConfig.getIndexFieldHasCache(), //
+                    fessConfig.getIndexFieldHost(), //
+                    fessConfig.getIndexFieldId(), //
+                    fessConfig.getIndexFieldLabel(), //
+                    fessConfig.getIndexFieldLang(), //
+                    fessConfig.getIndexFieldLastModified(), //
+                    fessConfig.getIndexFieldMimetype(), //
+                    fessConfig.getIndexFieldParentId(), //
+                    fessConfig.getIndexFieldRole(), //
+                    fessConfig.getIndexFieldSegment(), //
+                    fessConfig.getIndexFieldSite(), //
+                    fessConfig.getIndexFieldTimestamp(), //
+                    fessConfig.getIndexFieldUrl(), //
+                    fessConfig.getIndexFieldVersion() });
+        }
     }
 
     public QueryContext build(final String query, final Consumer<QueryContext> context) {
@@ -440,7 +525,11 @@ public class QueryHelper {
         } else if (isSearchField(field)) {
             context.addFieldLog(field, text);
             context.addHighlightedQuery(text);
-            return QueryBuilders.matchPhraseQuery(field, text).boost(boost);
+            if (notAnalyzedFieldSet.contains(field)) {
+                return QueryBuilders.termQuery(field, text).boost(boost);
+            } else {
+                return QueryBuilders.matchPhraseQuery(field, text).boost(boost);
+            }
         } else {
             final String origQuery = termQuery.toString();
             context.addFieldLog(Constants.DEFAULT_FIELD, origQuery);
@@ -540,6 +629,13 @@ public class QueryHelper {
         }
     }
 
+    public void setNotAnalyzedFields(final String[] fields) {
+        notAnalyzedFieldSet = new HashSet<>();
+        for (final String field : fields) {
+            notAnalyzedFieldSet.add(field);
+        }
+    }
+
     public boolean isApiResponseField(final String field) {
         return apiResponseFieldSet.contains(field);
     }

+ 22 - 7
src/test/java/org/codelibs/fess/helper/QueryHelperTest.java

@@ -69,13 +69,13 @@ public class QueryHelperTest extends UnitFessTestCase {
         assertEquals(answer_and("QUERY1 QUERY2", "QUERY3"), build_helper("\"QUERY1\u3000QUERY2\"\u3000QUERY3"));
     }
 
-    public void test_build_prefix() {
+    public void test_build_term_field() {
         final String[] ans =
                 {
-                        "{ \"match\" : { \"mimetype\" : { \"query\" : \"QUERY1\", \"type\" : \"phrase\", \"boost\" : 1.0 } } }",
-                        "{ \"bool\" : { \"should\" : [ { \"match\" : { \"mimetype\" : { \"query\" : \"QUERY1\", \"type\" : \"phrase\", \"boost\" : 1.0 } } }, { \"bool\" : { \"should\" : [ { \"match\" : { \"title\" : { \"query\" : \"QUERY2\", \"type\" : \"phrase\", \"boost\" : 1.6 } } }, { \"match\" : { \"content\" : { \"query\" : \"QUERY2\", \"type\" : \"phrase\", \"boost\" : 1.0 } } } ] } } ] } }",
-                        "{ \"bool\" : { \"should\" : [ { \"match\" : { \"mimetype\" : { \"query\" : \"QUERY1\", \"type\" : \"phrase\", \"boost\" : 1.0 } } }, { \"bool\" : { \"should\" : [ { \"match\" : { \"title\" : { \"query\" : \"QUERY2\", \"type\" : \"phrase\", \"boost\" : 1.6 } } }, { \"match\" : { \"content\" : { \"query\" : \"QUERY2\", \"type\" : \"phrase\", \"boost\" : 1.0 } } } ] } }, { \"bool\" : { \"should\" : [ { \"match\" : { \"title\" : { \"query\" : \"QUERY3\", \"type\" : \"phrase\", \"boost\" : 1.6 } } }, { \"match\" : { \"content\" : { \"query\" : \"QUERY3\", \"type\" : \"phrase\", \"boost\" : 1.0 } } } ] } } ] } }",
-                        "{ \"bool\" : { \"should\" : [ { \"match\" : { \"mimetype\" : { \"query\" : \"QUERY1\", \"type\" : \"phrase\", \"boost\" : 1.0 } } }, { \"match\" : { \"host\" : { \"query\" : \"QUERY2\", \"type\" : \"phrase\", \"boost\" : 1.0 } } }, { \"bool\" : { \"should\" : [ { \"match\" : { \"title\" : { \"query\" : \"QUERY3\", \"type\" : \"phrase\", \"boost\" : 1.6 } } }, { \"match\" : { \"content\" : { \"query\" : \"QUERY3\", \"type\" : \"phrase\", \"boost\" : 1.0 } } } ] } } ] } }",
+                        "{ \"term\" : { \"mimetype\" : { \"value\" : \"QUERY1\", \"boost\" : 1.0 } } }",
+                        "{ \"bool\" : { \"should\" : [ { \"term\" : { \"mimetype\" : { \"value\" : \"QUERY1\", \"boost\" : 1.0 } } }, { \"bool\" : { \"should\" : [ { \"match\" : { \"title\" : { \"query\" : \"QUERY2\", \"type\" : \"phrase\", \"boost\" : 1.6 } } }, { \"match\" : { \"content\" : { \"query\" : \"QUERY2\", \"type\" : \"phrase\", \"boost\" : 1.0 } } } ] } } ] } }",
+                        "{ \"bool\" : { \"should\" : [ { \"term\" : { \"mimetype\" : { \"value\" : \"QUERY1\", \"boost\" : 1.0 } } }, { \"bool\" : { \"should\" : [ { \"match\" : { \"title\" : { \"query\" : \"QUERY2\", \"type\" : \"phrase\", \"boost\" : 1.6 } } }, { \"match\" : { \"content\" : { \"query\" : \"QUERY2\", \"type\" : \"phrase\", \"boost\" : 1.0 } } } ] } }, { \"bool\" : { \"should\" : [ { \"match\" : { \"title\" : { \"query\" : \"QUERY3\", \"type\" : \"phrase\", \"boost\" : 1.6 } } }, { \"match\" : { \"content\" : { \"query\" : \"QUERY3\", \"type\" : \"phrase\", \"boost\" : 1.0 } } } ] } } ] } }",
+                        "{ \"bool\" : { \"should\" : [ { \"term\" : { \"mimetype\" : { \"value\" : \"QUERY1\", \"boost\" : 1.0 } } }, { \"term\" : { \"host\" : { \"value\" : \"QUERY2\", \"boost\" : 1.0 } } }, { \"bool\" : { \"should\" : [ { \"match\" : { \"title\" : { \"query\" : \"QUERY3\", \"type\" : \"phrase\", \"boost\" : 1.6 } } }, { \"match\" : { \"content\" : { \"query\" : \"QUERY3\", \"type\" : \"phrase\", \"boost\" : 1.0 } } } ] } } ] } }",
                         "{ \"bool\" : { \"should\" : [ { \"bool\" : { \"should\" : [ { \"match\" : { \"title\" : { \"query\" : \"QUERY1 QUERY2\", \"type\" : \"phrase\", \"boost\" : 1.6 } } }, { \"match\" : { \"content\" : { \"query\" : \"QUERY1 QUERY2\", \"type\" : \"phrase\", \"boost\" : 1.0 } } } ] } }, { \"bool\" : { \"should\" : [ { \"match\" : { \"title\" : { \"query\" : \"QUERY3\", \"type\" : \"phrase\", \"boost\" : 1.6 } } }, { \"match\" : { \"content\" : { \"query\" : \"QUERY3\", \"type\" : \"phrase\", \"boost\" : 1.0 } } } ] } } ] } }" };
         assertEquals(answer_query(ans[0]), build_helper("mimetype:QUERY1"));
         assertEquals(answer_query(ans[1]), build_helper("mimetype:QUERY1 QUERY2"));
@@ -84,13 +84,28 @@ public class QueryHelperTest extends UnitFessTestCase {
         assertEquals(answer_query(ans[4]), build_helper("mimetype:\"QUERY1 QUERY2\" QUERY3"));
     }
 
-    public void test_build_prefix_unknown() {
+    public void test_build_match_field() {
+        final String[] ans =
+                {
+                        "{ \"match\" : { \"title\" : { \"query\" : \"QUERY1\", \"type\" : \"phrase\", \"boost\" : 1.0 } } }",
+                        "{ \"bool\" : { \"should\" : [ { \"match\" : { \"title\" : { \"query\" : \"QUERY1\", \"type\" : \"phrase\", \"boost\" : 1.0 } } }, { \"bool\" : { \"should\" : [ { \"match\" : { \"title\" : { \"query\" : \"QUERY2\", \"type\" : \"phrase\", \"boost\" : 1.6 } } }, { \"match\" : { \"content\" : { \"query\" : \"QUERY2\", \"type\" : \"phrase\", \"boost\" : 1.0 } } } ] } } ] } }",
+                        "{ \"bool\" : { \"should\" : [ { \"match\" : { \"title\" : { \"query\" : \"QUERY1\", \"type\" : \"phrase\", \"boost\" : 1.0 } } }, { \"bool\" : { \"should\" : [ { \"match\" : { \"title\" : { \"query\" : \"QUERY2\", \"type\" : \"phrase\", \"boost\" : 1.6 } } }, { \"match\" : { \"content\" : { \"query\" : \"QUERY2\", \"type\" : \"phrase\", \"boost\" : 1.0 } } } ] } }, { \"bool\" : { \"should\" : [ { \"match\" : { \"title\" : { \"query\" : \"QUERY3\", \"type\" : \"phrase\", \"boost\" : 1.6 } } }, { \"match\" : { \"content\" : { \"query\" : \"QUERY3\", \"type\" : \"phrase\", \"boost\" : 1.0 } } } ] } } ] } }",
+                        "{ \"bool\" : { \"should\" : [ { \"match\" : { \"title\" : { \"query\" : \"QUERY1\", \"type\" : \"phrase\", \"boost\" : 1.0 } } }, { \"term\" : { \"host\" : { \"value\" : \"QUERY2\", \"boost\" : 1.0 } } }, { \"bool\" : { \"should\" : [ { \"match\" : { \"title\" : { \"query\" : \"QUERY3\", \"type\" : \"phrase\", \"boost\" : 1.6 } } }, { \"match\" : { \"content\" : { \"query\" : \"QUERY3\", \"type\" : \"phrase\", \"boost\" : 1.0 } } } ] } } ] } }",
+                        "{ \"bool\" : { \"should\" : [ { \"bool\" : { \"should\" : [ { \"match\" : { \"title\" : { \"query\" : \"QUERY1 QUERY2\", \"type\" : \"phrase\", \"boost\" : 1.6 } } }, { \"match\" : { \"content\" : { \"query\" : \"QUERY1 QUERY2\", \"type\" : \"phrase\", \"boost\" : 1.0 } } } ] } }, { \"bool\" : { \"should\" : [ { \"match\" : { \"title\" : { \"query\" : \"QUERY3\", \"type\" : \"phrase\", \"boost\" : 1.6 } } }, { \"match\" : { \"content\" : { \"query\" : \"QUERY3\", \"type\" : \"phrase\", \"boost\" : 1.0 } } } ] } } ] } }" };
+        assertEquals(answer_query(ans[0]), build_helper("title:QUERY1"));
+        assertEquals(answer_query(ans[1]), build_helper("title:QUERY1 QUERY2"));
+        assertEquals(answer_query(ans[2]), build_helper("title:QUERY1 QUERY2 QUERY3"));
+        assertEquals(answer_query(ans[3]), build_helper("title:QUERY1 host:QUERY2 QUERY3"));
+        assertEquals(answer_query(ans[4]), build_helper("title:\"QUERY1 QUERY2\" QUERY3"));
+    }
+
+    public void test_build_unknown_field() {
         final String[] ans =
                 {
                         "{ \"bool\" : { \"should\" : [ { \"match\" : { \"title\" : { \"query\" : \"foo:QUERY1\", \"type\" : \"phrase\", \"boost\" : 1.6 } } }, { \"match\" : { \"content\" : { \"query\" : \"foo:QUERY1\", \"type\" : \"phrase\", \"boost\" : 1.0 } } } ] } }",
                         "{ \"bool\" : { \"should\" : [ { \"bool\" : { \"should\" : [ { \"match\" : { \"title\" : { \"query\" : \"foo:QUERY1\", \"type\" : \"phrase\", \"boost\" : 1.6 } } }, { \"match\" : { \"content\" : { \"query\" : \"foo:QUERY1\", \"type\" : \"phrase\", \"boost\" : 1.0 } } } ] } }, { \"bool\" : { \"should\" : [ { \"match\" : { \"title\" : { \"query\" : \"QUERY2\", \"type\" : \"phrase\", \"boost\" : 1.6 } } }, { \"match\" : { \"content\" : { \"query\" : \"QUERY2\", \"type\" : \"phrase\", \"boost\" : 1.0 } } } ] } } ] } }",
                         "{ \"bool\" : { \"should\" : [ { \"bool\" : { \"should\" : [ { \"match\" : { \"title\" : { \"query\" : \"foo:QUERY1\", \"type\" : \"phrase\", \"boost\" : 1.6 } } }, { \"match\" : { \"content\" : { \"query\" : \"foo:QUERY1\", \"type\" : \"phrase\", \"boost\" : 1.0 } } } ] } }, { \"bool\" : { \"should\" : [ { \"match\" : { \"title\" : { \"query\" : \"QUERY2\", \"type\" : \"phrase\", \"boost\" : 1.6 } } }, { \"match\" : { \"content\" : { \"query\" : \"QUERY2\", \"type\" : \"phrase\", \"boost\" : 1.0 } } } ] } }, { \"bool\" : { \"should\" : [ { \"match\" : { \"title\" : { \"query\" : \"QUERY3\", \"type\" : \"phrase\", \"boost\" : 1.6 } } }, { \"match\" : { \"content\" : { \"query\" : \"QUERY3\", \"type\" : \"phrase\", \"boost\" : 1.0 } } } ] } } ] } }",
-                        "{ \"bool\" : { \"should\" : [ { \"bool\" : { \"should\" : [ { \"match\" : { \"title\" : { \"query\" : \"foo:QUERY1\", \"type\" : \"phrase\", \"boost\" : 1.6 } } }, { \"match\" : { \"content\" : { \"query\" : \"foo:QUERY1\", \"type\" : \"phrase\", \"boost\" : 1.0 } } } ] } }, { \"match\" : { \"host\" : { \"query\" : \"QUERY2\", \"type\" : \"phrase\", \"boost\" : 1.0 } } }, { \"bool\" : { \"should\" : [ { \"match\" : { \"title\" : { \"query\" : \"QUERY3\", \"type\" : \"phrase\", \"boost\" : 1.6 } } }, { \"match\" : { \"content\" : { \"query\" : \"QUERY3\", \"type\" : \"phrase\", \"boost\" : 1.0 } } } ] } } ] } }",
+                        "{ \"bool\" : { \"should\" : [ { \"bool\" : { \"should\" : [ { \"match\" : { \"title\" : { \"query\" : \"foo:QUERY1\", \"type\" : \"phrase\", \"boost\" : 1.6 } } }, { \"match\" : { \"content\" : { \"query\" : \"foo:QUERY1\", \"type\" : \"phrase\", \"boost\" : 1.0 } } } ] } }, { \"term\" : { \"host\" : { \"value\" : \"QUERY2\", \"boost\" : 1.0 } } }, { \"bool\" : { \"should\" : [ { \"match\" : { \"title\" : { \"query\" : \"QUERY3\", \"type\" : \"phrase\", \"boost\" : 1.6 } } }, { \"match\" : { \"content\" : { \"query\" : \"QUERY3\", \"type\" : \"phrase\", \"boost\" : 1.0 } } } ] } } ] } }",
                         "{ \"bool\" : { \"should\" : [ { \"bool\" : { \"should\" : [ { \"match\" : { \"title\" : { \"query\" : \"QUERY1 QUERY2\", \"type\" : \"phrase\", \"boost\" : 1.6 } } }, { \"match\" : { \"content\" : { \"query\" : \"QUERY1 QUERY2\", \"type\" : \"phrase\", \"boost\" : 1.0 } } } ] } }, { \"bool\" : { \"should\" : [ { \"match\" : { \"title\" : { \"query\" : \"QUERY3\", \"type\" : \"phrase\", \"boost\" : 1.6 } } }, { \"match\" : { \"content\" : { \"query\" : \"QUERY3\", \"type\" : \"phrase\", \"boost\" : 1.0 } } } ] } } ] } }" };
         assertEquals(answer_query(ans[0]), build_helper("foo:QUERY1"));
         assertEquals(answer_query(ans[1]), build_helper("foo:QUERY1 QUERY2"));