Package org.hibernate.search.jpa

Examples of org.hibernate.search.jpa.FullTextQuery


            // We'll fetch a little bit more in case there were extra activities
            // thrown on top.
            pageSize *= pageSizeMultiplierForSubsequentPages;
        }

        FullTextQuery query = searchRequestBuilder.buildQueryFromNativeSearchString(searchQuery);
        query.setSort(new Sort("id", true));
        List<Long> results = new ArrayList<Long>();
        int totalResults = 0;
        int batchSize = 0;
        do
        {
            // get the page size results - don't trust the previous offset in
            // case new activities were added on top
            if (log.isTraceEnabled())
            {
                log.trace("Preparing a query - search: '" + searchQuery + "'; paging:[0," + (pageSize - 1) + "]");
            }

            searchRequestBuilder.setPaging(query, 0, pageSize - 1);

            List<Long> queryResults = query.getResultList();
            if (totalResults == 0)
            {
                // only need to fetch this once - it describes the total results
                // regardless of paging
                totalResults = query.getResultSize();
            }
            batchSize = queryResults.size();

            if (log.isTraceEnabled())
            {
View Full Code Here


        long userPersonId = inActionContext.getPrincipal().getId();

        // build and parse the query, set its paging
        String nativeLuceneQuery = queryBuilder.buildNativeQuery(searchText, currentRequest.getWeightedField(),
                userPersonId);
        FullTextQuery query;
        // don't bubble up exceptions that occur from invalid search terms - this is annoying for as-you-type results
        try
        {
            query = searchRequestBuilder.buildQueryFromNativeSearchString(nativeLuceneQuery);
        }
        catch (Exception ex)
        {
            return new PagedSet<ModelView>(currentRequest.getStartIndex(), currentRequest.getEndIndex(), 0,
                    new ArrayList<ModelView>());
        }
        searchRequestBuilder.setPaging(query, currentRequest.getStartIndex(), currentRequest.getEndIndex());

        // get the results before query.getResultSize() is called for performance (it avoids a second search)
        List<ModelView> results = query.getResultList();

        // populate any transient properties
        transientPropertyPopulator.populateTransientProperties(results, userPersonId, searchText);

        // get the paged set, getting the total now that we've already made the query
        PagedSet<ModelView> pagedResults = new PagedSet<ModelView>(currentRequest.getStartIndex(), currentRequest
                .getEndIndex(), query.getResultSize(), results);

        // set the elapsed time
        String elapsedTime = formatElapasedTime(startTime, System.currentTimeMillis());
        pagedResults.setElapsedTime(elapsedTime);
View Full Code Here

        if (log.isTraceEnabled())
        {
            log.trace("Searching for " + maxResults + " people and groups with Lucene query: " + searchText);
        }

        FullTextQuery query = searchRequestBuilder.buildQueryFromNativeSearchString(searchText);

        searchRequestBuilder.setPaging(query, 0, maxResults);

        // get the model views (via the injected cache transformer)
        List<ModelView> searchResults = query.getResultList();

        if (log.isTraceEnabled())
        {
            log.trace("Found " + searchResults.size() + " search results");
        }
View Full Code Here

            log.debug("No search term found");
            return null;
        }

        String luceneQuery = "";
        FullTextQuery query = null;

        for (Entry<String, String> entry : requestToField.entrySet())
        {
            String req = entry.getKey();

            if (jsonQuery.containsKey(req))
            {
                String searchWord = jsonQuery.getString(req);
                // remove colons, which can be used to search other fields
                searchWord = searchWord.replace(":", "");

                if (transformers.containsKey(req))
                {
                    searchWord = (String) transformers.get(req).transform(jsonQuery, userEntityId);
                }

                // if this is activity content - keep track of it for special content-only handling
                if (req.toLowerCase().equals("keywords"))
                {
                    if (searchWord.contains("NOT ") || searchWord.contains("!") || searchWord.contains("-"))
                    {
                        // searching content with a NOT component
                        log.info("User is querying for activity content with:(" + searchWord
                                + ") and seems to be using a NOT/!/- component.  Lucene doesn't allow "
                                + "NOT queries with one component, so I'll add a constant keyword that "
                                + "I know is present: " + Activity.CONSTANT_KEYWORD_IN_EVERY_ACTIVITY_CONTENT);

                        luceneQuery += "+" + entry.getValue() + ":("
                                + Activity.CONSTANT_KEYWORD_IN_EVERY_ACTIVITY_CONTENT + " " + searchWord + ") ";
                    }
                    else
                    {
                        // searching content without NOT component
                        luceneQuery += "+" + entry.getValue() + ":(" + searchWord + ") ";
                    }
                }
                else
                {
                    // searching non-content
                    luceneQuery += "+" + entry.getValue() + ":(" + searchWord + ") ";
                }
            }
        }

        if (luceneQuery.length() == 0)
        {
            log.debug("Returning all activity");
            query = unstemmedRequestBuilder.buildQueryFromNativeSearchString("_hibernate_class:"
                    + "org.eurekastreams.server.domain.stream.Activity");
        }
        else
        {
            // don't let query parsing throw an exception that bubbles out to the client - it could be from an
            // incomplete as-you-type search
            try
            {
                query = searchRequestBuilder.buildQueryFromNativeSearchString(luceneQuery);
            }
            catch (Exception ex)
            {
                return new ArrayList<Long>();
            }
        }

        if (jsonQuery.containsKey("sortBy"))
        {
            query.setSort(new Sort(new SortField(jsonQuery.getString("sortBy"), true)));
        }

        if (log.isDebugEnabled())
        {
            log.debug("Native Lucene Query: " + query.toString());
        }

        searchRequestBuilder.setPaging(query, 0, maxResults);

        List<Long> activityIds = query.getResultList();
        if (log.isInfoEnabled())
        {
            log.info("Found " + activityIds.size() + " activities");
        }
        return activityIds;
View Full Code Here

            }

            String luceneQueryString = String.format(query.toString(), inRequest.getSearchString());
            org.apache.lucene.search.Query luceneQuery = parser.parse(luceneQueryString);

            FullTextQuery fullTextQuery = sessionEntityManager.createFullTextQuery(luceneQuery, inRequest
                    .getObjectType());

            fullTextQuery.setFirstResult(inRequest.getFirstResult());
            fullTextQuery.setMaxResults(inRequest.getMaxResults());

            SortField[] fields = new SortField[inRequest.getSortFields().size()];

            for (int i = 0; i < inRequest.getSortFields().size(); i++)
            {
                fields[i] = new SortField(inRequest.getSortFields().get(i), true);
            }

            Sort sort = new Sort(fields);

            fullTextQuery.setSort(sort);

            results = fullTextQuery.getResultList();

            /**
             * GWT can't serialize EMPTY_LIST.
             */
            if (results.equals(Collections.EMPTY_LIST))
            {
                results = new ArrayList<T>();
            }

            pagedSet = new PagedSet<T>(inRequest.getFirstResult(), inRequest.getFirstResult() + results.size() - 1,
                    fullTextQuery.getResultSize(), results);
        }
        catch (ParseException e)
        {
            log.error(e);
        }
View Full Code Here

            return false;
        }

        // search for groups with the input
        String luceneQuery = String.format("+id:(%d) +followerAndCoordinatorIds:(%d)", domainGroupId, personId);
        FullTextQuery query = searchRequestBuilder.buildQueryFromNativeSearchString(luceneQuery);

        // if we receive one result, the user is a coordinator or follower of the group
        return query.getResultSize() == 1;
    }
View Full Code Here

    );

    org.apache.lucene.search.Query luceneQuery;
    luceneQuery = parser.parse( searchQuery );

    final FullTextQuery query = ftEm.createFullTextQuery( luceneQuery, Book.class );

    return query;
  }
View Full Code Here

                boostPerField);

        org.apache.lucene.search.Query luceneQuery;
        luceneQuery = parser.parse(searchQuery);

        final FullTextQuery query = ftEm.createFullTextQuery(luceneQuery, Book.class);

        return query;
    }
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.