Package org.exist.indexing.lucene

Examples of org.exist.indexing.lucene.LuceneIndexWorker


        return NodeSet.EMPTY_SET;
     
        long start = System.currentTimeMillis();
        // the expression can be called multiple times, so we need to clear the previous preselectResult
        preselectResult = null;
        LuceneIndexWorker index = (LuceneIndexWorker) context.getBroker().getIndexController().getWorkerByIndexId(LuceneIndex.ID);

        // DW: contextSequence can be null
        DocumentSet docs = contextSequence.getDocumentSet();
        Item key = getKey(contextSequence, null);
        List<QName> qnames = new ArrayList<>(1);
        qnames.add(contextQName);
        Properties options = parseOptions(contextSequence, null);
        try {
            if (Type.subTypeOf(key.getType(), Type.ELEMENT))
                preselectResult = index.query(context, getExpressionId(), docs, useContext ? contextSequence.toNodeSet() : null,
                    qnames, (Element) ((NodeValue)key).getNode(), NodeSet.DESCENDANT, options);
            else
                preselectResult = index.query(context, getExpressionId(), docs, useContext ? contextSequence.toNodeSet() : null,
                    qnames, key.getStringValue(), NodeSet.DESCENDANT, options);
        } catch (IOException | org.apache.lucene.queryparser.classic.ParseException e) {
            throw new XPathException(this, "Error while querying full text index: " + e.getMessage(), e);
        }
        LOG.trace("Lucene query took " + (System.currentTimeMillis() - start));
View Full Code Here


            if (!(input instanceof VirtualNodeSet) && input.isEmpty())
                result = NodeSet.EMPTY_SET;
            else {
                NodeSet inNodes = input.toNodeSet();
                DocumentSet docs = inNodes.getDocumentSet();
                LuceneIndexWorker index = (LuceneIndexWorker)
                        context.getBroker().getIndexController().getWorkerByIndexId(LuceneIndex.ID);
                Item key = getKey(contextSequence, contextItem);
                List<QName> qnames = null;
                if (contextQName != null) {
                    qnames = new ArrayList<>(1);
                    qnames.add(contextQName);
                }
                Properties options = parseOptions(contextSequence, contextItem);
                try {
                    if (Type.subTypeOf(key.getType(), Type.ELEMENT))
                        result = index.query(context, getExpressionId(), docs, inNodes, qnames,
                                (Element)((NodeValue)key).getNode(), NodeSet.ANCESTOR, options);
                    else
                        result = index.query(context, getExpressionId(), docs, inNodes, qnames,
                                key.getStringValue(), NodeSet.ANCESTOR, options);
                } catch (IOException | org.apache.lucene.queryparser.classic.ParseException e) {
                    throw new XPathException(this, e.getMessage());
                }
            }
View Full Code Here

    public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
        if (!context.getUser().hasDbaRole())
            throw new XPathException(this, "user has to be a member of the dba group to call " +
                "the optimize function. Calling user was " + context.getUser().getName());
        LuceneIndexWorker index = (LuceneIndexWorker)
                context.getBroker().getIndexController().getWorkerByIndexId(LuceneIndex.ID);
        index.optimize();
        return Sequence.EMPTY_SEQUENCE;
    }
