Exemplo n.º 1
0
 /**
  * Choose a graph from a DatasetGraph. If it's the union, provide a union graph (not always the
  * best way to deal with union).
  *
  * @param dataset
  * @param graphNode
  * @return Graph
  */
 protected static Graph chooseGraph(DatasetGraph dataset, Node graphNode) {
   if (graphNode == null) return dataset.getDefaultGraph();
   else if (Var.isVar(graphNode))
     throw new NotImplemented("Choosing a graph OpExecutorStage.executeBlockFilter[Variable]");
   else if (graphNode == Node.ANY)
     throw new NotImplemented("OpExecutorMain.executeBlockFilter[Node.ANY]");
   else if (Quad.isUnionGraph(graphNode)) {
     // TODO Check this!  Work needed here to consolidate union graph handling.
     List<Node> graphs = Iter.toList(dataset.listGraphNodes());
     return new GraphUnionRead(dataset, graphs);
   } else return dataset.getGraph(graphNode);
 }
Exemplo n.º 2
0
  private ListMultimap<String, TextHit> query(
      Node property, String queryString, int limit, ExecutionContext execCxt) {
    // use the graph information in the text index if possible
    if (textIndex.getDocDef().getGraphField() != null
        && execCxt.getActiveGraph() instanceof GraphView) {
      GraphView activeGraph = (GraphView) execCxt.getActiveGraph();
      if (!Quad.isUnionGraph(activeGraph.getGraphName())) {
        String uri =
            activeGraph.getGraphName() != null
                ? TextQueryFuncs.graphNodeToString(activeGraph.getGraphName())
                : Quad.defaultGraphNodeGenerated.getURI();
        String escaped = QueryParserBase.escape(uri);
        String qs2 = textIndex.getDocDef().getGraphField() + ":" + escaped;
        queryString = "(" + queryString + ") AND " + qs2;
      }
    }

    // for language-based search extension
    if (textIndex.getDocDef().getLangField() != null) {
      String field = textIndex.getDocDef().getLangField();
      if (langArg != null) {
        String qs2 = !"none".equals(langArg) ? field + ":" + langArg : "-" + field + ":*";
        queryString = "(" + queryString + ") AND " + qs2;
      }
    }

    Explain.explain(execCxt.getContext(), "Text query: " + queryString);
    if (log.isDebugEnabled()) log.debug("Text query: {} ({})", queryString, limit);

    String cacheKey = limit + " " + property + " " + queryString;
    Cache<String, ListMultimap<String, TextHit>> queryCache =
        (Cache<String, ListMultimap<String, TextHit>>) execCxt.getContext().get(cacheSymbol);
    if (queryCache == null) {
        /* doesn't yet exist, need to create it */
      queryCache = CacheFactory.createCache(CACHE_SIZE);
      execCxt.getContext().put(cacheSymbol, queryCache);
    }

    final String queryStr = queryString; // final needed for the lambda function
    ListMultimap<String, TextHit> results =
        queryCache.getOrFill(
            cacheKey,
            () -> {
              List<TextHit> resultList = textIndex.query(property, queryStr, limit);
              ListMultimap<String, TextHit> resultMultimap = LinkedListMultimap.create();
              for (TextHit result : resultList) {
                resultMultimap.put(result.getNode().getURI(), result);
              }
              return resultMultimap;
            });
    return results;
  }