[Intermediate] Add your site to users browser Search Engine List with Open Search


(Jaco Roeloffs) #1

Hi,


Thought I’d share this one with fellow Matrix users. This takes [topic=“5409”]the original post[/topic] by Julz a bit further.



“Open Search” has been accepted and built into IE 7+ and FF2+. This means you can add some code in order for users to search your site from the comfort of their own browser.

To take it up to the next level you can also implement live search suggestions like Google does. Both Browsers support search suggestions.



Here are 2 images of Open Search in action in both browsers:

[attachment=405:opensearch_ie.png][attachment=406:opensearch_ff.png]



[size=4]There are 3 parts to this excercise:[/size]

[list=1]

  • Basic functionality to get your site ready to be added to a Users Browser Search Engine list
    [*]Add a line of code to your design template for "Auto Discovery"
    [*]Getting the Search Suggestions to work, could be considered lots of work or "advanced" that involves using Search Pages to create a JSON response etc.



    [size=4]1. Creating the XML file for your site:[/size]

      [*]Create a new File asset and apply a "blank" design to it.
      [*]Add the XML in accordance with "Auto Discovery" specs:
      [/list]
      [codebox]
      <?xml version="1.0" encoding="UTF-8"?>
      <OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
      <ShortName>YourCo</ShortName>
      <Description>YourCo Search Engine</Description>
      <Url type="text/html" rel="self" template="http://<your_co_url>/search?queries_all_query={searchTerms}"/>
      <Url type="application/x-suggestions+json" rel="self" template="http://<your_co_url>/xml/open_search?queries_all_query={searchTerms}"/>
      <Image width="16" height="16" type="image/x-icon">http://<your_co_url>/__data/assets/file/0018/12445/favicon.ico</Image>
      <Developer>Your Name</Developer>
      <Contact>you@<your_co_url>.com.au</Contact>
      </OpenSearchDescription>
      [/codebox]
      [list]
      [*]Make sure the asset is live with allow unrestricted set to "Yes".
      [/list]


      [size=4]2. Auto Discovery:[/size]
      In your site design HTML template add the following line of code between the "head" tags to enable the "Auto Discovery":
      You can place this tag on specific pages only if you prefer (like your site's official search page only; refer to the design manual on how to do the design customisations).
      [html]<link rel="search"
      type="application/opensearchdescription+xml"
      href="http://<your_co_url>/__data/assets/file/0013/22540/yourco_search.xml"
      title="YourCo Search" />[/html]


      [size=4]3. Search Suggestions:[/size]
      This functionality provides the user with suggested pages or phrases returned from your site "as-you-type" in the search box.
      For this example I am returning a list of pages that match the query. (I have not tried anything with thesaurus and terms etc. yet)
      In this application, say you type "training" then you will get your exact page matches in the list of suggestions, if you click
      on 1 of those suggestions you will go directly to the page listed. if you dont, and just press enter or "Search" you wil be taken
      to your site's Search page with the keyword "training" and results.

      [color="#8B0000"]Disclaimer:
      [list]
      [*]I managed to get this to work, but... I'm not sure how this will perform with a large amount of users, security etc.
      [*]I used 3 assets to generate the correct valid JSON, if anyone has ideas for a better way, of doing it, please post it in this thread.
      [*]A bug in Matrix stopped me from implementing this functionality. This bug "Auto Discovery" has only been fixed on 17 July 2009, so you may have to make sure your system has the latest patches applied before expecting this to work 100%.
      [/list]

      Note: you have to have the xml File described above in part 1 working on your site before you can do part 3.

      The "Auto Discovery" will need to be followed carefully.

      [list]
      [*]Create a standard page ("Open_Search"); apply a "blank" design to it.
      [*]Create a Search Page ("Search_1"); apply a "blank" design to it.
      [*]Pick a root node, pick your asset types to return, limit to 10 assets (or your choice) (I left the rest default)
      [*]Remember to specify the Search field(s), for my example I just used 1 field that searches all asset fields and called it "all"
      [*]In the "Default" Type Format make the 1 textbox: Presentation:"Raw HTML" and Content Type:"Raw HTML"
      [*]Add:
      [/list]
        "%asset_name%",

    [list]
    [*]Create a Position -1 Format make the 1 textbox: Presentation:"Raw HTML" and Content Type:"Raw HTML"
    [*]Add:
    [/list]
        "%asset_name%"

    [list]
    [*]In the "Results Page Layout" make the 1 textbox: Presentation:"Raw HTML" and Content Type:"Raw HTML"
    [*]Add:
    [/list]
        [%result_list%],

    [list]
    [*]Create another Search Page ("Search_2"); apply a "blank" design to it.
    [*]Pick the same root node(as in Search_1), pick the same asset types to return(as in Search_1), limit to 10 assets (or your choice) (I left the rest default)
    [*]Remember to specify the Search field(s), for my example I just used 1 field that searches all asset fields and called it "all"
    [*]In the "Default" Type Format make the 1 textbox: Presentation:"Raw HTML" and Content Type:"Raw HTML"
    [*]Add:
    [/list]
        "%asset_url%",

    [list]
    [*]Create a Position -1 Format make the 1 textbox: Presentation:"Raw HTML" and Content Type:"Raw HTML"
    [*]Add:
    [/list]
        "%asset_url%"

    [list]
    [*]In the "Results Page Layout" make the 1 textbox: Presentation:"Raw HTML" and Content Type:"Raw HTML"
    [*]Add:
    [/list]
        [%result_list%]

    [list]
    [*]Once done setting the 2 search assets up; it will be up to you how much tweaking you want to do on those 2 search assets including tidying up the "no results" bodycopies etc. But I would recommend doing this once you got it all working.
    [*]Next, go and edit your Standard Page "Open_Search"
    [*]On this page you will end up with 4 bodycopies.
    [*]First: 1 textbox: Presentation:"Raw HTML" and Content Type:"Raw HTML"
    [*]Add:
    [/list]
        ["%globals_get_queries_all_query%",

    [list]
    [*]Second: Nest Content: Presentation:"Raw HTML" and Content Type:"Nest Content" -> Here you nest "Search_1"
    [*]Third: Nest Content: Presentation:"Raw HTML" and Content Type:"Nest Content" -> Here you nest "Search_2"
    [*]Fourth: 1 textbox: Presentation:"Raw HTML" and Content Type:"Raw HTML"
    [*]Add:
    [/list]
        ]

    [list]
    [*]For the 2 Nested Assets you will need to add a variable in the section "Send the following additional GET variables to the asset:" for each.
    [*]I called this variable "queries_all_query" and the value set to: %globals_get_queries_all_query%
    [*]Now you are ready to test and see if you get the valid JSON
    [*]Use the/a url: "http://<your_co_url>/xml/open_search?queries_all_query=Hello" in your browser to see the results and compare with specs to see if it complies.
    [/list]

    This is the basic setup, you will most probably need to fiddle around to get it just right to fit your requirements.
    Then you can add and remove Your Co search engine to your browser to test. Remember when you make changes to the XML file in point 1 you will have to re-add it to your browser for the changes to take effect.

    Good Luck!

    Jaco.


    Handy tips for Open Search on this Page:
    "Auto Discovery" opensearch_ie.png (19.5 KB) opensearch_ff.png (12.6 KB)

  • (Duncan Robertson) #2

    That looks really good! How intensive it would be my biggest question. Have you done any stress testing or something similar?


    (Jaco Roeloffs) #3

    Thanks Duncan,

    I havent done any stress testing, I am currently still waiting for our system to be patched before I can run a real test. I will see how it goes and post the results here.