summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@yahoo-inc.com>2017-06-08 11:11:19 +0200
committerJon Bratseth <bratseth@yahoo-inc.com>2017-06-08 11:11:19 +0200
commit739833c51230d2bdb7699906b7acaa6a8bb76044 (patch)
treed1f3a937be23676a53f16066ab3ec9e0f67d42f0
parent6906d1d0da11d0ad46aefa016f1ba29dbf51ad22 (diff)
Nonfunctional changes
-rw-r--r--.gitignore1
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/derived/Derived.java4
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/derived/IndexInfo.java2
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/document/Matching.java2
-rw-r--r--container-search/src/main/java/com/yahoo/prelude/IndexFacts.java22
-rw-r--r--container-search/src/main/java/com/yahoo/prelude/IndexModel.java4
-rw-r--r--container-search/src/main/java/com/yahoo/prelude/SearchDefinition.java2
-rw-r--r--container-search/src/main/java/com/yahoo/prelude/query/parser/AbstractParser.java15
-rw-r--r--container-search/src/main/java/com/yahoo/prelude/querytransform/PhraseMatcher.java22
-rw-r--r--container-search/src/main/java/com/yahoo/prelude/querytransform/PhrasingSearcher.java17
-rw-r--r--container-search/src/test/java/com/yahoo/prelude/test/IndexFactsTestCase.java66
11 files changed, 116 insertions, 41 deletions
diff --git a/.gitignore b/.gitignore
index 7bc8af51e33..7ad1a865a5e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -40,3 +40,4 @@ Testing
/hadoop/dependency-reduced-pom.xml
/vespa-hadoop/dependency-reduced-pom.xml
.preprocessed/
+.DS_Store
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/derived/Derived.java b/config-model/src/main/java/com/yahoo/searchdefinition/derived/Derived.java
index 469af71f7d9..a8a36c5b00f 100644
--- a/config-model/src/main/java/com/yahoo/searchdefinition/derived/Derived.java
+++ b/config-model/src/main/java/com/yahoo/searchdefinition/derived/Derived.java
@@ -20,7 +20,7 @@ import java.util.List;
/**
* Superclass of all derived configurations
*
- * @author bratseth
+ * @author bratseth
*/
public abstract class Derived implements Exportable {
@@ -43,7 +43,7 @@ public abstract class Derived implements Exportable {
derive(index, search);
}
for (SDField field : search.allExtraFields() ) {
- derive(field,search);
+ derive(field, search);
}
search.allImportedFields()
.forEach(importedField -> derive(importedField, search));
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/derived/IndexInfo.java b/config-model/src/main/java/com/yahoo/searchdefinition/derived/IndexInfo.java
index b4791ecdff2..f82aeb3a24b 100644
--- a/config-model/src/main/java/com/yahoo/searchdefinition/derived/IndexInfo.java
+++ b/config-model/src/main/java/com/yahoo/searchdefinition/derived/IndexInfo.java
@@ -446,7 +446,7 @@ public class IndexInfo extends Derived implements IndexInfoConfig.Producer {
}
private boolean isExactMatch(Matching m) {
- if (m==null) return false;
+ if (m == null) return false;
if (m.getType().equals(Matching.Type.EXACT)) return true;
if (m.getType().equals(Matching.Type.WORD)) return true;
return false;
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/document/Matching.java b/config-model/src/main/java/com/yahoo/searchdefinition/document/Matching.java
index f4efadbd049..162124c537c 100644
--- a/config-model/src/main/java/com/yahoo/searchdefinition/document/Matching.java
+++ b/config-model/src/main/java/com/yahoo/searchdefinition/document/Matching.java
@@ -13,7 +13,7 @@ public class Matching implements Cloneable, Serializable {
public static final Type defaultType = Type.TEXT;
- public static enum Type {
+ public enum Type {
TEXT("text"),
WORD("word"),
EXACT("exact"),
diff --git a/container-search/src/main/java/com/yahoo/prelude/IndexFacts.java b/container-search/src/main/java/com/yahoo/prelude/IndexFacts.java
index 3f931c92489..a4fe92b5be8 100644
--- a/container-search/src/main/java/com/yahoo/prelude/IndexFacts.java
+++ b/container-search/src/main/java/com/yahoo/prelude/IndexFacts.java
@@ -1,9 +1,7 @@
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.prelude;
-
import com.google.common.collect.ImmutableList;
-import com.yahoo.language.process.StemMode;
import com.yahoo.search.Query;
import java.util.*;
@@ -46,11 +44,16 @@ public class IndexFacts {
/**
* The name of the default search definition, which is the union of all
* known document types.
+ *
+ * @deprecated do not use
*/
+ // TODO: Make this package private in Vespa 7
+ @Deprecated
public static final String unionName = "unionOfAllKnown";
/** A search definition which contains the union of all settings. */
- private SearchDefinition unionSearchDefinition=new SearchDefinition(unionName);
+ @SuppressWarnings("deprecation")
+ private SearchDefinition unionSearchDefinition = new SearchDefinition(unionName);
private boolean frozen;
@@ -111,6 +114,11 @@ public class IndexFacts {
clusterByDocument = invert(clusters);
}
+ /**
+ * @deprecated set indexes at creation time instead
+ */
+ // TODO: Remove on Vespa 7
+ @Deprecated
public void setSearchDefinitions(Map<String, SearchDefinition> searchDefinitions,
SearchDefinition unionSearchDefinition) {
ensureNotFrozen();
@@ -123,7 +131,7 @@ public class IndexFacts {
}
private boolean isIndexFromDocumentTypes(String indexName, List<String> documentTypes) {
- if (!isInitialized()) return true;
+ if ( ! isInitialized()) return true;
if (documentTypes.isEmpty()) {
return unionSearchDefinition.getIndex(indexName) != null;
@@ -300,7 +308,10 @@ public class IndexFacts {
*
* @param sdName name of search definition containing index, if null, modify default set
* @param indexName name of index, actual or otherwise
+ * @deprecated set indexes at creation time instead
*/
+ // TODO: Remove on Vespa 7
+ @Deprecated
public void addIndex(String sdName, String indexName) {
ensureNotFrozen();
@@ -320,7 +331,10 @@ public class IndexFacts {
/**
* Adds an index to the specified index, and the default index settings,
* overriding any current settings for this index
+ * @deprecated set indexes at creation time instead
*/
+ // TODO: Remove on Vespa 7
+ @Deprecated
public void addIndex(String sdName, Index index) {
ensureNotFrozen();
diff --git a/container-search/src/main/java/com/yahoo/prelude/IndexModel.java b/container-search/src/main/java/com/yahoo/prelude/IndexModel.java
index a4e08accd48..e0a4fc3561c 100644
--- a/container-search/src/main/java/com/yahoo/prelude/IndexModel.java
+++ b/container-search/src/main/java/com/yahoo/prelude/IndexModel.java
@@ -15,9 +15,10 @@ import com.yahoo.container.QrSearchersConfig;
/**
* Parameter class used for construction IndexFacts.
*
- * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a>
+ * @author Steinar Knutsen
*/
public final class IndexModel {
+
private static final Logger log = Logger.getLogger(IndexModel.class.getName());
// Copied from MasterClustersInfoUpdater. It's a temporary workaround for IndexFacts.
@@ -72,6 +73,7 @@ public final class IndexModel {
}
}
+ @SuppressWarnings("deprecation")
private void setDefinitions(IndexInfoConfig c) {
searchDefinitions = new HashMap<>();
unionSearchDefinition = new SearchDefinition(IndexFacts.unionName);
diff --git a/container-search/src/main/java/com/yahoo/prelude/SearchDefinition.java b/container-search/src/main/java/com/yahoo/prelude/SearchDefinition.java
index 0cec7cfc19d..a9fb3e54826 100644
--- a/container-search/src/main/java/com/yahoo/prelude/SearchDefinition.java
+++ b/container-search/src/main/java/com/yahoo/prelude/SearchDefinition.java
@@ -12,7 +12,7 @@ import static com.yahoo.text.Lowercase.toLowerCase;
* An object for storing information about search definitions in the centralized
* directory services.
*
- * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a>
+ * @author Steinar Knutsen
*/
// TODO: Make freezable!
public class SearchDefinition {
diff --git a/container-search/src/main/java/com/yahoo/prelude/query/parser/AbstractParser.java b/container-search/src/main/java/com/yahoo/prelude/query/parser/AbstractParser.java
index c7e3412facc..9fbaf0d83c9 100644
--- a/container-search/src/main/java/com/yahoo/prelude/query/parser/AbstractParser.java
+++ b/container-search/src/main/java/com/yahoo/prelude/query/parser/AbstractParser.java
@@ -67,22 +67,17 @@ public abstract class AbstractParser implements CustomParser {
* @param indexName the index name which should decide the submodes, or null to do nothing.
* @param session the session used to look up information about this index
*/
- @SuppressWarnings({"deprecation"})
// To avoid this we need to pass an IndexFacts.session down instead - easily done but not without breaking API's
- public void setFromIndex(final String indexName, IndexFacts.Session session) {
- if (indexName == null) {
- return;
- }
+ public void setFromIndex(String indexName, IndexFacts.Session session) {
+ if (indexName == null) return;
reset();
+ Index current = session.getIndex(indexName);
- final Index current = session.getIndex(indexName);
-
- if (current.isUriIndex()) {
+ if (current.isUriIndex())
url = true;
- } else if (current.isHostIndex()) {
+ else if (current.isHostIndex())
site = true;
- }
}
/** Sets default values for all submodes */
diff --git a/container-search/src/main/java/com/yahoo/prelude/querytransform/PhraseMatcher.java b/container-search/src/main/java/com/yahoo/prelude/querytransform/PhraseMatcher.java
index 12a904a29e2..7c6d1285454 100644
--- a/container-search/src/main/java/com/yahoo/prelude/querytransform/PhraseMatcher.java
+++ b/container-search/src/main/java/com/yahoo/prelude/querytransform/PhraseMatcher.java
@@ -12,13 +12,13 @@ import java.util.NoSuchElementException;
import static com.yahoo.language.LinguisticsCase.toLowerCase;
/**
- * <p>Detects query phrases using an automaton. This class is thread safe.</p>
+ * Detects query phrases using an automaton. This class is thread safe.
*
- * @author bratseth
+ * @author bratseth
*/
public class PhraseMatcher {
- private FSA phraseFSA;
+ private FSA phraseFSA = null;
private boolean matchPhraseItems=false;
@@ -31,7 +31,7 @@ public class PhraseMatcher {
private boolean matchAll =false;
/** For null subclass only */
- PhraseMatcher() {
+ private PhraseMatcher() {
}
/**
@@ -69,6 +69,8 @@ public class PhraseMatcher {
phraseFSA=phraseAutomatonFSA;
}
+ public boolean isEmpty() { return phraseFSA == null; }
+
/**
* Set whether to match words contained in phrase items as well.
* Default is false - don't match words contained in phrase items
@@ -138,10 +140,10 @@ public class PhraseMatcher {
}
/** Find matches within a composite */
- private void recursivelyMatchPhrases(Item item,MatchedPhrases phrases) {
- if (item==null) return;
+ private void recursivelyMatchPhrases(Item item, MatchedPhrases phrases) {
+ if (item == null) return;
if ( ! (item instanceof CompositeItem) ) return;
- if ( !matchPhraseItems && item instanceof PhraseItem ) return;
+ if ( ! matchPhraseItems && item instanceof PhraseItem ) return;
CompositeItem owner=(CompositeItem)item;
int i=0;
@@ -547,12 +549,16 @@ public class PhraseMatcher {
/** Returns a phrase matcher which (quickly) never matches anything */
public static PhraseMatcher getNullMatcher() {
+
return new PhraseMatcher() {
- public List<Phrase> matchPhrases(Item item) {
+ @Override
+ public List<Phrase> matchPhrases(Item item) {
return null;
}
+
};
+
}
}
diff --git a/container-search/src/main/java/com/yahoo/prelude/querytransform/PhrasingSearcher.java b/container-search/src/main/java/com/yahoo/prelude/querytransform/PhrasingSearcher.java
index 78c046efd10..f5e229fe6a2 100644
--- a/container-search/src/main/java/com/yahoo/prelude/querytransform/PhrasingSearcher.java
+++ b/container-search/src/main/java/com/yahoo/prelude/querytransform/PhrasingSearcher.java
@@ -7,6 +7,8 @@ import com.yahoo.component.chain.dependencies.After;
import com.yahoo.component.chain.dependencies.Before;
import com.yahoo.component.chain.dependencies.Provides;
import com.yahoo.container.QrSearchersConfig;
+import com.yahoo.search.Query;
+import com.yahoo.search.Result;
import com.yahoo.search.Searcher;
import com.yahoo.processing.request.CompoundName;
import com.yahoo.search.searchchain.Execution;
@@ -16,11 +18,11 @@ import com.yahoo.search.searchchain.PhaseNames;
import java.util.List;
/**
- * <p>Detects query phrases. When a phrase is detected in the query,
- * the query is mutated to reflect this fact.</p>
+ * Detects query phrases. When a phrase is detected in the query,
+ * the query is mutated to reflect this fact.
*
- * @author bratseth
- * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a>
+ * @author bratseth
+ * @author Einar M R Rosenvinge
*/
@After(PhaseNames.RAW_QUERY)
@Before(PhaseNames.TRANSFORMED_QUERY)
@@ -54,9 +56,11 @@ public class PhrasingSearcher extends Searcher {
}
@Override
- public com.yahoo.search.Result search(com.yahoo.search.Query query, Execution execution) {
+ public Result search(Query query, Execution execution) {
+ if (phraseMatcher.isEmpty()) return execution.search(query);
+
List<PhraseMatcher.Phrase> replacePhrases = phraseMatcher.matchPhrases(query.getModel().getQueryTree().getRoot());
- if (replacePhrases != null && !query.properties().getBoolean(suggestonly, false)) {
+ if (replacePhrases != null && ! query.properties().getBoolean(suggestonly, false)) {
replace(replacePhrases);
query.trace("Replacing phrases", true, 2);
}
@@ -73,4 +77,5 @@ public class PhrasingSearcher extends Searcher {
phrase.replace();
}
}
+
}
diff --git a/container-search/src/test/java/com/yahoo/prelude/test/IndexFactsTestCase.java b/container-search/src/test/java/com/yahoo/prelude/test/IndexFactsTestCase.java
index 0700d4489e7..9f68acd4a0f 100644
--- a/container-search/src/test/java/com/yahoo/prelude/test/IndexFactsTestCase.java
+++ b/container-search/src/test/java/com/yahoo/prelude/test/IndexFactsTestCase.java
@@ -7,7 +7,6 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.Set;
import java.util.TreeMap;
import com.yahoo.config.subscription.ConfigGetter;
@@ -23,21 +22,26 @@ import com.yahoo.prelude.IndexModel;
import com.yahoo.prelude.SearchDefinition;
import com.yahoo.search.Query;
import com.yahoo.search.searchchain.Execution;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
/**
* Tests using synthetic index names for IndexFacts class.
*
- * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a>
+ * @author Steinar Knutsen
*/
@SuppressWarnings({"rawtypes", "unchecked"})
-public class IndexFactsTestCase extends junit.framework.TestCase {
+public class IndexFactsTestCase {
private static final String INDEXFACTS_TESTING = "file:src/test/java/com/yahoo/prelude/test/indexfactstesting.cfg";
- public IndexFactsTestCase(String name) {
- super(name);
- }
-
private IndexFacts createIndexFacts() {
ConfigGetter<IndexInfoConfig> getter = new ConfigGetter<>(IndexInfoConfig.class);
IndexInfoConfig config = getter.getConfig(INDEXFACTS_TESTING);
@@ -54,6 +58,7 @@ public class IndexFactsTestCase extends junit.framework.TestCase {
return indexFacts;
}
+ @Test
public void testBasicCases() {
// First check default behavior
IndexFacts indexFacts = createIndexFacts();
@@ -68,6 +73,7 @@ public class IndexFactsTestCase extends junit.framework.TestCase {
assertEquals("yetanothersynthetic:b", q.getModel().getQueryTree().getRoot().toString());
}
+ @Test
public void testDefaultPosition() {
Index a = new Index("a");
assertFalse(a.isDefaultPosition());
@@ -96,6 +102,7 @@ public class IndexFactsTestCase extends junit.framework.TestCase {
assertTrue(indexFacts.getDefaultPosition("sd").equals("c"));
}
+ @Test
public void testIndicesInAnyConfigurationAreIndicesInDefault() {
IndexFacts.Session indexFacts = createIndexFacts().newSession(new Query());
assertTrue(indexFacts.isIndex("a"));
@@ -105,18 +112,21 @@ public class IndexFactsTestCase extends junit.framework.TestCase {
assertFalse(indexFacts.isIndex("anythingelse"));
}
+ @Test
public void testDefaultIsUnionHostIndex() {
IndexFacts.Session session = createIndexFacts().newSession(new Query());
assertTrue(session.getIndex("c").isHostIndex());
assertFalse(session.getIndex("a").isHostIndex());
}
+ @Test
public void testDefaultIsUnionUriIndex() {
IndexFacts indexFacts = createIndexFacts();
assertTrue(indexFacts.newSession(new Query()).getIndex("d").isUriIndex());
assertFalse(indexFacts.newSession(new Query()).getIndex("a").isUriIndex());
}
+ @Test
public void testDefaultIsUnionStemMode() {
IndexFacts.Session session = createIndexFacts().newSession(new Query());
assertEquals(StemMode.NONE, session.getIndex("a").getStemMode());
@@ -135,6 +145,7 @@ public class IndexFactsTestCase extends junit.framework.TestCase {
assertEquals(indexName + ":foo...", q.getModel().getQueryTree().getRoot().toString());
}
+ @Test
public void testExactMatching() {
assertExactIsWorking("test");
assertExactIsWorking("artist_name_ft_norm1");
@@ -163,6 +174,7 @@ public class IndexFactsTestCase extends junit.framework.TestCase {
assertNull(wem.getExactTerminator());
}
+ @Test
public void testComplexExactMatching() {
IndexFacts indexFacts = createIndexFacts();
String u_name = "foo_bar";
@@ -181,6 +193,7 @@ public class IndexFactsTestCase extends junit.framework.TestCase {
}
// This is also backed by a system test on cause of complex config
+ @Test
public void testRestrictLists1() {
Query query = new Query();
query.getModel().getSources().add("nalle");
@@ -193,6 +206,7 @@ public class IndexFactsTestCase extends junit.framework.TestCase {
assertTrue(indexFacts.isIndex("d"));
}
+ @Test
public void testRestrictLists2() {
Query query = new Query();
query.getModel().getSources().add("clusterTwo");
@@ -212,6 +226,7 @@ public class IndexFactsTestCase extends junit.framework.TestCase {
assertEquals(StemMode.NONE, session.getIndex("b").getStemMode());
}
+ @Test
public void testRestrictLists3() {
Query query = new Query();
query.getModel().getSources().add("clusterOne");
@@ -224,6 +239,7 @@ public class IndexFactsTestCase extends junit.framework.TestCase {
assertTrue(session.getIndex("e").isExact());
}
+ @Test
public void testOverlappingAliases() {
IndexInfoConfig cfg = new IndexInfoConfig(new IndexInfoConfig.Builder()
.indexinfo(
@@ -254,6 +270,7 @@ public class IndexFactsTestCase extends junit.framework.TestCase {
return query;
}
+ @Test
public void testPredicateBounds() {
Index index = new Index("a");
assertEquals(Long.MIN_VALUE, index.getPredicateLowerBound());
@@ -274,4 +291,39 @@ public class IndexFactsTestCase extends junit.framework.TestCase {
assertEquals(2L, index.getPredicateLowerBound());
assertEquals(Long.MAX_VALUE, index.getPredicateUpperBound());
}
+
+ @Test
+ public void testUriIndexAndRestrict() {
+ IndexInfoConfig.Builder b = new IndexInfoConfig.Builder();
+
+ IndexInfoConfig.Indexinfo.Builder b1 = new IndexInfoConfig.Indexinfo.Builder();
+ b1.name("hasUri");
+ IndexInfoConfig.Indexinfo.Command.Builder bb1 = new IndexInfoConfig.Indexinfo.Command.Builder();
+ bb1.indexname("url");
+ bb1.command("fullurl");
+ b1.command(bb1);
+ b.indexinfo(b1);
+
+ IndexInfoConfig.Indexinfo.Builder b2 = new IndexInfoConfig.Indexinfo.Builder();
+ b2.name("hasNotUri1");
+ b.indexinfo(b2);
+
+ IndexInfoConfig.Indexinfo.Builder b3 = new IndexInfoConfig.Indexinfo.Builder();
+ b3.name("hasNotUri2");
+ b.indexinfo(b3);
+
+ IndexInfoConfig config = new IndexInfoConfig(b);
+ IndexFacts indexFacts = new IndexFacts(new IndexModel(config, Collections.emptyMap()));
+ Query query1 = new Query("?query=url:https://foo.bar");
+ Query query2 = new Query("?query=url:https://foo.bar&restrict=hasUri");
+ assertEquals(0, query1.getModel().getRestrict().size());
+ assertEquals(1, query2.getModel().getRestrict().size());
+ IndexFacts.Session session1 = indexFacts.newSession(query1.getModel().getSources(), query1.getModel().getRestrict());
+ IndexFacts.Session session2 = indexFacts.newSession(query2.getModel().getSources(), query2.getModel().getRestrict());
+ assertTrue(session1.getIndex("url").isUriIndex());
+ assertTrue(session2.getIndex("url").isUriIndex());
+ assertEquals("url:\"https foo bar\"", query1.getModel().getQueryTree().toString());
+ assertEquals("url:\"https foo bar\"", query2.getModel().getQueryTree().toString());
+ }
+
}