@Override public String getPlanDescription(IndexPlan plan, NodeState root) { Filter filter = plan.getFilter(); LuceneIndexNode index = tracker.acquireIndexNode((String) plan.getAttribute(ATTR_INDEX_PATH)); checkState(index != null, "The Lucene index is not available"); try { FullTextExpression ft = filter.getFullTextConstraint(); Set<String> relPaths = getRelativePaths(ft); if (relPaths.size() > 1) { return new MultiLuceneIndex(filter, root, relPaths).getPlan(); } String parent = relPaths.size() == 0 ? "" : relPaths.iterator().next(); // we only restrict non-full-text conditions if there is // no relative property in the full-text constraint boolean nonFullTextConstraints = parent.isEmpty(); String planDesc = getLuceneRequest(filter, null, nonFullTextConstraints, index.getDefinition()) + " ft:(" + ft + ")"; if (!parent.isEmpty()) { planDesc += " parent:" + parent; } return planDesc; } finally { index.release(); } }
@Override public String getPlanDescription(IndexPlan plan, NodeState root) { Filter filter = plan.getFilter(); LuceneIndexNode index = tracker.acquireIndexNode((String) plan.getAttribute(ATTR_INDEX_PATH)); checkState(index != null, "The Lucene index is not available"); try { FullTextExpression ft = filter.getFullTextConstraint(); Set<String> relPaths = getRelativePaths(ft); if (relPaths.size() > 1) { return new MultiLuceneIndex(filter, root, relPaths).getPlan(); } String parent = relPaths.size() == 0 ? "" : relPaths.iterator().next(); // we only restrict non-full-text conditions if there is // no relative property in the full-text constraint boolean nonFullTextConstraints = parent.isEmpty(); String planDesc = getLuceneRequest(filter, null, nonFullTextConstraints, index.getDefinition()) + " ft:(" + ft + ")"; if (!parent.isEmpty()) { planDesc += " parent:" + parent; } return planDesc; } finally { index.release(); } }
@Override public long getSize() { LuceneIndexNode indexNode = tracker.acquireIndexNode((String) plan.getAttribute(ATTR_INDEX_PATH)); checkState(indexNode != null); try { IndexSearcher searcher = indexNode.getSearcher(); LuceneRequestFacade luceneRequestFacade = getLuceneRequest(filter, searcher.getIndexReader(), nonFullTextConstraints, indexNode.getDefinition()); if (luceneRequestFacade.getLuceneRequest() instanceof Query) { Query query = (Query) luceneRequestFacade.getLuceneRequest(); TotalHitCountCollector collector = new TotalHitCountCollector(); searcher.search(query, collector); int totalHits = collector.getTotalHits(); LOG.debug("Estimated size for query {} is {}", query, totalHits); return totalHits; } LOG.debug("Estimated size: not a Query: {}", luceneRequestFacade.getLuceneRequest()); } catch (IOException e) { LOG.warn("query via {} failed.", LuceneIndex.this, e); } finally { indexNode.release(); } return -1; } };
LuceneIndexNode indexNode = tracker.acquireIndexNode((String) plan.getAttribute(ATTR_INDEX_PATH)); checkState(indexNode != null); try {
LuceneIndexNode indexNode = tracker.acquireIndexNode((String) plan.getAttribute(ATTR_INDEX_PATH)); checkState(indexNode != null); try {
Facets facets = null; @SuppressWarnings("unchecked") List<String> facetFields = (List<String>) plan.getAttribute(ATTR_FACET_FIELDS); if (facetFields != null && facetFields.size() > 0) { Map<String, Facets> facetsMap = new HashMap<String, Facets>();
Facets facets = null; @SuppressWarnings("unchecked") List<String> facetFields = (List<String>) plan.getAttribute(ATTR_FACET_FIELDS); if (facetFields != null && facetFields.size() > 0) { Map<String, Facets> facetsMap = new HashMap<String, Facets>();
@Override public long getSize() { LuceneIndexNode indexNode = tracker.acquireIndexNode((String) plan.getAttribute(ATTR_INDEX_PATH)); checkState(indexNode != null); try { IndexSearcher searcher = indexNode.getSearcher(); LuceneRequestFacade luceneRequestFacade = getLuceneRequest(filter, searcher.getIndexReader(), nonFullTextConstraints, indexNode.getDefinition()); if (luceneRequestFacade.getLuceneRequest() instanceof Query) { Query query = (Query) luceneRequestFacade.getLuceneRequest(); TotalHitCountCollector collector = new TotalHitCountCollector(); searcher.search(query, collector); int totalHits = collector.getTotalHits(); LOG.debug("Estimated size for query {} is {}", query, totalHits); return totalHits; } LOG.debug("Estimated size: not a Query: {}", luceneRequestFacade.getLuceneRequest()); } catch (IOException e) { LOG.warn("query via {} failed.", LuceneIndex.this, e); } finally { indexNode.release(); } return -1; } };
@Test public void nullPropertyCheck2() throws Exception{ root = registerTestNodeType(builder).getNodeState(); NodeBuilder defn = newLucenePropertyIndexDefinition(builder, "test", of("foo"), "async"); NodeBuilder rules = defn.child(INDEX_RULES); TestUtil.child(rules, "oak:TestNode/properties/prop2") .setProperty(FulltextIndexConstants.PROP_NAME, "foo") .setProperty(FulltextIndexConstants.PROP_NULL_CHECK_ENABLED, true) .setProperty(FulltextIndexConstants.PROP_PROPERTY_INDEX, true); LuceneIndexDefinition idxDefn = new LuceneIndexDefinition(root, builder.getNodeState().getChildNode("test"), "/foo"); LuceneIndexNode node = createIndexNode(idxDefn); FilterImpl filter = createFilter(NT_TEST); filter.restrictProperty("foo", Operator.EQUAL, null); FulltextIndexPlanner planner = new FulltextIndexPlanner(node, "/foo", filter, Collections.<OrderEntry>emptyList()); QueryIndex.IndexPlan plan = planner.getPlan(); assertNotNull("For null checks plan should be returned with nullCheckEnabled", plan); FulltextIndexPlanner.PlanResult pr = (FulltextIndexPlanner.PlanResult) plan.getAttribute(FulltextIndex.ATTR_PLAN_RESULT); assertNotNull(pr.getPropDefn(filter.getPropertyRestriction("foo"))); }
protected static PlanResult getPlanResult(IndexPlan plan) { return (PlanResult) plan.getAttribute(ATTR_PLAN_RESULT); }
private static FulltextIndexPlanner.PlanResult pr(QueryIndex.IndexPlan plan) { return (FulltextIndexPlanner.PlanResult) plan.getAttribute(FulltextIndex.ATTR_PLAN_RESULT); }
@Test public void attribute() throws Exception{ IndexPlan plan = new IndexPlan.Builder().setAttribute("foo", "bar").build(); assertEquals("bar", plan.getAttribute("foo")); }