Yii Framework Forum: OpenSearch for Yii API - Yii Framework Forum

Jump to content

  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

OpenSearch for Yii API I wrote search Yii API plug-In but need some help. Rate Topic: -----

#1 User is offline   GOsha 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 24
  • Joined: 09-August 10
  • Location:Europe, Belarus, Brest

Posted 13 November 2010 - 08:55 AM

I wrote Yii API Open Search plug-in for Firefox and (as I knew later) for IE.
https://addons.mozil...x/addon/254552/
Here are screenshots:
in IE: http://img571.images.../7951/ieyii.png
in FF: http://img42.imagesh.../yiiscreen2.png
But Yii site not provides results for OpenSearch in proper format.
That`s why I wrote interfase for Yii suggester.
<?php
ob_start("ob_gzhandler");
header("Content-Type: text/html; charset=utf-8");
function make_response($content)
{
    $title = $desc = $url = array();
    $qa = explode("\n",$content);
    foreach($qa as $value)
    {
        $exploded = array();
        $title[] = $value;
        $exploded = explode('.',$value);
        $desc[] = $exploded[0];
        $str = "";
        $str = 'http://www.yiiframework.com/doc/api/1.1/'.$exploded[0];
        if(count($exploded) == 2)
        {
            $str .= '#'.trim($exploded[1],'()').'-detail';
        }
        $url[] = $str;
    }
    return '["'.$_GET['q'].'",["'.implode('","',$title).'"],["'.implode('","',$desc).'"],["'.implode('","',$url).'"]]';
}

if(!empty($_GET['q']))
{
    $link = "http://www.yiiframework.com/api/suggest/?q=".urlencode($_GET['q']).'&limit=100&timestamp='.time();
	$ch = curl_init ();
	curl_setopt ($ch , CURLOPT_URL , $link);
	curl_setopt ($ch , CURLOPT_RETURNTRANSFER , 1 );
	$content = curl_exec($ch);
    echo make_response($content);
}
ob_end_flush();
?>

Temporary hosted on another site and you can see output here: http://www.z-zag.com...gest.php?q=Form
Can you help me with host this suggester, or make special suggester page in yii official site to make it more stable.
And the second wish is to redirect from search page if it is the only result for query.
Example: http://www.yiiframew...ype=api-suggest
Because of in IE plugin works correctly and goes to defined page straightly. But in FF searcer can`t do it, and redirects to search page.
OPENSEARCH suggestions specification: http://www.opensearc...Suggestions/1.1
P.S.> Sorry for long post and my english.
3

#2 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,899
  • Joined: 04-October 08
  • Location:DC, USA

Posted 13 November 2010 - 09:01 AM

This is great. Could you describe what format of the response you are expecting? It would be better if you could illustrate it with an example. Thanks!
0

#3 User is offline   GOsha 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 24
  • Joined: 09-August 10
  • Location:Europe, Belarus, Brest

Posted 13 November 2010 - 09:09 AM

You can see in example. BUt shortly JSON arrays:
["sea", //what we search
  ["sears", //list of suggestions
   "search engines",
   "search engine",
   "search",
   "sears.com",
   "seattle times"],
  ["7,390,000 results", //list of descriptions
   "17,900,000 results",
   "25,700,000 results",
   "1,220,000,000 results",
   "1 result",
   "17,600,000 results"],
  ["http://example.com?q=sears", //list of url
   "http://example.com?q=search+engines",
   "http://example.com?q=search+engine",
   "http://example.com?q=search",
   "http://example.com?q=sears.com",
   "http://example.com?q=seattle+times"]]

Positions in array are fixed. I don`t know how to say it in english:
["search",["suggest1","suggest2",...],["descr1","descr2",...],["url1","url2",...]]

Mozilla not supports format with urls, that`s why I ask for redirect if only 1 result found.
1

#4 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,899
  • Joined: 04-October 08
  • Location:DC, USA

Posted 13 November 2010 - 09:46 AM

Is description required?

Regarding redirect, do you mean if there is only one result, instead of returning json results, we should just send a redirect header?
0

#5 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,899
  • Joined: 04-October 08
  • Location:DC, USA

Posted 13 November 2010 - 09:48 AM

Can you make the plugin in English so that more users can use it? After it is in good shape, I can add a link to the plugin on our website.
0

