Project:Apache Solr Search Integration
Version:6.x-2.x-dev
Component:Code
Category:support request
Priority:normal
Assigned:Unassigned
Status:closed (fixed)

Issue Summary

I'm looking for suggestions on the best way to modify the search path from search/apachesolr_search/% to something more appealing to business editors. #327833: Allow Override of Core Search Path - /search was a similar request to what I'm trying to do but was marked as a duplicate of #337737: Re-Work get_path() so that the facet blocks can be used outside the search page. Rather than just allowing the blocks to work from any context I'd like to be able to have everything point to search/% or myterm/% instead of search/apachesolr_search/%

I've tried a few different options for doing this and can take them further but wanted to post here in case there is an easier approach that I am missing.

Comments

#1

Category:support request» feature request

I didn't find a better option so here's first attempt at a patch. It adds a new variable in the Advanced Configuration area that optionally replaces 'apachesolr_search' in paths with search/apachesolr_search/term when apachsolr replaces default search.

AttachmentSizeStatusTest resultOperations
apachesolr-524366-1.patch4.75 KBIgnored: Check issue status.NoneNone

#2

Status:active» needs review

#3

Here is same patch re-rolled for 6.x-1.x-dev

AttachmentSizeStatusTest resultOperations
apachesolr-524366-2.patch4.26 KBIgnored: Check issue status.NoneNone

#4

+++ apachesolr.taxonomy.inc (working copy)
@@ -41,7 +41,10 @@
+      $data = apachesolr_search_execute($keys, $filters, $solrsort,
+        'search'. variable_get('apachesolr_search_prefix', 'apachesolr_search'), $page);

Missed a / in 'search/'

I also added the appropriate lines to enforce a menu_rebuild() upon changing this setting.

The browse-by blocks and ability to search without keys stopped working; fixed with this: (a big fat hack?):

--- apachesolr_search.module 27 Aug 2009 20:07:02 -0000 1.1.2.6.2.111.2.10
+++ apachesolr_search.module 28 Aug 2009 17:37:31 -0000
@@ -165,6 +172,9 @@
       watchdog('search', '%keys (@type).', array('%keys' => $log, '@type' => t('Search')), WATCHDOG_NOTICE, l(t('results'), 'search/'. $type .'/'. $keys));

       // Collect the search results:
+      if ($type == variable_get('apachesolr_search_prefix', 'apachesolr_search')) {
+        $type = 'apachesolr_search';
+      }
       $content = search_data($keys, $type);

Maybe we need to put our efforts behind decoupling from core search to do this. You call, @robert..

New patch, please review.

AttachmentSizeStatusTest resultOperations
apachesolr-524366-4.patch5.93 KBIgnored: Check issue status.NoneNone

#5

Just an FYI that we just accomplished this by exposing everything to panel pages. Now we just create panels wherever we want search results.

#6

whoops, meant to reply to cyberswat...

#7

I don't suppose you would be interested in going into some detail? I don't understand, what do panel pages have to do with whether you can tell Drupal that /search now means, "use apachesolr_search and return results, but keep the url like this: http://mywebsite/search".

#8

nevermind, i figured something out.

#9

Mausolos, how do you resolve this issue?

#10

@mausolos We used ctools for integration and created several ctools content types based off of similar functionality in ctools. We re-implemented the following files from ctools in a custom search module and modified them to display information from this apache solr module:
ctools/plugins/content_types/block/block.inc as search_blocks.inc (implements solr blocks)
ctools/plugins/content_types/search/search_form.inc
ctools/plugins/content_types/search/search_result.inc

So, basically, what this gave us was the ability to create a panel page at any path other than /search and pass the arguments down ... you can see this working at http://www.boatingmag.com/find/boats (panel pages is /find arg is boats) and again at http://www.flyingmag.com/find/boats

I'm not about to step on the toes of the people maintaining this module but could put together a code based example if they are interested.

#11

cyberswat,
that'll be great if you can put together a code based example. I would like to learn more about how to achieve this.

thank you!

#12

or you could use apache solr views...

drupal.org/project/apachesolr_views

#13

or we can stick with non-alpha and non-beta releases for production environments ... That being said, the work that is happening around views 3 and apachesolr_views is exciting and will one day be very cool. I'll work on getting a code sample put together and posted tomorrow.

#14

cyberswat, do you get any chance to come up a example of this?
thanks

#15

+1, please provide steps on doing this

#16

+ $menu['search/' . variable_get('apachesolr_search_prefix', 'apachesolr_search') . '/%menu_tail'] = $menu['search/apachesolr_search/%menu_tail'];
+ unset ($menu['search/apachesolr_search/%menu_tail']);

If apachesolr_search_prefix is not set, or it is set to apachesolr_search, then you will unset it, and you will have no menu item for searching with Solr.

Anyway, what's so bad about doing this in a custom module:

<?php
function custom_menu() {
 
$items['search/custom'] = array(
   
'page callback' => 'custom_page',
   
'access arguments' => array('search content'),
   
'type' => MENU_CALLBACK,
  );
  return
$items;
}

function
custom_page() {
  return
menu_execute_active_handler('search/apachesolr_search/'. search_get_keys());
}
?>

#17

Status:needs review» needs work

CNW for above noted bug.

By the way, you can do one better with this patch. Core search (with search_get_keys) only assumes your search path is of the form: foo/bar/keywords. So, you can allow apachesolr users to set both the "foo" and the "bar" parts of the search path. The above path just allows the setting of the "bar" part.