View Full Code Here

      doc = context.getBroker().getXMLResource(uri, Lock.READ_LOCK);
      if (doc == null) {
                return Sequence.EMPTY_SEQUENCE;
            }
      // Get the lucene worker
            LuceneIndexWorker index = (LuceneIndexWorker) context.getBroker().getIndexController().getWorkerByIndexId(LuceneIndex.ID);
            String content = index.getFieldContent(doc.getDocId(), field);
            return content == null ? Sequence.EMPTY_SEQUENCE : new org.exist.xquery.value.StringValue(content);
    } catch (PermissionDeniedException e) {
      throw new XPathException(this, LuceneModule.EXXQDYFT0001, "Permission denied to read document " + args[0].getStringValue());
    } catch (IOException e) {
      throw new XPathException(this, LuceneModule.EXXQDYFT0002, "IO error while reading document " + args[0].getStringValue());
View Full Code Here

            if (doc == null) {
                throw new XPathException("Document " + path + " does not exist.");
            }

            // Retrieve Lucene
            LuceneIndexWorker index = (LuceneIndexWorker) context.getBroker()
                    .getIndexController().getWorkerByIndexId(LuceneIndex.ID);

            // Note: code order is important here,
            index.setDocument(doc, StreamListener.REMOVE_BINARY);

            index.flush();

        } catch (Exception ex) { // PermissionDeniedException
            throw new XPathException(ex);

        } finally {
View Full Code Here

      // Verify the document actually exists
      if (doc == null) {
          throw new XPathException("Document " + path + " does not exist.");
      }
     
      LuceneIndexWorker index = (LuceneIndexWorker)
        context.getBroker().getIndexController().getWorkerByIndexId(LuceneIndex.ID);
      return new BooleanValue(index.hasIndex(doc.getDocId()));
    } catch (PermissionDeniedException e) {
      throw new XPathException(this, LuceneModule.EXXQDYFT0001, e.getMessage());
    } catch (URISyntaxException e) {
      throw new XPathException(this, LuceneModule.EXXQDYFT0003, e.getMessage());
    } catch (IOException e) {
View Full Code Here

    public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {

        DocumentImpl doc = null;
        try {
          // Retrieve Lucene
            LuceneIndexWorker index = (LuceneIndexWorker) context.getBroker()
                    .getIndexController().getWorkerByIndexId(LuceneIndex.ID);
           
          if (isCalledAs("index")) {
              // Get first parameter, this is the document
              String path = args[0].itemAt(0).getStringValue();
 
              // Retrieve document from database
              doc = context.getBroker().getXMLResource(XmldbURI.xmldbUriFor(path), Lock.READ_LOCK);
 
              // Verify the document actually exists
              if (doc == null) {
                  throw new XPathException("Document " + path + " does not exist.");
              }
 
              boolean flush = args.length == 2 || args[2].effectiveBooleanValue();
 
              // Note: code order is important here,
              index.setDocument(doc, StreamListener.STORE);
              index.setMode(StreamListener.STORE);
 
              // Get 'solr' node from second parameter
              NodeValue descriptor = (NodeValue) args[1].itemAt(0);
             
              // Pas document and index instructions to indexer
              index.indexNonXML(descriptor);
             
              if (flush) {
                // Make sure things are written
                index.writeNonXML();
              }
          } else {
            // "close"
            index.writeNonXML();
          }

        } catch (Exception ex) { // PermissionDeniedException
            logger.error(ex.getMessage(), ex);
            throw new XPathException(ex);
View Full Code Here

              query = args[0].itemAt(0).getStringValue();
            else
              query = args[1].itemAt(0).getStringValue();

            // Get the lucene worker
            LuceneIndexWorker index = (LuceneIndexWorker) context.getBroker()
                    .getIndexController().getWorkerByIndexId(LuceneIndex.ID);

            // Perform search
            report = index.search(context, toBeMatchedURIs, query);


        } catch (XPathException ex) {
            // Log and rethrow
            logger.error(ex);
View Full Code Here

    public NodeSet preSelect(Sequence contextSequence, boolean useContext) throws XPathException {
        long start = System.currentTimeMillis();
        // the expression can be called multiple times, so we need to clear the previous preselectResult
        preselectResult = null;
        LuceneIndexWorker index = (LuceneIndexWorker)
                context.getBroker().getIndexController().getWorkerByIndexId(LuceneIndex.ID);
        String field = getArgument(0).eval(contextSequence).getStringValue();
        DocumentSet docs = contextSequence.getDocumentSet();
        Item query = getKey(contextSequence, null);
        Properties options = parseOptions(contextSequence, null);
        try {
            if (Type.subTypeOf(query.getType(), Type.ELEMENT))
                preselectResult = index.queryField(context, getExpressionId(), docs, useContext ? contextSequence.toNodeSet() : null,
                    field, (Element) ((NodeValue)query).getNode(), NodeSet.DESCENDANT, options);
            else
                preselectResult = index.queryField(context, getExpressionId(), docs, useContext ? contextSequence.toNodeSet() : null,
                    field, query.getStringValue(), NodeSet.DESCENDANT, options);
        } catch (IOException | ParseException e) {
            throw new XPathException(this, "Error while querying full text index: " + e.getMessage(), e);
        }
        LOG.debug("Lucene query took " + (System.currentTimeMillis() - start));
View Full Code Here

          NodeSet contextSet = null;
          if (contextSequence != null)
            contextSet = contextSequence.toNodeSet();
         
          LuceneIndexWorker index = (LuceneIndexWorker)
            context.getBroker().getIndexController().getWorkerByIndexId(LuceneIndex.ID);
          Properties options = parseOptions(contextSequence, contextItem);
          try {
            if (Type.subTypeOf(query.getType(), Type.ELEMENT))
              result = index.queryField(context, getExpressionId(), docs, contextSet, field,
                  (Element)((NodeValue)query).getNode(), NodeSet.ANCESTOR, options);
            else
              result = index.queryField(context, getExpressionId(), docs, contextSet, field,
                  query.getStringValue(), NodeSet.ANCESTOR, options);
            } catch (IOException | ParseException e) {
            throw new XPathException(this, e.getMessage());
          }
          if( context.getProfiler().traceFunctions() ) {
View Full Code Here

TOP

Related Classes of org.exist.indexing.lucene.LuceneIndexWorker

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.