Advanced search functions » Discuss

Discussions on Advanced search functions

  1.  

    Metaweb Queries with JavaScript

    1. Hi

      I am Sreedhar Ambati working on Freebase. 

      In section 4.5 of the tutorial found in url

      Metaweb Queries with JavaScript

      I wrote a sample using the code given and json.js and metaweb.js files
      I was success in running the application

      But in section 4.5 I replaced the query with the below

      var queryItem =

      {

       

      query:[{

      name:null,

      type:"/freebase/domain_category"

      }]

       

      Now I am getting error saying query is not a supported property.

      Where  I went wrong?

       

      Regards,

      Sreedhar Ambati

      1. Sreedhar,

        If you are using the Metaweb.read() function defined in §4.5.2, you will see that Metaweb.read() adds the “query” keyword for you:

        envelope = {qname: {query: q}}

        You do need to have “query” in your query, but if you are using Metaweb.read() with your queryItem, then you will have it twice.

      2. I am Sreedhar Ambati. Recently started working on Freebase API.

         

        I want to list down all the categories like “Arts  & entertainment,society,sports,Porducts & services,Money etc.. in a dropdown .

         

        I tested with this below code: Which displays albums by the specified band eg: Backstreet Boys

         

        <script type="text/javascript" src="metaweb.js"></script>

         <script type="text/javascript" src="json.js"></script>

         

        <script>                               

         

         

        function listalbums()

        {

            var band = document.getElementById("TypeText").value;

         

            var albumlist = document.getElementById("albumlist");

         

            albumlist.innerHTML = "Loading..."

         

            var query =

            {                    

                type: "/music/artist",        

                name: band,                   

                album: [{                        

                        name:null,                

                        release_date:null,        

                        sort: "release_date"      

                       }]

            };   

           

            Metaweb.read(query, displayAlbums);     

          

           function displayAlbums(result)

           { 

            

                if (!result || !result.album)

                {

                    albumlist.innerHTML = "Unknown band: " + band + "";

                    return;

                }

               

                var albums = result.album;

         

         

                albumlist.innerHTML = "";

                for(var i = 0; i < albums.length; i++)

                {

                      addOption(document.getElementById('drpSuggestedValues'),albums[i].name, albums[i].name);

                  

                }

              

               function addOption(selectbox,text,value )

               {     

                    var optn = document.createElement("OPTION");

                    optn.text = text;

                    optn.value = value;

                    selectbox.options.add(optn);

               }  

              

         

            }

         

        }

         

        </script>

         

        <html>

        <head>

        <title id="title">

        </title>

        </head>

        <body>

            <input type="text" id="TypeText" />

            <div id="albumlist">

            </div>    

            <input type="button" value="God save me" id="btn" onclick="listalbums()"/>

            <select id="drpSuggestedValues" size=5 runat="server"></select>

        </body>

        </html>

         

        Now I want to list down all the categories in the same way by changing the query to:

         

            var queryItem =

            {       

                query:[{

                        name:null,

                        type:"/freebase/domain_category"

                      }]

                  

            }; 

         

        It is showing error : “No such property by name query”

         

        Can you help me in solving my problem of displaying all the categories(“Arts  & entertainment,society,sports,Porducts & services,Money etc.. )in a in a dropdown

         

        Regards,

        Sreedhar Ambati

      3. Sreedhar,

        Please read my previous reply. Your working example uses Metaweb.read() and does not include a query key. Your non-working example includes a query key; if you are still using Metaweb.read(), that will not work.

      4. Hi

        Thanks for the support.

        I could able to progress better.

        I have three dropdowns , a textbox, two buttons.

        On page load none of the dropdowns have values.

        On click of categories button first dropdown gets values with "arts and science,sports,movies etc"

        On change of first dropdown second dropdown gets values.On change of second third dropdown gets values.

        Upto this I completed.

        Now user searches for a text and clicks on search button. I was struck up here as I dont know how to write the query here.

        Based on the third dropdown and the textbox inputs I have to show the result with autocomplete feature too.

        How to do that?

        I am providing my code below:

        <script type="text/javascript" src="metaweb.js"></script>

        <script type="text/javascript" src="json.js"></script>

         

        <script>

        function LoadCategories()

        {

        divList.innerHTML = "Loading..."

        var query = [{ name: null, type: '/freebase/domain_category' }];

         

        Metaweb.read(query, displayCategories);

        function displayCategories(result)

        {

        if (!result)

        {

        divList.innerHTML = "Unknown:";

        return;

        }

        divList.innerHTML = "";

        for(var i = 0; i < result.length; i++)

        {

        addOption(document.getElementById('drpCategoryValues'),result[i].name, result[i].name);

        }

        }

        }

        function addOption(selectbox,text,value)

        {

        var optn = document.createElement("OPTION");

        optn.text = removeJunk(text);

        optn.value = removeJunk(text);

        selectbox.options.add(optn);

        }

         

        function removeJunk(text)

        {

        if(text.search(/&amp;/)>0)

        {

        text = text.replace(/amp;/,"");

        }

        return text;

        }

         

        function removeAllOptions(selectbox)

        {

        for(var i= selectbox.options.length-1;i>=0;i--)

        {

        selectbox.remove(i);

        }

        }

         

        function LoadSubCategories()

        {

        var selectedValue = document.getElementById('drpCategoryValues').value;

         

        var query = [{ domains:[], name: selectedValue, type: '/freebase/domain_category' }];

         

        Metaweb.read(query, displayNames);

         

        function displayNames(result)

        {

        if (!result)

        {

        divList.innerHTML = "Unknown";

        return;

        }

        divList.innerHTML = "";

        removeAllOptions(document.getElementById('drpSubCategoryValues'))

         

        for(var i = 0; i < result[0].domains.length; i++)

        {

        addOption(document.getElementById('drpSubCategoryValues'),result[0].domains[i], result[0].domains[i]);

        }

        }

        }

         

        function LoadTypes()

        {

        debugger;

        var selectedValue = document.getElementById('drpSubCategoryValues').value;

         

        var query = [{ types:[{name:null}],name: selectedValue, type: '/type/domain' }];

         

        Metaweb.read(query, displayTypes);

         

        function displayTypes(result)

        {

        if (!result)

        {

        divList.innerHTML = "Unknown";

        return;

        }

        divList.innerHTML = "";

        removeAllOptions(document.getElementById('drpTypes'))

         

        for(var i = 0; i < result[0].types.length; i++)

        {

        addOption(document.getElementById('drpTypes'),result[0].types[i].name, result[0].types[i].name);

        }

        }

        }

        function Search()

        {

        }

         

        </script>

        <html>

        <head>

        </head>

        <body>

        <div id="divList">

        </div>

        <select id="drpCategoryValues" size=5 runat="server" onchange="LoadSubCategories(this);"></select>

        <input type="button" value="Categories" id="btn" onclick="LoadCategories()"/>

        <select id="drpSubCategoryValues" size=5 runat="server" onchange="LoadTypes(this);"></select>

         

        <select id="drpTypes" size=5 runat="server"></select>

        <input type="text" id="txtSearch" />

        <input type="button" value="Search" id="btnSearch" onclick="Search()"/>

        </body>

        </html>

        Thanks & Regards,

        Sreedhar Ambati 

         

         

      5. Sreedhar,

        I would suggest looking at the auto-complete examples.  You can download the latest freebase-suggest here.  The website has live examples, and there are also examples included in the zip archive itself.  You can use the type that the user selects in your third select box as the constraint for the autocomplete query.

      6. Hi Cheunger,

        How to retrieve the suggestions which have images on the top left side from the autosuggest feature of the textbox ?

        How to tweak this?

        Thanks

        Sreedhar Ambati

      7. Images and descriptions are displayed in the flyout if the topic has them.

        However, if I understand your question correctly, you want to only retrieve topics that have an image.  This can be done in your suggest query where you can constrain results returned by also trying to return the image id for /common/topic/image .

      8. Hi Cheunger ,

        You are right.

        My intention is I want to display suggestions in the textbox which are having images. 

        I wrote code like this (in the below).

        But the problem is it is not solving my purpose.

        Can you please check it once and tell me where I went wrong?

        <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"

        xmlns:freebase="http://freebase.com/">

         

        <head>

        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

        <link type="text/css" rel="stylesheet" href="../dist/css/freebase-controls.css" />

        <script type="text/javascript" src="http://code.jquery.com/jquery-nightly.pack.js"></script>

        <script type="text/javascript" src="../dist/freebase.suggest.js"></script>

         

        <style type="text/css">

        .fbs-li-types { display:none; }

        </style>

         

        <script type="text/javascript">

         

         

        jQuery(function($) {

        $("#Text1")

        .freebaseSuggest({'/common/topic/image':[{id:null}]})

        .bind("fb-select", function(e, data) {

        mylog("select id: " , data.id , ", name: " , data.name, data);

        })

        .bind("fb-submit", function(e, data) {

        mylog("submit id: " , data.id , ", name: " , data.name, data);

        });

        });

         

        function mylog() {

        var msg = "";

        $.each(arguments, function(i,n) {

        msg += n;

        });

        if (msg) {

        $("#msg").append("<li>" + msg + "</li>");

        }

        };

        </script>

         

        </head>

        <body>

        <input type="text" id="Text1" />

        </body>

        </html>

        Thanks

        Sreedhar Ambati

        http://ambatisreedhar.spaces.live.com

      9. After a bit more research, at this point, the autocomplete service does not support anything other than what is listed in the autocomplete API.  However, you may be able to work around your problem by using filter, as documented here.  We hope to add support MQL queries within autocomplete sometime in the future, so stay tuned for that development.

      10. Hi

        Thanks for your help.

        Can you provide an example on how to use filter ?

        Thanks

        Sreedhar Ambati 

         

      11. Something like:

        $("myinput").freebaseSuggest({
            filter: function(data, prefix) {
                if (data.image)
                return true;
                return false;
            },
            ac_param: {
                type: "/common/topic",
                start: 0,
                limit: 100
            }
        });


        By default, we're retrieving the first 20 results from the search API. You may want to increase that number (to 100) so that after you apply your filter, you get more results.


    Discussion is posted in:

    Think this discussion also relates to something else? Cross-post it by adding a new discussion area:

  2.  

    Treeview Structure of all categories

    1. Hi

      I am  Sreedhar Ambati.

      I want to display all the categories in a tree view structure. Like main category in root node and its subcategories in leaf nodes. etc.

      How can I do that?

      Please provide me some code or sample so that I can start my Search application.

      This is my id: ambatisreedhar@gmail.com

      Regards,

      Sreedhar A

       

      1. Sreedhar, I posted a reply to your 3 questions here.


    Discussion is posted in:

    Think this discussion also relates to something else? Cross-post it by adding a new discussion area:

  3.  

    API please

    1. Hi

      Can anyone let me know what is the API I have to use for getting Advanced Search functionality in my .net application?

      Thanks

      Sreedhar 

       

      1. Sreedhar,

         See the response to your other post here.  For the most part, you only need to post once in one location to receive an answer.


    Discussion is posted in:

    Think this discussion also relates to something else? Cross-post it by adding a new discussion area:

Start a New Discussion

Discussion will be posted in:

Think this discussion also relates to something else? Cross-post it by adding a new discussion area: