cancel
Showing results for 
Search instead for 
Did you mean: 

Performance problem with the search

djimenez
Champ in-the-making
Champ in-the-making
Hello,

I have a problem when I list contents using webscripts and the freemarker APi. I realize a probe with 700 contents in the repository, In listing 700 contents the doclist webscript  spent 53 seconds. I modify this webscript and I limit to 20 the number of contents that the webscript show, it was executed in 45 seconds. I have checked that the searches depends directly the number of contents in the repository but this times are unacceptable. Is normal his situation?

The most time it's spent in the next instruction of freemarker

<#assign docs=companyhome.childrenByLuceneSearch[PATH:\"/app:company_home/cm:folder/*\"]?sort_by(["properties","name") >

I think if It could limit the size of the result the execution time improve. How can I do this limitation?

Thank u.
4 REPLIES 4

witho
Champ on-the-rise
Champ on-the-rise
I have the same problem with a doclit portlet I have created to find the last 20 documents uploaded to the repoitory. The thing is that I have to search every docs in the repository order by date and only print the first 20 documents and the others just set at display:none.

Is there any better solution in order to minimize the waiting time?

Thanks a lot!!!

rogier_oudshoor
Champ in-the-making
Champ in-the-making
That's because you're using Freemarker to do the sorting. That means that all 700 nodes are loaded into the template to be sorted.

What you SHOULD do, is code a Java-backed webscript in which Lucene does the sorting (!) and you have full control over which attributes from which nodes you access. I'm quite sure from experience you'll be able to drop it to a second when only touching 20 nodes. (Lucene doesn't have to load a node to sort)

witho
Champ on-the-rise
Champ on-the-rise
The thing is that I want to have the same functionality that in teh doclist portlet, so I would have to edit or replicate the WebScriportlet. The problem is that I don't know where in the WebScriptPortlet can I put my code to only get the 20 last documents added to the repository.

witho
Champ on-the-rise
Champ on-the-rise
Hi,

Finally I got a valid solution for me. I replicate the method getChildrenByLuceneSearch the class LuceneSearchResultsMap and also the method get inside this class. I make a new lucene search that sort the documents by created date and get only the 20 first. This is my method get:


    public Object get(Object key)
    {
        // execute the search
        String search = key.toString();
       List<TemplateNode> nodes = null;
        HashSet<NodeRef> nodeRefs = new HashSet<NodeRef>();

        // check if a full Lucene search string has been supplied or extracted from XML
        if (search != null && search.length() != 0)
        {
            // perform the search against the repo
            ResultSet results = null;
            try
            {
                SearchParameters sp = new SearchParameters();
                sp.addStore(this.parent.getNodeRef().getStoreRef());
                sp.setLanguage(SearchService.LANGUAGE_LUCENE);
                sp.setQuery(search);
                sp.addSort("CREATED", false);
                sp.setLimitBy(LimitBy.FINAL_SIZE);
                int limit = 20;
                sp.setLimit(limit);

                results = this.services.getSearchService().query(sp);

                if (results.length() != 0)
                {
                    nodes = new ArrayList<TemplateNode>(results.length());
                    for (ResultSetRow row : results)
                    {
                        NodeRef nodeRef = row.getNodeRef();
                        if (!nodeRefs.contains(nodeRef))
                        {
                            nodes.add(new TemplateNode(nodeRef, services, this.parent.getImageResolver()));
                            nodeRefs.add(nodeRef);
                        }
                    }
                }
            }
            catch (Throwable err)
            {
                throw new AlfrescoRuntimeException("Failed to execute search: " + search, err);
            }
            finally
            {
                if (results != null)
                {
                    results.close();
                }
            }
        }

        return nodes != null ? nodes : (List) Collections.emptyList();
    }

I hope this may help somebody too.