Hi,

Attached to this you have the code that searches through the result xml and reorders the search results based on the number of items that come from a certain domain name (both the number and domain name are set in the function) .

-- WHY WAS IT CHANGED --

The customer wanted to have the ability of promoting to the top of the first search page results that come from a certain domain. The "out-of-the-box" module functionality did not support such a feature, therefor a custom implementation had to be done

-- WHAT WAS CHANGED --

Added variables and explanation
- $promoted_items_to_top_of_search - integer : number of promoted items to be placed at the top of the first search page (currently set to 5)
- $promoted_items_domain_name - string : items to be promoted to the top of the first search page will be fetched from this domain name on a first occurrence basis

- $promoted_results - empty array : temporary array that will hold the information of promoted items found from search result.
- $occurrence - integer : counter used to determine the number of currently found items that are to be promoted

Background information
- the google_appliance_parse_device_response_xml parses a raw xml coming from google_appliance_search_view

google_appliance.module : added logic starting at line 472
- the 3 conditions of the IF statement explained :
- check if the current item was fetched from the promoted_items_domain_name. The format of the url is always "http://www.some-domain-name.fi", therefor we check only for "some-domain-name" by excluding the "http://www." part of the string and continue the comparison by the length of $promoted_items_domain_name. If the values are matched, we have a winner. AND
- we make sure that we do not exceed the number of $promoted_items_to_top_of_search by comparing it to the $occurrence counter. AND
- we check if we are on the first page. 2nd, 3rd ... Nth search pages have the "?page=n" argument attached to the url and the first page doesn't, so we check for it.

- once all 3 conditions are met :
- the $occurrence gets incremented
- we add the result's domain ($result['result_domain']) to the result array (to be used later, read on)
- we store the result in the $promoted_results['entry'] array

- if any of the 3 conditions are not met :
- the result is either not coming from the domain name, either we already have the required no of $promoted_items_to_top_of_search, either we are not on the first page of the search result
- add the result array to the $results['entry'] array

- after we have gone through all of the raw xml we check for if the $promoted_results exists
- if it does => we have results that need to be at the top of the search page and we merge the $promoted_results with the (non-promoted) $results
- if it doesn't => the proverbial "sh*t happens" and we move on

- return the $results array

This is by no means a generic solution but could be if somebody has the time to do it. The attached function can be a starting point.

This is my first ever contribution to anything related to Drupal so whip me 'til I bleed because I haven't done this properly.

Comments

mpgeek’s picture

Thanks for the clear explanation of what you are trying to accomplish and how it was done. If there were a patch, It'd be much easier for the maintainers to have a look at the code and such. Learn about patches here...
http://drupal.org/contribute/development

Also, did you consider setting up keymatches on the GSA device and using that functionality to "bubble up" results? Perhaps I misunderstand what you are actually trying to accomplish. That's why a patch would be good here... thanks for getting involved.

Cristian.Andrei’s picture

StatusFileSize
new67.05 KB
new3.63 KB

Hi,

I created a patch and attached it to this post. Also, I've created a screenshot of what we achieved (the user can distinguish easily results coming from different domains => better UX). I forgot to mention in the initial post that a change needs to be made in the theme/google-appliance-result.tpl.php but included it in the patch.

I wasn't aware of the "bubble up" functionality that GSA offers so that's why I cooked up this implementation.

mpgeek’s picture

Status: Needs work » Postponed

Postponing, as this is a very specific use case that is not general enough to bring into the module. I'd be happy to create a branch if others think it is useful across many use cases.

iamEAP’s picture

Status: Postponed » Closed (won't fix)

For the sake of cleaning up the issue queue, I'm going to close this.

I believe everything the OP wanted to do is now possible by implementing hook_google_appliance_results_alter() as well as maybe a template override.