Package org.hibernate.search.jpa

Examples of org.hibernate.search.jpa.FullTextQuery


    }

    public List<HProject> searchProjects(@Nonnull String searchQuery,
            int maxResult, int firstResult, boolean includeObsolete)
            throws ParseException {
        FullTextQuery query = getTextQuery(searchQuery, includeObsolete);
        return query.setMaxResults(maxResult).setFirstResult(firstResult)
                .getResultList();
    }
View Full Code Here


                .getResultList();
    }

    public int getQueryProjectSize(@Nonnull String searchQuery,
            boolean includeObsolete) throws ParseException {
        FullTextQuery query = getTextQuery(searchQuery, includeObsolete);
        return query.getResultSize();
    }
View Full Code Here

  }
 
  @SuppressWarnings("unchecked")
  @Override
  public List<Project> searchByName(String searchTerm, Integer limit, Integer offset) {
    FullTextQuery query = getSearchByNameQuery(searchTerm);
   
    // Sort
    List<SortField> sortFields = ImmutableList.<SortField>builder()
        .add(new SortField(Project.NAME_SORT_FIELD_NAME, SortField.STRING))
        .build();
    query.setSort(new Sort(sortFields.toArray(new SortField[sortFields.size()])));
   
    if (offset != null) {
      query.setFirstResult(offset);
    }
    if (limit != null) {
      query.setMaxResults(limit);
    }
   
    return (List<Project>) query.getResultList();
  }
View Full Code Here

  }
 
  @SuppressWarnings("unchecked")
  @Override
  public List<Artifact> searchByName(String searchTerm, ArtifactDeprecationStatus deprecation, Integer limit, Integer offset) {
    FullTextQuery query = getSearchByNameQuery(searchTerm, deprecation);
   
    // Sort
    List<SortField> sortFields = ImmutableList.<SortField>builder()
        .add(new SortField(Binding.artifact().group().getPath() + '.' + ArtifactGroup.GROUP_ID_SORT_FIELD_NAME, SortField.STRING))
        .add(new SortField(Artifact.ARTIFACT_ID_SORT_FIELD_NAME, SortField.STRING))
        .build();
    query.setSort(new Sort(sortFields.toArray(new SortField[sortFields.size()])));
   
    if (offset != null) {
      query.setFirstResult(offset);
    }
    if (limit != null) {
      query.setMaxResults(limit);
    }
   
    return (List<Artifact>) query.getResultList();
  }
View Full Code Here

  }
 
  @SuppressWarnings("unchecked")
  @Override
  public List<User> search(String searchTerm, Integer limit, Integer offset) {
    FullTextQuery query = getSearchQuery(searchTerm);
   
    query.setSort(new Sort(new SortField(Binding.user().userName().getPath(), SortField.STRING)));
   
    if (offset != null) {
      query.setFirstResult(offset);
    }
    if (limit != null) {
      query.setMaxResults(limit);
    }
   
    return (List<User>) query.getResultList();
  }
View Full Code Here

  }
 
  @SuppressWarnings("unchecked")
  @Override
  public List<Artifact> searchRecommended(String searchTerm, Integer limit, Integer offset) throws ServiceException {
    FullTextQuery query = getSearchRecommendedQuery(searchTerm);
    if (query == null) {
      return Lists.newArrayListWithExpectedSize(0);
    }
   
    // Sort
    List<SortField> sortFields = ImmutableList.<SortField>builder()
        .add(new SortField(Binding.artifact().followersCount().getPath(), SortField.LONG, true))
        .add(new SortField(Binding.artifact().group().getPath() + '.' + ArtifactGroup.GROUP_ID_SORT_FIELD_NAME, SortField.STRING))
        .add(new SortField(Artifact.ARTIFACT_ID_SORT_FIELD_NAME, SortField.STRING))
        .build();
   
    query.setSort(new Sort(sortFields.toArray(new SortField[sortFields.size()])));
   
    if (offset != null) {
      query.setFirstResult(offset);
    }
    if (limit != null) {
      query.setMaxResults(limit);
    }
   
    return (List<Artifact>) query.getResultList();
  }
View Full Code Here

    return (List<Artifact>) query.getResultList();
  }
 
  @Override
  public int countSearchRecommended(String searchTerm) throws ServiceException {
    FullTextQuery query = getSearchRecommendedQuery(searchTerm);
    if (query == null) {
      return 0;
    }
    return query.getResultSize();
  }
