Package org.dspace.search

Examples of org.dspace.search.QueryResults


   
    // Search the repository
        QueryArgs queryArgs = new QueryArgs();
        queryArgs.setQuery(query);
        queryArgs.setPageSize(Integer.MAX_VALUE);
        QueryResults results = DSQuery.doQuery(context, queryArgs);
       

        // Get a list of found items
        ArrayList<Item> items = new ArrayList<Item>();
        @SuppressWarnings("unchecked")
        java.util.List<String> handles = results.getHitHandles();
        for (String handle : handles)
        {
            DSpaceObject resultDSO = HandleManager.resolveToObject(context, handle);

            if (resultDSO instanceof Item)
View Full Code Here


  }

  private List<String> getHandles(String query) throws IOException {
    QueryArgs args = new QueryArgs();
    args.setQuery(query);
    QueryResults results = DSQuery.doQuery(context, args);
    return results.getHitHandles();
  }
View Full Code Here

                }

                qArgs.setQuery(query);

                // Perform the search
                QueryResults qResults = null;
                if (container == null)
                {
                        qResults = DSQuery.doQuery(context, qArgs);
                }
                else if (container instanceof Collection)
                {
                    qResults = DSQuery.doQuery(context, qArgs, (Collection)container);
                }
                else if (container instanceof Community)
                {
                    qResults = DSQuery.doQuery(context, qArgs, (Community)container);
                }
               
                // now instantiate the results
                DSpaceObject[] results = new DSpaceObject[qResults.getHitHandles().size()];
                for (int i = 0; i < qResults.getHitHandles().size(); i++)
                {
                    String myHandle = (String)qResults.getHitHandles().get(i);
                    DSpaceObject dso = HandleManager.resolveToObject(context, myHandle);
                    if (dso == null)
                    {
                        throw new SQLException("Query \"" + query
                                + "\" returned unresolvable handle: " + myHandle);
View Full Code Here

                arg.setSortOrder(SortOption.DESCENDING);
            } else {
                arg.setSortOrder(SortOption.ASCENDING);
            }

            QueryResults qre;

            /**
             * search can be performed only on community or collection selected
             * or all, not on the both in same time; check this requirement
             */
//            if (_community != null) {
//                qre = DSQuery.doQuery(context, arg, _community);
//            } else if (_collection != null) {
//                qre = DSQuery.doQuery(context, arg, _collection);
//            } else {
                qre = DSQuery.doQuery(context, arg);
//            }
            entities.add(new SearchResultsInfoEntity(qre.getHitCount(), qre.getHitTypes(), qre.getHitHandles(), qre.getHitIds()));

            /**
             * check returned objects, recognize them and put in result
             * list as expected
             */
            for (int x = 0; x < qre.getHitTypes().size(); x++) {
                switch ((Integer) (qre.getHitTypes().get(x))) {
                    case Constants.ITEM: {
//                            entities.add(idOnly ? new ItemEntityId(qre.getHitIds().get(x).toString(), context) : new ItemEntity(qre.getHitIds().get(x).toString(), context,1, uparams));
                    }
                    break;

View Full Code Here

        if (page > 1)
            queryArgs.setStart((Integer.valueOf(page) - 1) * queryArgs.getPageSize());
        else
            queryArgs.setStart(0);

        QueryResults qResults = null;
        if (scope instanceof Community)
        {
            qResults = DSQuery.doQuery(context, queryArgs, (Community) scope);
        }
        else if (scope instanceof Collection)
View Full Code Here

        // get the start of the query results page
        qArgs.setQuery(query);

        // Perform the search
        QueryResults qResults = null;
        if (container == null)
        {
                qResults = DSQuery.doQuery(context, qArgs);
        }
        else if (container instanceof Collection)
        {
            logInfo = "collection_id=" + container.getID() + ",";
            qResults = DSQuery.doQuery(context, qArgs, (Collection)container);
        }
        else if (container instanceof Community)
        {
            logInfo = "community_id=" + container.getID() + ",";
            qResults = DSQuery.doQuery(context, qArgs, (Community)container);
        }
       
        // now instantiate the results
        DSpaceObject[] results = new DSpaceObject[qResults.getHitHandles().size()];
        for (int i = 0; i < qResults.getHitHandles().size(); i++)
        {
            String myHandle = (String)qResults.getHitHandles().get(i);
            DSpaceObject dso = HandleManager.resolveToObject(context, myHandle);
            if (dso == null)
            {
                throw new SQLException("Query \"" + query
                        + "\" returned unresolvable handle: " + myHandle);
View Full Code Here

        Item[] resultsItems;
        Collection[] resultsCollections;
        Community[] resultsCommunities;

        QueryResults qResults = null;
        QueryArgs qArgs = new QueryArgs();
        SortOption sortOption = null;

        if (request.getParameter("etal") != null)
            qArgs.setEtAl(UIUtil.getIntParameter(request, "etal"));

        try
        {
            if (sortBy > 0)
            {
                sortOption = SortOption.getSortOption(sortBy);
                qArgs.setSortOption(sortOption);
            }

            if (SortOption.ASCENDING.equalsIgnoreCase(order))
            {
                qArgs.setSortOrder(SortOption.ASCENDING);
            }
            else
            {
                qArgs.setSortOrder(SortOption.DESCENDING);
            }
        }
        catch (Exception e)
        {
        }

        // Override the page setting if exporting metadata
        if ("submit_export_metadata".equals(UIUtil.getSubmitButton(request, "submit")))
        {
            qArgs.setPageSize(Integer.MAX_VALUE);
        }
        else if (rpp > 0)
        {
            qArgs.setPageSize(rpp);
        }
       
        // if the "advanced" flag is set, build the query string from the
        // multiple query fields
        if (advanced != null)
        {
            query = qArgs.buildQuery(request);
            advancedQuery = qArgs.buildHTTPQuery(request);
        }

        // Ensure the query is non-null
        if (query == null)
        {
            query = "";
        }

        // Get the location parameter, if any
        String location = request.getParameter("location");
        String newURL;

        // If there is a location parameter, we should redirect to
        // do the search with the correct location.
        if ((location != null) && !location.equals(""))
        {
            String url = "";

            if (!location.equals("/"))
            {
                // Location is a Handle
                url = "/handle/" + location;
            }

            // Encode the query
            query = URLEncoder.encode(query, Constants.DEFAULT_ENCODING);

            if (advancedQuery.length() > 0)
            {
                query = query + "&from_advanced=true&" + advancedQuery;
            }

            // Do the redirect
            response.sendRedirect(response.encodeRedirectURL(request
                    .getContextPath()
                    + url + "/simple-search?query=" + query));

            return;
        }

        // Build log information
        String logInfo = "";

        // Get our location
        Community community = UIUtil.getCommunityLocation(request);
        Collection collection = UIUtil.getCollectionLocation(request);

        // get the start of the query results page
        //        List resultObjects = null;
        qArgs.setQuery(query);
        qArgs.setStart(start);

        // Perform the search
        if (collection != null)
        {
            logInfo = "collection_id=" + collection.getID() + ",";

            // Values for drop-down box
            request.setAttribute("community", community);
            request.setAttribute("collection", collection);

            qResults = DSQuery.doQuery(context, qArgs, collection);
        }
        else if (community != null)
        {
            logInfo = "community_id=" + community.getID() + ",";

            request.setAttribute("community", community);

            // Get the collections within the community for the dropdown box
            request
                    .setAttribute("collection.array", community
                            .getCollections());

            qResults = DSQuery.doQuery(context, qArgs, community);
        }
        else
        {
            // Get all communities for dropdown box
            Community[] communities = Community.findAll(context);
            request.setAttribute("community.array", communities);

            qResults = DSQuery.doQuery(context, qArgs);
        }

        // now instantiate the results and put them in their buckets
        for (int i = 0; i < qResults.getHitTypes().size(); i++)
        {
            Integer myType = (Integer) qResults.getHitTypes().get(i);

            // add the handle to the appropriate lists
            switch (myType.intValue())
            {
            case Constants.ITEM:
                itemCount++;
                break;

            case Constants.COLLECTION:
                collCount++;
                break;

            case Constants.COMMUNITY:
                commCount++;
                break;
            }
        }

        // Make objects from the handles - make arrays, fill them out
        resultsCommunities = new Community[commCount];
        resultsCollections = new Collection[collCount];
        resultsItems = new Item[itemCount];

        collCount = 0;
        commCount = 0;
        itemCount = 0;

        for (int i = 0; i < qResults.getHitTypes().size(); i++)
        {
            Integer myId    = (Integer) qResults.getHitIds().get(i);
            String myHandle = (String) qResults.getHitHandles().get(i);
            Integer myType  = (Integer) qResults.getHitTypes().get(i);

            // add the handle to the appropriate lists
            switch (myType.intValue())
            {
            case Constants.ITEM:
                if (myId != null)
                {
                    resultsItems[itemCount] = Item.find(context, myId);
                }
                else
                {
                    resultsItems[itemCount] = (Item)HandleManager.resolveToObject(context, myHandle);
                }

                if (resultsItems[itemCount] == null)
                {
                    throw new SQLException("Query \"" + query
                            + "\" returned unresolvable item");
                }
                itemCount++;
                break;

            case Constants.COLLECTION:
                if (myId != null)
                {
                    resultsCollections[collCount] = Collection.find(context, myId);
                }
                else
                {
                    resultsCollections[collCount] = (Collection)HandleManager.resolveToObject(context, myHandle);
                }

                if (resultsCollections[collCount] == null)
                {
                    throw new SQLException("Query \"" + query
                            + "\" returned unresolvable collection");
                }

                collCount++;
                break;

            case Constants.COMMUNITY:
                if (myId != null)
                {
                    resultsCommunities[commCount] = Community.find(context, myId);
                }
                else
                {
                    resultsCommunities[commCount] = (Community)HandleManager.resolveToObject(context, myHandle);
                }

                if (resultsCommunities[commCount] == null)
                {
                    throw new SQLException("Query \"" + query
                            + "\" returned unresolvable community");
                }

                commCount++;
                break;
            }
        }

        // Log
        log.info(LogManager.getHeader(context, "search", logInfo + "query=\""
                + query + "\",results=(" + resultsCommunities.length + ","
                + resultsCollections.length + "," + resultsItems.length + ")"));

        // Pass in some page qualities
        // total number of pages
        int pageTotal = 1 + ((qResults.getHitCount() - 1) / qResults
                .getPageSize());

        // current page being displayed
        int pageCurrent = 1 + (qResults.getStart() / qResults.getPageSize());

        // pageLast = min(pageCurrent+9,pageTotal)
        int pageLast = ((pageCurrent + 9) > pageTotal) ? pageTotal
                : (pageCurrent + 9);

        // pageFirst = max(1,pageCurrent-9)
        int pageFirst = ((pageCurrent - 9) > 1) ? (pageCurrent - 9) : 1;

        // Pass the results to the display JSP
        request.setAttribute("items", resultsItems);
        request.setAttribute("communities", resultsCommunities);
        request.setAttribute("collections", resultsCollections);

        request.setAttribute("pagetotal", new Integer(pageTotal));
        request.setAttribute("pagecurrent", new Integer(pageCurrent));
        request.setAttribute("pagelast", new Integer(pageLast));
        request.setAttribute("pagefirst", new Integer(pageFirst));

        request.setAttribute("queryresults", qResults);

        // And the original query string
        request.setAttribute("query", query);

        request.setAttribute("order",  qArgs.getSortOrder());
        request.setAttribute("sortedBy", sortOption);

        if (AuthorizeManager.isAdmin(context))
        {
            // Set a variable to create admin buttons
            request.setAttribute("admin_button", new Boolean(true));
        }
       
        if ((fromAdvanced != null) && (qResults.getHitCount() == 0))
        {
            // send back to advanced form if no results
            Community[] communities = Community.findAll(context);
            request.setAttribute("communities", communities);
            request.setAttribute("no_results", "yes");
View Full Code Here

        Item[] resultsItems;
        Collection[] resultsCollections;
        Community[] resultsCommunities;

        QueryResults qResults = null;
        QueryArgs qArgs = new QueryArgs();

        // if the "advanced" flag is set, build the query string from the
        // multiple query fields
        if (advanced != null)
        {
            query = qArgs.buildQuery(request);
            advancedQuery = qArgs.buildHTTPQuery(request);
        }

        // Ensure the query is non-null
        if (query == null)
        {
            query = "";
        }

        // Get the location parameter, if any
        String location = request.getParameter("location");
        String newURL;

        // Build log information
        String logInfo = "";

        // Get our location
        Community community = UIUtil.getCommunityLocation(request);
        Collection collection = UIUtil.getCollectionLocation(request);

        // get the start of the query results page
        // List resultObjects = null;
        qArgs.setQuery(query);
        qArgs.setStart(start);

        // Perform the search
        if (collection != null)
        {
            logInfo = "collection_id=" + collection.getID() + ",";

            // Values for drop-down box
            request.setAttribute("community", community);
            request.setAttribute("collection", collection);

            qResults = DSQuery.doQuery(context, qArgs, collection);
        }
        else if (community != null)
        {
            logInfo = "community_id=" + community.getID() + ",";

            request.setAttribute("community", community);

            // Get the collections within the community for the dropdown box
            request
                    .setAttribute("collection.array", community
                            .getCollections());

            qResults = DSQuery.doQuery(context, qArgs, community);
        }
        else
        {
            // Get all communities for dropdown box
            Community[] communities = Community.findAll(context);
            request.setAttribute("community.array", communities);

            qResults = DSQuery.doQuery(context, qArgs);
        }

        // now instantiate the results and put them in their buckets
        for (int i = 0; i < qResults.getHitHandles().size(); i++)
        {
            String myHandle = (String) qResults.getHitHandles().get(i);
            Integer myType = (Integer) qResults.getHitTypes().get(i);

            // add the handle to the appropriate lists
            switch (myType.intValue())
            {
            case Constants.ITEM:
                itemHandles.add(myHandle);

                break;

            case Constants.COLLECTION:
                collectionHandles.add(myHandle);

                break;

            case Constants.COMMUNITY:
                communityHandles.add(myHandle);

                break;
            }
        }

        int numCommunities = communityHandles.size();
        int numCollections = collectionHandles.size();
        int numItems = itemHandles.size();

        // Make objects from the handles - make arrays, fill them out
        resultsCommunities = new Community[numCommunities];
        resultsCollections = new Collection[numCollections];
        resultsItems = new Item[numItems];

        for (int i = 0; i < numItems; i++)
        {
            String myhandle = (String) itemHandles.get(i);

            Object o = HandleManager.resolveToObject(context, myhandle);

            resultsItems[i] = (Item) o;

            if (resultsItems[i] == null)
            {
                throw new SQLException("Query \"" + query
                        + "\" returned unresolvable handle: " + myhandle);
            }
        }

        for (int i = 0; i < collectionHandles.size(); i++)
        {
            String myhandle = (String) collectionHandles.get(i);

            Object o = HandleManager.resolveToObject(context, myhandle);

            resultsCollections[i] = (Collection) o;

            if (resultsCollections[i] == null)
            {
                throw new SQLException("Query \"" + query
                        + "\" returned unresolvable handle: " + myhandle);
            }
        }

        for (int i = 0; i < communityHandles.size(); i++)
        {
            String myhandle = (String) communityHandles.get(i);

            Object o = HandleManager.resolveToObject(context, myhandle);

            resultsCommunities[i] = (Community) o;

            if (resultsCommunities[i] == null)
            {
                throw new SQLException("Query \"" + query
                        + "\" returned unresolvable handle: " + myhandle);
            }
        }

        // Log
        log.info(LogManager.getHeader(context, "search", logInfo + "query=\""
                + query + "\",results=(" + resultsCommunities.length + ","
                + resultsCollections.length + "," + resultsItems.length + ")"));

        // Pass in some page qualities
        // total number of pages
        int pageTotal = 1 + ((qResults.getHitCount() - 1) / qResults
                .getPageSize());

        // current page being displayed
        int pageCurrent = 1 + (qResults.getStart() / qResults.getPageSize());

        // pageLast = min(pageCurrent+9,pageTotal)
        int pageLast = ((pageCurrent + 9) > pageTotal) ? pageTotal
                : (pageCurrent + 9);
View Full Code Here

                    qArgs.setSortOption(sort);
                    qArgs.setSortOrder(sortOrder);
                }

                // Perform the search
                QueryResults qResults = null;
                if (scope == null)
                {
                    qResults = DSQuery.doQuery(context, qArgs);
                }
                else if (scope.getType() == Constants.COLLECTION)
                {
                    qResults = DSQuery.doQuery(context, qArgs, (Collection) scope);
                }
                else if (scope.getType() == Constants.COMMUNITY)
                {
                    qResults = DSQuery.doQuery(context, qArgs, (Community) scope);
                }
                else
                {
                    throw new IllegalStateException("Invalid container for search context (container type is "+scope.getClass().getName()+")");
                }

                // now instantiate the results
                DSpaceObject[] results = new DSpaceObject[qResults.getHitHandles().size()];
                for (int i = 0; i < qResults.getHitHandles().size(); i++)
                {
                    String myHandle = qResults.getHitHandles().get(i);
                    DSpaceObject dso = HandleManager.resolveToObject(context, myHandle);
                    if (dso == null)
                    {
                        throw new SQLException("Query \"" + query + "\" returned unresolvable handle: " + myHandle);
                    }
                    results[i] = dso;
                }

                // generates the OpenSearch result
                resultsDoc = OpenSearch.getResultsDoc(format, query, qResults.getHitCount(), qResults.getStart(), qResults.getPageSize(), scope, results, FeedUtils.i18nLabels);
                FeedUtils.unmangleI18N(resultsDoc);
            }

            // Send the SAX events
            DOMStreamer streamer = new DOMStreamer(contentHandler, lexicalHandler);
View Full Code Here

  }

  private List<String> getHandles(String query) throws IOException {
    QueryArgs args = new QueryArgs();
    args.setQuery(query);
    QueryResults results = DSQuery.doQuery(context, args);
    return results.getHitHandles();
  }
View Full Code Here

TOP

Related Classes of org.dspace.search.QueryResults

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.