Package org.apache.jetspeed.services.search

Examples of org.apache.jetspeed.services.search.ParsedObject


     * @param o
     * @return
     */
    public ParsedObject parseObject(Object o)
    {
        ParsedObject result = new BaseParsedObject();

        if ((o instanceof URL) == false)
        {
            logger.error("URLToDocHandler: invalid object type: " + o);
            return null;
        }

        URL pageToAdd = (URL) o;

        HttpClient client = new HttpClient();
        client.startSession(pageToAdd);
        GetMethod method = new GetMethod(pageToAdd.getPath());
        method.setFollowRedirects(true);
        int statusCode = -1;
        int attempt = 0;

        // We will retry up to 3 times.
        while (statusCode == -1 && attempt < 3)
        {
            try
            {
                // execute the method.
                client.executeMethod(method);
                statusCode = method.getStatusCode();
                if (logger.isDebugEnabled())
                {
                    logger.debug("URL = " + pageToAdd.toString() + "Status code = " + statusCode);
                }
            }
            catch (HttpException e)
            {
                // We will retry
                attempt++;
            }
            catch (IOException e)
            {
                return null;
            }
        }
        // Check that we didn't run out of retries.
        if (statusCode != -1)
        {
            String content = null;
            try
            {
                content = method.getResponseBodyAsString();
            }
            catch (Exception ioe)
            {
                logger.error("Getting content for " + pageToAdd.toString(), ioe);
            }

            if (content != null)
            {
                try
                {
                    result.setKey(java.net.URLEncoder.encode(pageToAdd.toString()));
                    result.setType(ParsedObject.OBJECT_TYPE_URL);
                    // TODO: We should extract the <title> tag here.
                    result.setTitle(pageToAdd.toString());
                    result.setContent(content);
                    result.setDescription("");
                    result.setLanguage("");
                    result.setURL(pageToAdd);
                    result.setClassName(o.getClass().getName());
                    logger.info("Parsed '" + pageToAdd.toString() + "'");
                }
                catch (Exception e)
                {
                    e.printStackTrace();
View Full Code Here


     * @param o
     * @return
     */
    public ParsedObject parseObject(Object o)
    {
        ParsedObject result = super.parseObject(o);
       
        if ((o instanceof PortletEntry) == false)
        {
            logger.error("PortletEntryToDocHandler: invalid object type: " + o);
            return null;
        }

        PortletEntry portletEntry = (PortletEntry) o;
       
        HashMap fields = new HashMap();
        fields.put(PARENT, portletEntry.getParent());
        fields.put(TYPE, portletEntry.getType());
       
        result.setFields(fields);

        StringBuffer content = new StringBuffer();
        String title = portletEntry.getTitle();
        content.append(title == null ? portletEntry.getName() : title);
        content.append(" ");
        content.append(portletEntry.getDescription());
        content.append(" ");
        Iterator it = portletEntry.listCategories();
        while (it.hasNext())
        {
            Category cat = (Category) it.next();
            content.append(cat.getName());
            content.append(" ");
        }

        result.setContent(content.toString());

        result.setType(ParsedObject.OBJECT_TYPE_PORTLET);

        // TODO: index the url for portlets defining one. A good candidate would be HTML, Webpage
        // and IFrame portlets.
       
        return result;
View Full Code Here

    /* (non-Javadoc)
     * @see org.apache.jetspeed.services.search.ObjectHandler#parseObject(java.lang.Object)
     */
    public ParsedObject parseObject(Object o)
    {
        ParsedObject result = new BaseParsedObject();

        if ((o instanceof Portlet) == false)
        {
            logger.error("PortletToDocHandler: invalid object type: " + o);
            return null;
        }

        Portlet portlet = (Portlet) o;
       
       
        JetspeedRunDataService rds = (JetspeedRunDataService) ((TurbineServices) TurbineServices.getInstance())
                                                                                  .getResources(RunDataService.SERVICE_NAME);
        result.setContent(portlet.getContent(rds.getCurrentRunData()).toString());
        result.setDescription(portlet.getDescription());
        result.setType(this.getClass().getName());
        //result.setFields();
        result.setKey(portlet.getName());
        //result.setKeywords();
        //result.setLanguage();
        result.setTitle(portlet.getTitle());
        //result.setURL();
       
        return result;
    }
View Full Code Here

     * @param o
     * @return
     */
    public ParsedObject parseObject(Object o)
    {
        ParsedObject result = new BaseParsedObject();

        if ((o instanceof RegistryEntry) == false)
        {
            logger.error("RegistryEntryToDocHandler: invalid object type: " + o);
            return null;
        }

        RegistryEntry regEntry = (RegistryEntry) o;
        String desc = regEntry.getDescription();
        result.setDescription(desc == null ? regEntry.getName() : desc);
        result.setKey(regEntry.getName());
        String title = regEntry.getTitle();
        result.setTitle(title == null ? regEntry.getName() : title);
       
        result.setClassName(o.getClass().getName());
       
        return result;
    }
View Full Code Here

        int hitCount = hits.length();
        Document doc = null;
        SearchResults results = new SearchResults(hitCount);
        for (int counter = 0; counter < hitCount; counter++)
        {           
            ParsedObject result = new BaseParsedObject();
            try
            {
                doc = hits.doc(counter);
                addFieldsToParsedObject(doc, result);
               
                result.setScore(hits.score(counter));
                Field type = doc.getField(ParsedObject.FIELDNAME_TYPE);
                if(type != null)
                {
                    result.setType(type.stringValue());
                }
               
                Field key = doc.getField(ParsedObject.FIELDNAME_KEY);
                if(key != null)
                {
                    result.setKey(key.stringValue());
                }
               
                Field description = doc.getField(ParsedObject.FIELDNAME_DESCRIPTION);
                if(description != null)
                {
                    result.setDescription(description.stringValue());
                }
               
                Field title = doc.getField(ParsedObject.FIELDNAME_TITLE);
                if(title != null)
                {
                    result.setTitle(title.stringValue());
                }
               
                Field content = doc.getField(ParsedObject.FIELDNAME_CONTENT);
                if(content != null)
                {
                    result.setContent(content.stringValue());
                }
               
                Field language = doc.getField(ParsedObject.FIELDNAME_LANGUAGE);
                if (language != null)
                {
                  result.setLanguage(language.stringValue());
                }
               
                Field classname = doc.getField(ParsedObject.FIELDNAME_CLASSNAME);
                if (classname != null)
                {
                  result.setClassName(classname.stringValue());
                }
               
                Field url = doc.getField(ParsedObject.FIELDNAME_URL);
                if (url != null)
                {
                    result.setURL(new URL(url.stringValue()));
                }
               
                results.add(counter, result);
            }
            catch (Exception ioe)
View Full Code Here

                logger.error("Failed to create hanlder for object " + o.getClass().getName());
                continue;
            }

            // Parse the object
            ParsedObject parsedObject = handler.parseObject(o);

            // Create document
            Document doc = new Document();

            // Populate document from the parsed object
            if (parsedObject.getKey() != null)
            {
                doc.add(Field.Keyword(ParsedObject.FIELDNAME_KEY, parsedObject.getKey()));
            }
            if (parsedObject.getType() != null)
            {
                doc.add(Field.Text(ParsedObject.FIELDNAME_TYPE, parsedObject.getType()));
            }
            if (parsedObject.getTitle() != null)
            {
                doc.add(Field.Text(ParsedObject.FIELDNAME_TITLE, parsedObject.getTitle()));
            }
            if (parsedObject.getDescription() != null)
            {
                doc.add(Field.Text(ParsedObject.FIELDNAME_DESCRIPTION, parsedObject.getDescription()));
            }
            if (parsedObject.getContent() != null)
            {
                doc.add(Field.Text(ParsedObject.FIELDNAME_CONTENT, parsedObject.getContent()));
            }
            if (parsedObject.getLanguage() != null)
            {
                doc.add(Field.Text(ParsedObject.FIELDNAME_LANGUAGE, parsedObject.getLanguage()));  
            }
            if (parsedObject.getURL() != null)
            {
                doc.add(Field.Text(ParsedObject.FIELDNAME_URL, parsedObject.getURL().toString()));
            }
            if(parsedObject.getClassName() != null)
            {
                doc.add(Field.Text(ParsedObject.FIELDNAME_CLASSNAME, parsedObject.getClassName()));
            }

            MultiMap multiKeywords = parsedObject.getMultiKeywords();
            addFieldsToDocument(doc, multiKeywords, KEYWORD);
           
            MultiMap multiFields = parsedObject.getMultiFields();
            addFieldsToDocument(doc, multiFields, TEXT);
           
            Map fields = parsedObject.getFields();
            addFieldsToDocument(doc, fields, TEXT);

            // Add the document to search index
            try
            {
                indexWriter.addDocument(doc);
            }
            catch (IOException e)
            {
               logger.error("Error adding document to index.", e);
            }
            logger.debug("Index Document Count = " + indexWriter.docCount());
            logger.info("Added '" + parsedObject.getTitle() + "' to index");
            result = true;
        }

        try
        {
View Full Code Here

                Object o = it.next();
                // Look up appropriate handler
                ObjectHandler handler = HandlerFactory.getHandler(o);

                // Parse the object
                ParsedObject parsedObject = handler.parseObject(o);

                // Create term
                Term term = null;

                if (parsedObject.getKey() != null)
                {
                    term = new Term(ParsedObject.FIELDNAME_KEY, parsedObject.getKey());
                    // Remove the document from search index
                    int rc = indexReader.delete(term);
                    logger.info("Attempted to delete '" + term.toString() + "' from index, documents deleted = " + rc);
                    //System.out.println("Attempted to delete '" + term.toString() + "' from index, documents deleted = " + rc);
                    result = rc > 0;
View Full Code Here

        }
       
        //
        // execute the query
        //
        ParsedObject result = null;
        SearchResults results  = Search.search(searchString);
        //System.out.println("Query hits = " + results.size());
        rundata.getRequest().setAttribute(SEARCH_RESULTS, results.getResults());               
    }
View Full Code Here

    /* (non-Javadoc)
     * @see org.apache.jetspeed.services.search.ObjectHandler#parseObject(java.lang.Object)
     */
    public ParsedObject parseObject(Object o)
    {
        ParsedObject result = new BaseParsedObject();

        if ((o instanceof Portlet) == false)
        {
            logger.error("PortletToDocHandler: invalid object type: " + o);
            return null;
        }

        Portlet portlet = (Portlet) o;
       
       
        JetspeedRunDataService rds = (JetspeedRunDataService) ((TurbineServices) TurbineServices.getInstance())
                                                                                  .getResources(RunDataService.SERVICE_NAME);
        result.setContent(portlet.getContent(rds.getCurrentRunData()).toString());
        result.setDescription(portlet.getDescription());
        result.setType(this.getClass().getName());
        //result.setFields();
        result.setKey(portlet.getName());
        //result.setKeywords();
        //result.setLanguage();
        result.setTitle(portlet.getTitle());
        //result.setURL();
       
        return result;
    }
View Full Code Here

     * @param o
     * @return
     */
    public ParsedObject parseObject(Object o)
    {
        ParsedObject result = new BaseParsedObject();

        if ((o instanceof RegistryEntry) == false)
        {
            logger.error("RegistryEntryToDocHandler: invalid object type: " + o);
            return null;
        }

        RegistryEntry regEntry = (RegistryEntry) o;
        String desc = regEntry.getDescription();
        result.setDescription(desc == null ? regEntry.getName() : desc);
        result.setKey(regEntry.getName());
        String title = regEntry.getTitle();
        result.setTitle(title == null ? regEntry.getName() : title);
       
        return result;
    }
View Full Code Here

TOP

Related Classes of org.apache.jetspeed.services.search.ParsedObject

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.