Package org.apache.jetspeed.services.search

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


        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);
                result.setScore(hits.score(counter));
                result.setType(doc.getField(ParsedObject.FIELDNAME_TYPE).stringValue());
                result.setKey(doc.getField(ParsedObject.FIELDNAME_KEY).stringValue());
                result.setDescription(doc.getField(ParsedObject.FIELDNAME_DESCRIPTION).stringValue());
                result.setTitle(doc.getField(ParsedObject.FIELDNAME_TITLE).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


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

                // 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()));
                }

                // TODO: How to handle keywords and fields
                /*String[] keywords = parsedObject.getKeywords();
                if (keywords != null)
                {
                    for (int i = 0; i < keywords.length; i++)
                    {
                        doc.add(Field.Keyword();
                    }
                } */

                // Add the document to search index
                indexWriter.addDocument(doc);
                logger.debug("Index Document Count = " + indexWriter.docCount());
                logger.info("Added '" + parsedObject.getTitle() + "' to index");
                result = true;
            }

            indexWriter.optimize();
            indexWriter.close();
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

     * @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
            }
            catch (IOException e)
            {
                return null;
            }
        }
        // Check that we didn't run out of retries.
        if (statusCode != -1)
        {
            String content = null;
            try
            {
                content = method.getDataAsString();
            }
            catch (IOException 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);
                    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

        }
       
        //
        // 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

     * @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
            }
            catch (IOException e)
            {
                return null;
            }
        }
        // Check that we didn't run out of retries.
        if (statusCode != -1)
        {
            String content = null;
            try
            {
                content = method.getDataAsString();
            }
            catch (IOException 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

        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));
                result.setType(doc.getField(ParsedObject.FIELDNAME_TYPE).stringValue());
                result.setKey(doc.getField(ParsedObject.FIELDNAME_KEY).stringValue());
                result.setDescription(doc.getField(ParsedObject.FIELDNAME_DESCRIPTION).stringValue());
                result.setTitle(doc.getField(ParsedObject.FIELDNAME_TITLE).stringValue());
                result.setContent(doc.getField(ParsedObject.FIELDNAME_CLASSNAME).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

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.