static PropertyValue getExcerpt(PropertyValue value) { Splitter listSplitter = Splitter.on(',').trimResults().omitEmptyStrings(); StringBuilder excerpt = new StringBuilder(EXCERPT_BEGIN); for (String v : listSplitter.splitToList(value.toString())) { excerpt.append(v); } excerpt.append(EXCERPT_END); return PropertyValues.newString(excerpt.toString()); } }
private static PropertyValue mvpToString(PropertyValue pv) { String v = Joiner.on(' ') .appendTo(new StringBuilder(), pv.getValue(Type.STRINGS)) .toString(); return PropertyValues.newString(v); }
@Override public PropertyValue currentProperty() { PropertyValue p = operand.currentProperty(); if (p == null) { return null; } // TODO what is the expected result of UPPER(x) for an array property? // currently throws an exception String value = p.getValue(STRING); return PropertyValues.newString(value.toUpperCase()); }
static ResultRowImpl getMappingResultRow(ResultRowImpl delegate, final Map<String, String> columnToFacetMap) { if (columnToFacetMap.size() == 0) { return delegate; } PropertyValue[] mappedVals = delegate.getValues(); for (Map.Entry<String, String> entry : columnToFacetMap.entrySet()) { mappedVals[delegate.query.getColumnIndex(entry.getKey())] = PropertyValues.newString(entry.getValue()); } return new ResultRowImpl(delegate.query, delegate.trees, mappedVals, delegate.distinctValues, delegate.orderValues); } }
private PropertyValue getFallbackExcerpt(String columnName, PropertyValue indexValue) { String ex = SimpleExcerptProvider.getExcerpt(getPath(), columnName, query, true); if (ex != null && ex.length() > 24) { return PropertyValues.newString(ex); } else if (indexValue != null) { return SimpleExcerptProvider.getExcerpt(indexValue); } return PropertyValues.newString(getPath()); }
private PropertyValue getFallbackExcerpt(String columnName, PropertyValue indexValue) { String ex = SimpleExcerptProvider.getExcerpt(getPath(), columnName, query, true); if (ex != null && ex.length() > 24) { return PropertyValues.newString(ex); } else if (indexValue != null) { return SimpleExcerptProvider.getExcerpt(indexValue); } return PropertyValues.newString(getPath()); }
private static Set<String> find(PropertyIndexLookup lookup, String name, String value, Filter filter) { return Sets.newHashSet(lookup.query(filter, name, value == null ? null : PropertyValues.newString(value))); }
@Override public PropertyValue currentProperty() { String path = selector.currentPath(); if (path == null) { return null; } String name = PathUtils.getName(path); String localName = getLocalName(name); // TODO reverse namespace remapping? return PropertyValues.newString(localName); }
@Override public PropertyValue currentProperty() { String path = selector.currentPath(); if (path == null) { return null; } String name = PathUtils.getName(path); String localName = getLocalName(name); // TODO reverse namespace remapping? return PropertyValues.newString(localName); }
@Override public void restrict(FilterImpl f) { if (f.getSelector().equals(selector)) { PropertyValue p = expression.currentValue(); String term = p.getValue(Type.STRING); String query = SUGGEST_PREFIX + term; PropertyValue v = PropertyValues.newString(query); f.restrictProperty(NativeFunctionImpl.NATIVE_PREFIX + NATIVE_LUCENE_LANGUAGE, Operator.EQUAL, v); } }
@Override public void restrict(FilterImpl f) { if (f.getSelector().equals(selector)) { PropertyValue p = expression.currentValue(); String term = p.getValue(Type.STRING); String query = SUGGEST_PREFIX + term; PropertyValue v = PropertyValues.newString(query); f.restrictProperty(NativeFunctionImpl.NATIVE_PREFIX + NATIVE_LUCENE_LANGUAGE, Operator.EQUAL, v); } }
private List<String> query(String propertyName, String value) { FilterImpl f = createFilter(); f.restrictProperty(propertyName, Operator.EQUAL, newString(value)); return query(f, propertyName); }
@Test public void testNoPlanWithPropertyRestrictions() throws Exception { SelectorImpl selector = newSelector(nodeState, "a"); SolrQueryIndex solrQueryIndex = new SolrQueryIndex(null, null, null); FilterImpl filter = new FilterImpl(selector, "select * from [nt:base] as a where name = 'hello')", new QueryEngineSettings()); filter.restrictProperty("name", Operator.EQUAL, PropertyValues.newString("hello")); List<QueryIndex.OrderEntry> sortOrder = new LinkedList<QueryIndex.OrderEntry>(); List<QueryIndex.IndexPlan> plans = solrQueryIndex.getPlans(filter, sortOrder, nodeState); assertEquals(0, plans.size()); }
@Test public void nodeTypeInheritance() throws Exception{ //Index if for nt:hierarchyNode and query is for nt:folder //as nt:folder extends nt:hierarchyNode we should get a plan NodeBuilder defn = newLucenePropertyIndexDefinition(builder, "test", of("foo"), "async"); defn.setProperty(createProperty(IndexConstants.DECLARING_NODE_TYPES, of("nt:hierarchyNode"), STRINGS)); LuceneIndexNode node = createIndexNode(new LuceneIndexDefinition(root, defn.getNodeState(), "/foo")); FilterImpl filter = createFilter("nt:folder"); filter.restrictProperty("foo", Operator.EQUAL, PropertyValues.newString("bar")); FulltextIndexPlanner planner = new FulltextIndexPlanner(node, "/foo", filter, Collections.<OrderEntry>emptyList()); assertNotNull(planner.getPlan()); }
@Test public void noMatchingProperty() throws Exception{ NodeBuilder defn = newLucenePropertyIndexDefinition(builder, "test", of("foo"), "async"); LuceneIndexNode node = createIndexNode(new LuceneIndexDefinition(root, defn.getNodeState(), "/foo")); FilterImpl filter = createFilter("nt:base"); filter.restrictProperty("bar", Operator.EQUAL, PropertyValues.newString("bar")); FulltextIndexPlanner planner = new FulltextIndexPlanner(node, "/foo", filter, Collections.<OrderEntry>emptyList()); assertNull(planner.getPlan()); } @Test
@Test public void noPathRestHasQueryPath() throws Exception{ NodeBuilder defn = newLucenePropertyIndexDefinition(builder, "test", of("foo"), "async"); defn.setProperty(createProperty(IndexConstants.QUERY_PATHS, of("/test/a"), Type.STRINGS)); LuceneIndexNode node = createIndexNode(new LuceneIndexDefinition(root, defn.getNodeState(), "/foo")); FilterImpl filter = createFilter("nt:base"); filter.restrictProperty("foo", Operator.EQUAL, PropertyValues.newString("bar")); filter.restrictPath("/test2", Filter.PathRestriction.ALL_CHILDREN); FulltextIndexPlanner planner = new FulltextIndexPlanner(node, "/foo", filter, Collections.<OrderEntry>emptyList()); assertNull(planner.getPlan()); }
@Test public void valuePattern() throws Exception{ defnb.indexRule("nt:base").property("foo").sync().valueIncludedPrefixes("bar/"); newCallback().propertyUpdated("/a", "foo", pd("foo"), null, createProperty("foo", "bar/a")); newCallback().propertyUpdated("/b", "foo", pd("foo"), null, createProperty("foo", "baz/a")); assertThat(query("foo", newString("bar/a")), containsInAnyOrder("/a")); //As baz pattern is excluded it should not be indexed assertThat(query("foo", newString("baz/a")), empty()); }
@Test public void hasPathRestHasNoExplicitQueryPaths() throws Exception{ NodeBuilder defn = newLucenePropertyIndexDefinition(builder, "test", of("foo"), "async"); LuceneIndexNode node = createIndexNode(new LuceneIndexDefinition(root, defn.getNodeState(), "/foo")); FilterImpl filter = createFilter("nt:base"); filter.restrictPath("/test2", Filter.PathRestriction.ALL_CHILDREN); filter.restrictProperty("foo", Operator.EQUAL, PropertyValues.newString("bar")); FulltextIndexPlanner planner = new FulltextIndexPlanner(node, "/foo", filter, Collections.<OrderEntry>emptyList()); assertNotNull(planner.getPlan()); }
@Test public void pathResultAbsolutePath() throws Exception{ defnb.indexRule("nt:base").property("foo").sync(); propertyUpdated("/a", "foo", "bar"); String propertyName = "foo"; FilterImpl filter = createFilter(); filter.restrictProperty("foo", Operator.EQUAL, newString("bar")); HybridPropertyIndexLookup lookup = new HybridPropertyIndexLookup(indexPath, builder.getNodeState()); Iterable<String> paths = lookup.query(filter, propertyName, filter.getPropertyRestriction(propertyName)); assertThat(ImmutableList.copyOf(paths), containsInAnyOrder("/a")); }
@Test public void matchingProperty() throws Exception{ NodeBuilder defn = newLucenePropertyIndexDefinition(builder, "test", of("foo"), "async"); LuceneIndexNode node = createIndexNode(new LuceneIndexDefinition(root, defn.getNodeState(), "/foo")); FilterImpl filter = createFilter("nt:base"); filter.restrictProperty("foo", Operator.EQUAL, PropertyValues.newString("bar")); FulltextIndexPlanner planner = new FulltextIndexPlanner(node, "/foo", filter, Collections.<OrderEntry>emptyList()); QueryIndex.IndexPlan plan = planner.getPlan(); assertNotNull(plan); assertNotNull(pr(plan)); assertTrue(pr(plan).evaluateNonFullTextConstraints()); }