#6 User is offline   GOsha 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 24
  • Joined: 09-August 10
  • Location:Europe, Belarus, Brest

Posted 13 November 2010 - 09:53 AM

It`s multilang:
https://addons.mozil...x/addon/254552/
I gave you you russian link - sorry.

About redirect - yes.
If I click on suggestion in IE - browser goes to defined in urls array page. But if i click on suggestion in FF - browser goes in search page with suggested query (FF not supports opensearch links) and finds here only 1 entry. After click on it - we go to correct page. That`s why straight redirect if 1 search result will be good for search form.
0

#7 User is offline   GOsha 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 24
  • Joined: 09-August 10
  • Location:Europe, Belarus, Brest

Posted 13 November 2010 - 10:42 AM

I simply use classname for description.
But you can provide blank array without descriptions
["search",["suggest1","suggest2",...],[],["url1","url2",...]]

0

#8 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,899
  • Joined: 04-October 08
  • Location:DC, USA

Posted 13 November 2010 - 02:10 PM

I just added support for this. http://www.yiiframew...?q=clist&json=1 (you need to put json=1 in the query part)
Please let me know if this works well. Thanks!
0

#9 User is offline   GOsha 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 24
  • Joined: 09-August 10
  • Location:Europe, Belarus, Brest

Posted 13 November 2010 - 02:32 PM

It works!. I`ve updated this plugin.
But there are some troubles:
1. You forget to add "-detail" if query is about method or property.
not
http://www.yiiframework.com/doc/api/1.1/CAccessControlFilter#rules
but
http://www.yiiframework.com/doc/api/1.1/CAccessControlFilter#rules-detail

2. Because of big quantity of suggestions:
in FF it works in slow letter by letter input(((
in IE it works if there is not many suggestions (<=20 in tests)
0

#10 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,899
  • Joined: 04-October 08
  • Location:DC, USA

Posted 13 November 2010 - 03:31 PM

I just enabled the limit GET parameter. You can set it to a smaller number to make it work fast.
Regarding "-detail", this is because a method could be defined in a base class whose detail description is only available in the base class API page.
0

#11 User is offline   GOsha 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 24
  • Joined: 09-August 10
  • Location:Europe, Belarus, Brest

Posted 13 November 2010 - 04:00 PM

OK. Now it works more stable.
you can save yiisearch.xml:
<?xml version="1.0" encoding="UTF-8"?>
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/"
                       xmlns:moz="http://www.mozilla.org/2006/browser/search/">
<ShortName>Yiisearch</ShortName>
<Description>Yii Class Referrence Searcher</Description>
<InputEncoding>UTF-8</InputEncoding>
<OutputEncoding>UTF-8</OutputEncoding>
<Image width="16" height="16" type="image/x-icon">http://yiiframework.com/favicon.ico</Image>
<Url type="text/html" method="GET" xmlns:referrer="http://a9.com/-/opensearch/extensions/referrer/" template="http://www.yiiframework.com/search/?q={searchTerms}&amp;type=api-suggest"/>
<Url type="application/x-suggestions+json" template="http://www.yiiframework.com/api/suggest/?q={searchTerms}&amp;json=1&amp;limit=20" />
<moz:SearchForm>http://www.yiiframework.com/doc/api/</moz:SearchForm>
</OpenSearchDescription>

in the root directory of your site.
and add in head section:
<link rel="search" type="application/opensearchdescription+xml" title="Yiisearch"
        href="/yiisearch.xml" />

After that IE and FF will notify user, that there is opensearch plugin. By highlighting choose arrow in fastsearch panel. And make Google Chrome able to find opensearch and suggester on this site.

And will it possible about redirect if the only variant found? It makes Firefox to go directly to suggested API page.
0

#12 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,899
  • Joined: 04-October 08
  • Location:DC, USA

Posted 13 November 2010 - 05:13 PM

Added the xml file and changed the head section. It is working nicely! Thank you very much!

Regarding the redirection, it is a bit complicated. I will need to ask Wei for help.

Is your FF search plug-in still needed?

Now I need to write something to advertise this. Thanks!
0

#13 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,899
  • Joined: 04-October 08
  • Location:DC, USA

Posted 13 November 2010 - 05:21 PM

Could you please explain how to make it work for Chrome?
Also, it seems IE8 doesn't give autocompletion. Is this expected?
0

#14 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,899
  • Joined: 04-October 08
  • Location:DC, USA

Posted 13 November 2010 - 05:22 PM

Or even better, if you could write a wiki article explaining how to make use of this wonderful thing.
I will add a link to the article then.
0

#15 User is offline   GOsha 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 24
  • Joined: 09-August 10
  • Location:Europe, Belarus, Brest

Posted 13 November 2010 - 06:15 PM

View Postqiang, on 13 November 2010 - 05:13 PM, said:

Is your FF search plug-in still needed?

This plugin duplicated xml-flie.
But firefox add-ons make plugin searching easier for users. And the can make own plugin collections and provide it to other users. Let it be in firefox too.

View Postqiang, on 13 November 2010 - 05:21 PM, said:

Could you please explain how to make it work for Chrome?

Right Click in the address bar and select Edit Search Engines and on the next window select Yiisearch and Edit.
here you can change alias. searching will be able as {alias}<TAB or SPACE>{query}. Autocomplete working nicely.
You make changes to search form URL - but it was wery handy to search only in API Docs. May be it would be good to make Yii Site Search, and Yii Api Search in 2 xml files. and 2 header links.
sitesearch.xml:
 http://www.yiiframework.com/search/?q={searchTerms}

apisearch.xml
 http://www.yiiframework.com/search/?type=api-suggest&amp;q={searchTerms}

It`s very handy to experienced programmers. In russian jabber yii conference - they were dissapointed searching in all site.