View Full Code Here

        return ( searchResults != null ) && ( currentPage == 0 );
    }

    @SuppressWarnings("unchecked")
    private void updateResults() {
        FullTextQuery query;
        try {
            query = searchQuery(searchQuery);
        } catch (ParseException pe) {
            return;
        }
     
        List<Product> items = query
            .setMaxResults(pageSize + 1)
            .setFirstResult(pageSize * currentPage)
            .getResultList();
        numberOfResults = query.getResultSize();
       
        if (items.size() > pageSize) {
            searchResults = new ArrayList(items.subList(0, pageSize));
            hasMore = true;
        } else {
View Full Code Here

        // Use the TextFlowTarget index
        Query textQuery =
                generateQuery(query, sourceLocale, targetLocale, queryText,
                        multiQueryText, IndexFieldLabels.TF_CONTENT_FIELDS);

        FullTextQuery ftQuery =
                entityManager.createFullTextQuery(textQuery, entities);

        ftQuery.setProjection(FullTextQuery.SCORE, FullTextQuery.THIS);

        if (maxResult > 0) {
            ftQuery.setMaxResults(maxResult);
        }

        if (sortByDate) {
            ftQuery.setSort(lastChangedSort);
        }

        return (List<Object[]>) ftQuery.getResultList();
    }
View Full Code Here

                                IndexFieldLabels.CONTENT_STATE_FIELD,
                                ContentState.New.toString()));
                targetQuery.add(approvedStateQuery, Occur.MUST_NOT);
            }

            FullTextQuery ftQuery =
                    entityManager.createFullTextQuery(targetQuery,
                            HTextFlowTarget.class);
            @SuppressWarnings("unchecked")
            List<HTextFlowTarget> matchedTargets =
                    (List<HTextFlowTarget>) ftQuery.getResultList();
            log.info("got {} HTextFLowTarget results", matchedTargets.size());
            for (HTextFlowTarget htft : matchedTargets) {
                // manually check for case sensitive matches
                if (!constraints.isCaseSensitive()
                        || (contentIsValid(htft.getContents(), constraints))) {
                    if (!htft.getTextFlow().getDocument().isObsolete()) {
                        resultList.add(htft.getTextFlow());
                    }
                }
            }
        }

        if (constraints.isSearchInSource()) {
            // Source locale
            // NB: Assume the first document's locale, or the same target locale
            // if there are no documents
            // TODO Move source locale to the Project iteration level
            LocaleId sourceLocaleId = localeId;
            HProjectIteration projectIteration =
                    projectIterationDAO.getBySlug(projectSlug, iterationSlug);
            if (!projectIteration.getDocuments().isEmpty()) {
                sourceLocaleId =
                        projectIteration.getDocuments().values().iterator()
                                .next().getLocale().getLocaleId();
            }

            // Content query for source
            String sourceAnalyzerName =
                    TextContainerAnalyzerDiscriminator
                            .getAnalyzerDefinitionName(sourceLocaleId.getId());
            Analyzer sourceAnalyzer =
                    entityManager.getSearchFactory().getAnalyzer(
                            sourceAnalyzerName);

            Query srcContentPhraseQuery;
            QueryParser srcContentQueryParser =
                    new MultiFieldQueryParser(Version.LUCENE_29,
                            IndexFieldLabels.CONTENT_FIELDS, sourceAnalyzer);
            try {
                srcContentPhraseQuery =
                        srcContentQueryParser.parse("\""
                                + QueryParser.escape(constraints
                                        .getSearchString()) + "\"");
            } catch (ParseException e) {
                throw new ZanataServiceException("Failed to parse query", e);
            }

            // Source Query
            BooleanQuery sourceQuery = new BooleanQuery();
            sourceQuery.add(projectQuery, Occur.MUST);
            sourceQuery.add(iterationQuery, Occur.MUST);
            sourceQuery.add(srcContentPhraseQuery, Occur.MUST);
            if (documentsQuery.getTermArrays().size() > 0) {
                sourceQuery.add(documentsQuery, Occur.MUST);
            }

            FullTextQuery ftQuery =
                    entityManager.createFullTextQuery(sourceQuery,
                            HTextFlow.class);
            @SuppressWarnings("unchecked")
            List<HTextFlow> matchedSources =
                    (List<HTextFlow>) ftQuery.getResultList();
            log.info("got {} HTextFLow results", matchedSources.size());
            for (HTextFlow htf : matchedSources) {
                if (!resultList.contains(htf)) {
                    // manually check for case sensitive matches
                    if (!constraints.isCaseSensitive()
View Full Code Here

TOP

Related Classes of org.hibernate.search.jpa.FullTextQuery

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.