Package org.apache.lucene.queryParser

Examples of org.apache.lucene.queryParser.MultiFieldQueryParser


    @Override
    @SuppressWarnings("unchecked")
    @Transactional(readOnly = true)
    public <T extends DomainEntity> List<T> search(Class<T> clazz, String field, String query, int offset, int number) {
        FullTextEntityManager fullTextEntityManager = Search.createFullTextEntityManager(getEntityManager());
        MultiFieldQueryParser parser = new MultiFieldQueryParser(getAllIndexedFields(clazz, field), new StandardAnalyzer());
        try {
            org.apache.lucene.search.Query parsedquery = parser.parse(query.trim().replaceAll(" ", "* ") + "*");
            FullTextQuery hq = fullTextEntityManager.createFullTextQuery(parsedquery, clazz);
            hq.setMaxResults(number > 0 ? number : MAX_RESULTS);
            hq.setFirstResult(offset > 0 ? offset : 0);
            return hq.getResultList();
        } catch (Exception ex) {
View Full Code Here


  }

  private Query buildQuery(String search, String... fields) {
    Query query = null;
    try {
      MultiFieldQueryParser parser = new MultiFieldQueryParser(fields,
          new StandardAnalyzer());
      if (search != null && !search.trim().equals("")) {
        StringBuffer cds = new StringBuffer();
        // 分词并构造组合查询条件
        final String[] tmp_conditions = search.split(" ");
        int index = 0;
        for (final String c : tmp_conditions) {
          if (c.equals("")) {
            continue;
          }
          if (index > 0) {
            cds.append(" AND ");
          }
          cds.append("(" + c + ")");
          index++;
        }
        query = parser.parse(cds.toString());

      }
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
View Full Code Here

  @Transactional(type = TransactionalType.READOLNY)
  public List<Song> search(String condition,String artistCityId) {
    try {
      BooleanQuery booleanQuery = new BooleanQuery();
      MultiFieldQueryParser parser = new MultiFieldQueryParser(
          new String[] { "name", "lyric" }, new StandardAnalyzer());
      Query query;
      query = parser.parse(condition);
      booleanQuery.add(query, BooleanClause.Occur.MUST);
      if(artistCityId != null){
        TermQuery tq = new TermQuery(new Term("artistCityId", artistCityId));
        booleanQuery.add(tq, BooleanClause.Occur.MUST);
      }
View Full Code Here

      Assert.notNull(clazz);
      Assert.hasText(query);
        try {
            FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(getEntityManager());
            List<String> indexedFields = getAllIndexedFields(clazz, "");
            MultiFieldQueryParser parser = new MultiFieldQueryParser(indexedFields.toArray(new String[indexedFields.size()]), new StandardAnalyzer());
            FullTextQuery hq = fullTextEntityManager.createFullTextQuery(parser.parse(query.trim().replaceAll(" ", "* ") + "*"), clazz);
            hq.setMaxResults(number > 0 ? number : MAX_RESULTS);
            hq.setFirstResult(offset > 0 ? offset : 0);
            return hq.getResultList();
        } catch (Exception ex) {
            throw new IWebMvcException("Could not perform search", ex);
View Full Code Here

      {
         Map<String,Float> boostPerField = new HashMap<String,Float>();
         boostPerField.put( "title:en", 4f );
         boostPerField.put( "body:en", 1f );
         String[] productFields = {"title:en", "body:en"};
         QueryParser parser = new MultiFieldQueryParser(productFields, new StandardAnalyzer(), boostPerField);
         parser.setAllowLeadingWildcard(true);
         org.apache.lucene.search.Query luceneQuery;
         try
         {
            luceneQuery = parser.parse(searchPattern);
         }
         catch (ParseException e)
         {
            return null;
         }
View Full Code Here

        boostPerField.put("description", 2f);
        boostPerField.put("actors.name", 2f);
        boostPerField.put("categories.name", 0.5f);

        String[] productFields = {"title", "description", "actors.name", "categories.name"};
        QueryParser parser = new MultiFieldQueryParser(productFields, new StandardAnalyzer(), boostPerField);
        parser.setAllowLeadingWildcard(true);
        org.apache.lucene.search.Query luceneQuery;
        luceneQuery = parser.parse(searchQuery);
        return ( (FullTextEntityManager) em ).createFullTextQuery(luceneQuery, Product.class);
    }
View Full Code Here

          checkIsIndexUpToDate();
        }     
      }
      log.info("queryString=" + queryString);
     
      QueryParser queryParser = new MultiFieldQueryParser(Version.LUCENE_CURRENT, fields, analyzer);
      queryParser.setLowercaseExpandedTerms(false);//some add. fields are not tokenized and not lowered case
      Query query = queryParser.parse(queryString);
      try {
        query = searcher.rewrite(query);
      } catch (Exception ex) {
        throw new QueryException("Rewrite-Exception query because too many clauses. Query=" + query);
      }
View Full Code Here

    int arraySize = indexedFields.size();
    String indexedArray[] = new String[arraySize];
    for (int ii = 0; ii < arraySize; ii++) {
      indexedArray[ii] = indexedFields.get(ii);
    }
    MultiFieldQueryParser parser = new MultiFieldQueryParser(Version.LUCENE_CURRENT, indexedArray, analyzer);
    query = parser.parse(queryString);
    message("Searching for: " + query.toString());
    return (query);

  }
View Full Code Here

    int arraySize = fields.size();
    fieldsArray = new String[arraySize];
    for (int ii = 0; ii < arraySize; ii++) {
      fieldsArray[ii] = fields.get(ii);
    }
    MultiFieldQueryParser parser = new MultiFieldQueryParser(Version.LUCENE_CURRENT, fieldsArray, analyzer);
    query = parser.parse(queryString);
    System.out.println("Searching for: " + query.toString());
  }
View Full Code Here

    {
        List<RepositoryContentIndex> indexes = getHashcodeIndexes( principal, selectedRepos );

        try
        {
            QueryParser parser = new MultiFieldQueryParser( new String[]{HashcodesKeys.MD5, HashcodesKeys.SHA1},
                                           new HashcodesHandlers().getAnalyzer() );
            LuceneQuery query = new LuceneQuery( parser.parse( checksum ) );
            SearchResults results = searchAll( query, limits, indexes, null );
            results.getRepositories().addAll( this.localIndexedRepositories );

            return results;
        }
View Full Code Here

TOP

Related Classes of org.apache.lucene.queryParser.MultiFieldQueryParser

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.