Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

LAPI search java 1

Status
Not open for further replies.

ahaboub

Technical User
Jul 31, 2009
41
0
0
LB
i need to know if there is anything wrong with this function, the variable "results" is always { } whatever is the searchstring...

Code:
public static void search(String wordName)
    {
        String searchString="";
        searchString="(OTName : '*')";
        LAPI_SEARCH search= new LAPI_SEARCH(session);
        LLValue brokers= new LLValue();
        LLValue broker= new LLValue();
        LLValue selectList= new LLValue();
        LLValue results= new LLValue();
        LLValue result=new LLValue();
        int brokerID=0;
        int status= search.GetSearchBrokers(brokers);
        if (status!=0)
        {
        
        }
        else
        {
            for(int i=0; i<brokers.size(); i++)
            {
                broker=brokers.toValue(i);
                //System.out.println(broker.toString());
                if ((broker.toString("NodeName")).equals("Enterprise"))
                {
                    brokerID=broker.toInteger("NodeID");
                    break;
                }
            }
            if (brokerID > 0)
            {
                selectList.setList();
                selectList.setSize(2);
                selectList.setString(0,"OTName");
                selectList.setString(1,"OTDataID");
                if (search.ApplyQuery(brokerID, selectList, searchString, LAPI_SEARCH.SORTBYDEFAULT, "", 0, 100, "LivelinkQueryLanguage", results) !=0)
                {
                    System.out.println("ApplyQuery Failed");
                }
                else
                {
                    System.out.println("results: " + results.toString()); //always { }
                    for(int j=0;j<results.size();j++)
                    {
                        result=results.toValue(j);
                        System.out.println(result.toString("OTDataID") + " " + result.toString("OTName"));
                    }
                }
            }
        }
    }
 
YOU DO NOT HAVE OTOBJECT IN YOUR CODE I BELEIVE
//Set up the list of fields for ApplyQuery to return
//Note: OTObject must be in this list for ApplyQuery to work
vSelectList.add( "OTName" ); //Object Name
//vSelectList.add( "OTDataID" ); //The objects ID
vSelectList.add( "OTObject" );
vSelectList.add( "OTOwnerID" );
vSelectList.add("Attr_152278_35");

working code from my work
Code:
//Java Sample using ApplyQuery

import com.opentext.api.*;

public class ApplyQuery
{
    //For Connection
    private static String Server = "localhost";
    private static int Port = 2099;
    private static String DFT = "";
    private static String User = "Admin";
    private static String Pass = "Admin";

    public static void main( String[] args )
    {
        try
        {
            //variables
               LLSession             session;
            LAPI_DOCUMENTS         doc;
            LAPI_SEARCH            search;
            int                    brokerID;

            //Constructors for session and search objects
            session = new LLSession (Server, Port, DFT, User, Pass);
            search = new LAPI_SEARCH (session);

             brokerID = GetSearchBroker(search, session);
            LLValue        vListBrokers=new LLValue();
            search.GetDisplayableFields(brokerID,vListBrokers);
            Search(brokerID, session, search);
        }


        catch ( Throwable e )
        {
            System.err.println( e.getMessage() );
            e.printStackTrace( System.err );
        }
    }


    public static int GetSearchBroker(LAPI_SEARCH search, LLSession session)
    {
        //Returns the BrokerID for the Enterprise Slice

        LLValue        vListBrokers, tmpAssoc;
        int            length, brokerID;
        String        nodeName, broker;

        broker = "Enterprise";
        brokerID = -1;

        //Define the value objects
        vListBrokers = new LLValue();    //List of available brokers
        tmpAssoc = new LLValue();        //Temp Assoc


        // Retrieve the Search Brokers
        if (search.GetSearchBrokers(vListBrokers) != 0)
        {
            System.out.println("Failed to get Search Brokers");
            sError(session);
        }
        else
        {
            //Find the Enterpise BrokerID
            length = vListBrokers.size();
            for (int i=0; i<length; i++)
            {
                tmpAssoc = vListBrokers.toValue(i);
                nodeName = tmpAssoc.toString("NodeName");
                System.out.println("Got this Broker"+nodeName );
                if (nodeName.equals(broker))
                {
                    brokerID = tmpAssoc.toInteger("NodeID");
                }
            }
        }

        return (brokerID);
    }

    public static void Search(int brokerID, LLSession session, LAPI_SEARCH search)
    {
        //Use Apply query to Search for a specified term

        //Variables
        LLValue vSelectList, vQueryResults, value;
        String    where, fName;
        int length;

        //Define value objects
        vSelectList = new LLValue().setList();
        vQueryResults = new LLValue();
        value = new LLValue();

        //Set up the list of fields for ApplyQuery to return
        //Note: OTObject must be in this list for ApplyQuery to work
        vSelectList.add( "OTName" );        //Object Name
        //vSelectList.add( "OTDataID" );        //The objects ID
        vSelectList.add( "OTObject" );
        vSelectList.add( "OTOwnerID" );
        vSelectList.add("Attr_152278_35");
        //The objects VolumeID

        //Where clause which searches on the OTName region for the word "Livelink"
        //where = "(OTData :\"Livelink\")";
        where = "(Attr_152278_35 :\"CUST DUMMY DOC #1\")";
        

        //Search Livelink
        if ( search.ApplyQuery( brokerID, vSelectList, where, search.SORTBYDEFAULT, "OTName", 0, 100, "LivelinkQueryLanguage", vQueryResults) != 0)
        {
            System.out.println("Apply query failed");
            sError(session);
        }
        else
        {
            //Displays the results of the search
            length = vQueryResults.size();
            if (length > 0)
            {
                System.out.println("The query returned "+ length+" results");
                for (int i=0; i<length; i++)
                {
                    value = vQueryResults.toValue(i);
                    fName = value.toString("OTName");
                    System.out.println(fName);
                }
            }
        }
    }

    private static void sError(LLSession session)
    {
        //Error Checking
        System.out.println("Status Code: " + session.getStatus());
        System.out.println("Api Error: " + session.getApiError());
        System.out.println("Error Message: " + session.getErrMsg());
        System.out.println("Status Message: " + session.getStatusMessage());
    }



}

Well, if I called the wrong number, why did you answer the phone?
James Thurber, New Yorker cartoon caption, June 5, 1937
Certified OT Developer,Livelink ECM Champion 2008,Livelink ECM Champion 2010
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top