Examples of QueryParser


Examples of org.apache.clerezza.rdf.core.sparql.QueryParser

    return this.selectedScheme;
  }

  @Override
  public Graph retrieveConcepts(String searchTerm) {
    QueryParser queryParser = QueryParser.getInstance();

    String query = "PREFIX owl: <http://www.w3.org/2002/07/owl#> " +
        "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> " +
        "PREFIX skos: <http://www.w3.org/2008/05/skos#> " +
        "CONSTRUCT {?concept a skos:Concept; skos:prefLabel ?prefLabel; " +
        "rdfs:comment ?comment; owl:sameAs ?sameConcept .} " +
        "WHERE {?concept skos:inScheme " + selectedScheme.toString() +
        "; skos:prefLabel ?prefLabel . " +
        "OPTIONAL { ?concept skos:altLabel ?altLabel .} " +
        "OPTIONAL { ?concept rdfs:comment ?comment .} " +
        "OPTIONAL { ?concept owl:sameAs ?sameConcept .} " +
        "FILTER (REGEX(STR(?prefLabel), '" +
        searchTerm + "', 'i') || REGEX(STR(?altLabel), '" +
        searchTerm + "', 'i'))}";

    ConstructQuery constructQuery;
    try {
      constructQuery = (ConstructQuery) queryParser.parse(query);
    } catch (ParseException ex) {
      throw new RuntimeException(ex);
    }

    MGraph defaultGraph = contentGraphProvider.getContentGraph();
View Full Code Here

Examples of org.apache.jackrabbit.core.query.lucene.fulltext.QueryParser

                tmp.append(nsMappings.getPrefix(propName.getNamespaceURI()));
                tmp.append(":").append(FieldNames.FULLTEXT_PREFIX);
                tmp.append(propName.getLocalName());
                fieldname = tmp.toString();
            }
            QueryParser parser = new QueryParser(fieldname, analyzer);
            parser.setOperator(QueryParser.DEFAULT_OPERATOR_AND);
            // replace unescaped ' with " and escaped ' with just '
            StringBuffer query = new StringBuffer();
            String textsearch = node.getQuery();
            // the default lucene query parser recognizes 'AND' and 'NOT' as
            // keywords.
            textsearch = textsearch.replaceAll("AND", "and");
            textsearch = textsearch.replaceAll("NOT", "not");
            boolean escaped = false;
            for (int i = 0; i < textsearch.length(); i++) {
                if (textsearch.charAt(i) == '\\') {
                    if (escaped) {
                        query.append("\\\\");
                        escaped = false;
                    } else {
                        escaped = true;
                    }
                } else if (textsearch.charAt(i) == '\'') {
                    if (escaped) {
                        query.append('\'');
                        escaped = false;
                    } else {
                        query.append('\"');
                    }
                } else {
                    if (escaped) {
                        query.append('\\');
                        escaped = false;
                    }
                    query.append(textsearch.charAt(i));
                }
            }
            Query context = parser.parse(query.toString());
            if (relPath != null && (!node.getReferencesProperty() || relPath.getLength() > 1)) {
                // text search on some child axis
                Path.PathElement[] elements = relPath.getElements();
                for (int i = elements.length - 1; i >= 0; i--) {
                    String name = null;
View Full Code Here

Examples of org.apache.lucene.queryParser.QueryParser

        StringTokenizer st = new StringTokenizer(params.getSearchKey());
        while(st.hasMoreElements()){
          String q = st.nextToken();
      String[] indexFields = searching.getIndexFields();
      for(int i=0;i<indexFields.length;i++){
        QueryParser qp = new QueryParser(indexFields[i], analyzer);
        try{
          Query subjectQuery = qp.parse(q);
          comboQuery.add(subjectQuery, BooleanClause.Occur.SHOULD);
          _query_count ++;
        }catch(Exception e){
          log.error("Add query parameter failed. key="+q, e);
        }
View Full Code Here

Examples of org.apache.lucene.queryParser.QueryParser

            // take a reference as the searcher may change
            Searcher searcher = access.searcher;
            // reuse the same analyzer; it's thread-safe;
            // also allows subclasses to control the analyzer used.
            Analyzer analyzer = access.writer.getAnalyzer();
            QueryParser parser = new QueryParser(Version.LUCENE_30,
                    LUCENE_FIELD_DATA, analyzer);
            Query query = parser.parse(text);
            // Lucene 3 insists on a hard limit and will not provide
            // a total hits value. Take at least 100 which is
            // an optimal limit for Lucene as any more
            // will trigger writing results to disk.
            int maxResults = (limit == 0 ? 100 : limit) + offset;
View Full Code Here

Examples of org.apache.lucene.queryParser.QueryParser

  }
 
  public void testQueryWithScore() throws Exception{
    BrowseRequest br=new BrowseRequest();
    br.setShowExplanation(false)// default
      QueryParser parser=new QueryParser(Version.LUCENE_29,"color",new StandardAnalyzer(Version.LUCENE_29));
      br.setQuery(parser.parse("color:red OR shape:square"));
        br.setCount(10);
        br.setOffset(0);
       
        br.setSort(new SortField[]{SortField.FIELD_SCORE});
        BrowseResult res = doTest(br,4,null,new String[]{"1","7","2","5"});
View Full Code Here

Examples of org.apache.lucene.queryParser.QueryParser

  }

  public void testBrowseWithQuery(){
    try{
      BrowseRequest br=new BrowseRequest();
      QueryParser parser=new QueryParser(Version.LUCENE_29,"shape",new StandardAnalyzer(Version.LUCENE_29));
      br.setQuery(parser.parse("square OR circle"));
        br.setCount(10);
        br.setOffset(0);
       
        BrowseSelection sel=new BrowseSelection("color");
        sel.addValue("red");
View Full Code Here

Examples of org.apache.lucene.queryParser.QueryParser

//    System.out.println("request after conversion to msg:\n" + req.toString());
    String reqString = TextFormat.printToString(req);
    reqString = reqString.replace('\r', ' ').replace('\n', ' ');
//    System.out.println(reqString);
    Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_CURRENT);
    QueryParser _qparser = new QueryParser(Version.LUCENE_CURRENT,"", analyzer);
//    System.out.println("msg to req");
    BrowseRequest boboReqAfter = BrowseProtobufConverter.convert(req, _qparser);
//    System.out.println("get query 2: "
//        + (boboReqAfter.getQuery() != null ? boboReqAfter.getQuery().getClass()
//            : "null query"));
View Full Code Here

Examples of org.apache.lucene.queryParser.QueryParser

  }
 
  static void doBrowse(BoboBrowser browser) throws Exception
  {
    String q="java";
    QueryParser parser=new QueryParser(Version.LUCENE_CURRENT,"b",new StandardAnalyzer(Version.LUCENE_CURRENT));
    Query query=parser.parse(q);
    BrowseRequest br=new BrowseRequest();
    //br.setQuery(query);
    br.setOffset(0);
    br.setCount(0);
View Full Code Here

Examples of org.apache.lucene.queryParser.QueryParser

          }
        }
 
        // Check whether the document is in the index
        Analyzer analyzer = new WhitespaceAnalyzer();
        QueryParser parser = new QueryParser(Version.LUCENE_30, "url", analyzer);
        String queryString = "\"" + transformedFileUrl + "\"";
       
        try {
          query = parser.parse(queryString);
        } catch (ParseException ex) {
          throw new RegainException("Parsing of url lookup-query failed.", ex);
        }
       
        ScoreDoc[] hits = manager.search(query);
View Full Code Here

Examples of org.apache.lucene.queryParser.QueryParser

          for (int k = 0; k < indexConfigs.length; k++) {

            String[] searchFieldArr = indexConfigs[k].getSearchFieldList();
            for (int i = 0; i < searchFieldArr.length; i++) {

              QueryParser parser = new QueryParser(Version.LUCENE_30, searchFieldArr[i], mAnalyzer);
              parser.setDefaultOperator(QueryParser.AND_OPERATOR);
              parser.setAllowLeadingWildcard(true);
              Query fieldQuery = parser.parse(queryText);

              // Add as OR
              mQuery.add(fieldQuery, Occur.SHOULD);
            }
            //System.out.println("Query: '" + queryText + "' -> '" + mQuery.toString() + "'");
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.