View Postqiang, on 13 November 2010 - 05:21 PM, said:

Also, it seems IE8 doesn't give autocompletion. Is this expected?

I have IE8 - completion works more narrow then in FF.
Check if completion is on. Click on search engines chooser (arrow)
check something like Search plugins Management (I have russian version ant can`t say more exactly). And check if completion is on for Yii Search. if it is on. try to enter letters more slowly.

View Postqiang, on 13 November 2010 - 05:22 PM, said:

Or even better, if you could write a wiki article explaining how to make use of this wonderful thing.
I will add a link to the article then.

My eng is not great to do it))). But I can try.

P.S.> for Opera
Tools>Preferences>Search>Add
Name: Yii Search
Keyword: yii
Address: http://www.yiiframework.com/search/?type=api-suggest&q=%s

Then search by "yii<space>searchstr" but Opera not works with suggestions.

Now I`ll going sleepin` for 8h.)))
0

#16 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 3,739
  • Joined: 17-January 09
  • Location:Russia

Posted 13 November 2010 - 06:35 PM

Nice. I've got it working in Opera. It requires some config editing.

How to do it:
1. Go to http://www.yiiframework.com/doc/api/.
2. Put cursor on the left column search field and in context menu select "create search".
3. Enter "yii" to keyword field and save.
4. Close Opera.
5. Go to Opera's profile directory.
6. Open search.ini.
7. Find your search section by searching "yii". It should look like:
[Search Engine 24]
UNIQUEID=76AA614D8305D94BB62572AB5A59C224
…

8. Add the following to the end of the section:
Suggest Protocol=JSON
Suggest URL=http://www.yiiframework.com/api/suggest/?q={SearchTerm}&json=1

9. Save.
10. Start Opera and try typing "yii ca" in your address bar.
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

#17 User is offline   GOsha 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 24
  • Joined: 09-August 10
  • Location:Europe, Belarus, Brest

Posted 13 November 2010 - 06:37 PM

samdark - Молодец...))) А я не думал, что саджест к опере прикрутить мона. Можно вдвоем статейку накидать)))
0

#18 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 3,739
  • Joined: 17-January 09
  • Location:Russia

Posted 13 November 2010 - 06:43 PM

It seems there is a problem with cache headers. Yii website should send nocache headers to prevent wrong suggestions.
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

#19 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 3,739
  • Joined: 17-January 09
  • Location:Russia

Posted 13 November 2010 - 07:00 PM

GOsha
Good suggestion about two separate opensearches. Separate API search is a must have.
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

#20 User is offline   Antonio Ramirez 

  • Elite Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 1,450
  • Joined: 04-October 10

Posted 14 November 2010 - 03:53 AM

Thank you very much guys for your work... Works nicely
¿How long would it take for you to understand that you own nothing in this world?

www.ramirezcobos.com
www.2amigos.us
www.github.com/tonydspaniard
www.github.com/2amigos


Posted Image
0

Share this topic:


  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users