#18

I'm working on a module based on some code I received from cyberswat. I'll look into starting a project for it, if not having it included as a contrib module under this project. Anyhow, I'll probably have some code ready this week for those interested in integrating Apache Solr Search with Panels.

#19

@ximo .. thanks for following through with that ... looking forward to the contrib project.

#20

cyberswat was kind enough to share his site specific code for placing Solr searches in Panels, and I refactored it into a more generic solution. Its name was obvious – Solr Panels!

http://drupal.org/project/apachesolr_panels

It's still very much alpha, but I'll be working on getting a stable release fairly soon for the sake of some sites we're working on. If you're familiar with Apache Solr and/or Panels and are interested in co-maintaining this, feel free to contact me :)

(Make sure to check out the easter egg on http://wiki.github.com/nodeone/drupal-apachesolr-panels/)

#21

thx, jpmckinney, that solution worked well!
I didn't want to change code of the apachesolr module, in case of updates. So I redirected within form_alter:

<?php
   
if( $form_id == 'search_block_form' ) {

       
$solr_search_urlprefix = 'search/apachesolr_search/';
        if(
strpos( $_REQUEST['q'], $solr_search_urlprefix ) !== false ) {
           
           
$goto = str_replace($solr_search_urlprefix, 'search/content/', $_REQUEST['q']);
           
drupal_goto($goto);
            exit;
        }
    }
?>

'search/content/%menu_tail' is then to be mapped to the function calling menu_execute_active_handler

#22

Category:feature request» support request
Status:needs work» fixed

Fixed in 7.x. For 6.x, people will have to rely on the solutions proposed in this thread.

#23

Status:fixed» closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

#24

Status:closed (fixed)» active

jpmckinney, there are several different solutions proposed in this thread. which one is the best and how exactly implemented? will this go to official release of the module?

#25

Status:active» fixed

This will not make it into any official 6.x release. See #16 and #21 for some implementations. Use whichever works for you.

#26

I tried to implement #16 and #21 by creating a new module, for some reason it did not work, maybe someone could show what and how exactly should be done to implement this?

#27

Status:fixed» active

Sorry for re-opening the request, but it is really not clear how to implement this. I tried #16, putting the following code in a custom module:

<?php
function custom_menu() {
 
$items['search/custom'] = array(
   
'page callback' => 'custom_page',
   
'access arguments' => array('search content'),
   
'type' => MENU_CALLBACK,
  );
  return
$items;
}

function
custom_page() {
  return
menu_execute_active_handler('search/apachesolr_search/'. search_get_keys());
}
?>

unfortunately, it did not work.

I also tried to put the following in template.php:

<?php
function mytheme_search_form($form) {

       
$solr_search_urlprefix = 'search/apachesolr_search/';
        if(
strpos( $_REQUEST['q'], $solr_search_urlprefix ) !== false ) {
           
           
$goto = str_replace($solr_search_urlprefix, 'search/content/', $_REQUEST['q']);
           
drupal_goto($goto);
            exit;
        }
    }
?>

cleared cache and tried to search it still gives search/apachesolr_search in url.

#28

@yngens

Try :

<?php
function mymodule_menu_alter (&$menu) {
 
$menu['search/custom'] = array(
   
'page callback' => 'custom_page',
   
'access arguments' => array('search content'),
   
'type' => MENU_CALLBACK,
  );
}

function
custom_page() {
  return
menu_execute_active_handler('search/apachesolr_search/'. search_get_keys());
}
?>

www.example.com/search/custom/something

#29

marthinal, thanks for the suggestion.

I have created custom module and named it 'csearch'. My csearch.module contains:

<?php
function csearch_menu_alter (&$menu) {
 
$items['search/custom'] = array(
   
'page callback' => 'custom_page',
   
'access arguments' => array('search content'),
   
'type' => MENU_CALLBACK,
  );
  return
$items;
}

function
custom_page() {
  return
menu_execute_active_handler('search/apachesolr_search/'. search_get_keys());
}
?>

Unfortunately, /search/custom/something does not give any results while /search/apachesolr_search/something works just fine.

#30

your code

<?php
function csearch_menu_alter (&$menu) {
 
$items['search/custom'] = array(
   
'page callback' => 'custom_page',
   
'access arguments' => array('search content'),
   
'type' => MENU_CALLBACK,
  );
  return
$items;
}
?>

try

<?php
function csearch_menu_alter (&$menu) {
 
$menu['search/custom'] = array(
   
'page callback' => 'custom_page',
   
'access arguments' => array('search content'),
   
'type' => MENU_CALLBACK,
  );
}
?>

http://api.drupal.org/api/drupal/developer--hooks--core.php/function/hoo...

doesnt return + you are altering $menu not $items in this case &$items you need in your function params

#31

yahoo, finally works. thank you, marthinal!

now, search form still returns the old path '/search/apachesolr_search/drupal'. is it possible to make it work with custom path? is it possible to redirect it with apache rules in .htaccess or #21 does that? if it does, where exactly that code should be placed in? i tried it placing in template.php and, unfortunately, it did not make any effect. maybe i can incorporate the code in #21 in csearch module?

#32

Subscribing

#33

#34

Status:active» closed (fixed)

I have created module page: http://drupal.org/project/custom_search_path

nobody click here