Problem/Motivation
The apachesolr module provides a search form block for the default 'Core Search' page. This block cannot be used for additional search pages configured in the 'Pages/Blocks' tab under 'Settings' -> 'Apache Solr search'.
Proposed resolution
A search form block should be provided for every configured search page.
Remaining tasks
The patch in this ticket has been reviewed en tested by several people, so the solution seems ready to go into a stable release.
User interface changes
For every configured search page, a 'Apachesolr search form : [search page name]' block is available in the blocks configuration page.
API changes
None
Data model changes
None
Original report by vistree
Hi, how can I create a search block like drupals core search block?
Or is it possible to use the core to run Solr-quries?
Regards
vistree
Comment | File | Size | Author |
---|---|---|---|
#62 | apachesolr-add_search_block-326375-62.patch | 1.88 KB | Greg Boggs |
#61 | interdiff-326375-46-61-do-not-test.diff | 1.56 KB | herved |
#61 | apachesolr-add_search_block-326375-61.patch | 1.75 KB | herved |
| |||
#46 | apachesolr-add_search_block-326375-46.patch | 1.87 KB | cgmonroe |
#41 | add_search_block-326375-41.patch | 1.59 KB | drikc |
Comments
Comment #1
robertDouglass CreditAttribution: robertDouglass commentedwhether you use the core search block or create a new one, you'll want to set the action of the form to be search/apachesolr_search. The action of the core form is search/node. This means you can probably use form_alter to change the action on that form. Or you can create a new search form in the block.
I'm marking this as a feature request and changing the title because I think the module should either ship with its own block, or hijack the existing one.
Comment #2
vistree CreditAttribution: vistree commentedThat is great. Thank you for reply.
Where can I change the behaviour? In the template.php?
And can you tell me the correct code for this?
Thank your very much!
vistree
Comment #3
robertDouglass CreditAttribution: robertDouglass commentedYour own custom module is the place where you would implement hook_form_alter. I don't have the exact code for this but you can get a start by reading the API docs: http://api.drupal.org/api/function/hook_form_alter/6
Comment #4
JacobSingh CreditAttribution: JacobSingh commentedHey Robert,
Didn't you have me and my dad put this functionality in search_config a couple months ago? (where is is now committed).
Best,
Jacob
Comment #5
vistree CreditAttribution: vistree commentedThank you for the link.
My problem is, that I am no programmer and don't know how to create my own module.
I thought that it would be much more easier to generate my own Solr search block, e.g. by adding a "print ... " in a newly created block.
Is there some more information on how to create such a module or block? Or maybe an already existing example?
Regards
vistree
Comment #6
pahariwalla CreditAttribution: pahariwalla commented@jacobsingh - I believe you are correct. current dev 5.x-1.4 of search_config module contains that patch (http://drupal.org/project/search_config )
@vistree - after enabling the Search Config module, go to admin/settings/search (Site Configuration | Search Settings). Under "Advanced Search Confuration" you will see "Default Search" which lists of all modules that hook into search. Whichever one you select will cause the Drupal search box to take you to that results tab.
Hope this is what you are looking for.
Comment #7
vistree CreditAttribution: vistree commentedYes, that is what I am searching for ;-)
Unfortunately I work with Drupal 6 - where is currently no version of the mentioned module above ;-(
Is there an alternative?
Regards
vistree
Comment #8
Anonymous (not verified) CreditAttribution: Anonymous commentedWell, not sure if anyone is interested in a followup with this but here's what I did. Dead simple:
Created a block, PHP input filter, with the following code:
Good to go. Substitute the path to your install in the form action.
Hope that helps.
Comment #9
vistree CreditAttribution: vistree commentedThis is great and works well. It is what I was still looking for - thank you!!
Regards
vistree
Comment #10
David Lesieur CreditAttribution: David Lesieur commentedThis is still valid as a feature request since it would be useful if the module provided its own search block.
Comment #11
pwolanin CreditAttribution: pwolanin commented@David Lesieur - we are planning code to decouple this module from it's dependence on core search, in which case we will certainly provide a separate search block.
Comment #12
coupet CreditAttribution: coupet commentedI think we should suggest an interim solution [Apache Search Block] in module Documentation.
Comment #13
zzolo CreditAttribution: zzolo commentedThe way the search_theme_form ($search_box variable in the page.tpl.php file) actually goes to the search page is through a redirect in the submission, so we have to add a submission, then redirect it. (May be a more efficient way, but this works)
Comment #14
pwolanin CreditAttribution: pwolanin commentedsee: http://drupal.org/node/405206
Comment #15
Anonymous (not verified) CreditAttribution: Anonymous commentedCode from #13 doesn't work for me. Using Drupal 6.13 and solr 6.x-dev 12th of august.
While custommodule_form_alter() is called, the custommodule_search_submit() is not... So is $form['#submit'][] correct?
P.S. I changed back from duplicate, because it hasnt been committed to the august 12th dev version either. And nowhere is the real solution patched.
Comment #16
robertDouglass CreditAttribution: robertDouglass commentedI agree that it's not a duplicate, and it's one of the tasks that we need to handle to totally decouple from search.module. But there is no patch, it's an active issue, and it is for 6.2.
Comment #17
Anonymous (not verified) CreditAttribution: Anonymous commentedI have "Make Apache Solr Search the default:" set to Enable, which is supposed to redirect the Search Block. But it doesn't work... Only for normal form on /search page
Comment #18
Anonymous (not verified) CreditAttribution: Anonymous commentedComment #19
Anonymous (not verified) CreditAttribution: Anonymous commentedComment #20
Anonymous (not verified) CreditAttribution: Anonymous commentedSolution found! It's an incompatibility with search_config.module! They do this:
Which overrides apache_solr's redirect... I'm just going to deactivate this module. Rather use Solr at all than have this extra.
Comment #21
ducdebreme CreditAttribution: ducdebreme commentedsubscribing
Comment #22
janusman CreditAttribution: janusman commentedI think this is solved? Closing out
Comment #23
tbenice CreditAttribution: tbenice commented[edited to add a final sippet at bottom]
I wanted this and started out using the solution in #8, but I wanted to keep the spelling suggestions and retain filters functionality in the block form. I thought I'd post my little solution here.
1) create a block using php with the snippet:
2) in your .module file, put a function that recapitulates the apachesolr_search_form_search_form_alter code minus the first conditional statement that selects only forms with ['module']['#value'] == 'apachesolr_search'. Like this:
Please note the second line which is added to set the action to search/apachesolr_search.
Also note the added snippet:
and the line:
which keep the filters and the status of retain-filters=1 when the checkbox is ticked.
Cheers.
Comment #24
maxmmize CreditAttribution: maxmmize commentedI followed #23but i get sent to: search/node/Name the module mymodule
Comment #25
twom CreditAttribution: twom commentedThe solution #23 can be simplified if you use
This will populate ['module']['#value'] with the value apachesolr_search. This means that the default apache solr submit handler will be used!
Comment #26
butler CreditAttribution: butler commentedJust a note to others who might not get this right away - the simplification suggested in comment #25 refers to step 1. in #23 above. I was poking around in the suggested module code for a bit before I realized this...
Comment #27
esbon CreditAttribution: esbon commentedHi, I have a similar need which is not redirecting a form the this page: search/apachesolr_search. I recently installed apache solr autocomplete and I would like to just paste this form: search/apachesolr_search on block. Can someone please help deploy this?
Comment #28
esbon CreditAttribution: esbon commentedPost #11 is very good news, do we know when this will happen? Having a an ApacheSolr search block would be the answer to my prayers!
Comment #29
tbenice CreditAttribution: tbenice commented2x to #28. Also, I'd love to see a search block that can limit search to contexts and return results to any arbitrary url. I'm thinking right now of a block for og search that returns results from within a group context to the group page/search. Is that sort of flexibility feasible?
Comment #30
pixelsweatshop CreditAttribution: pixelsweatshop commentedsub
Comment #31
cafuego CreditAttribution: cafuego commentedSo um, will there be a 6.x-2.x release ever? Or at the very least a release of a 6.x-2.x-beta module?
As it stands, this is a problem with 6.x-1.x and there are no other releases available unless you expect people to fetch them using git. In which case I don't think you'll get many testers.
Comment #32
Nick_vhcafuego - The 6.2 will be phased out. We are stabilizing the D7 version first so we can backport all of the functionalities for D7 to D6 version. This will be 6.x-3.x release and will be started in this month and hopefully it will see it's completion soon.
Comment #33
cafuego CreditAttribution: cafuego commentedOk. I should note btw that in 6.x-2.x-beta5 the search block doesn't seem to be using solr, but instead still defaults to the core node search. I've added a submit redirect in a custom module to work around that for the moment.
Comment #34
Nick_vhThe 6.x-2.x version has been deprecated. Moving this to 6.x-1.x-dev
Comment #35
Nick_vhNot sure if this is already resolved in the 7.x-1.x branch before backporting this to 6
Comment #36
naeluh CreditAttribution: naeluh commentedHas this been back ported to 6x yet ?
Comment #37
ryan.gibson CreditAttribution: ryan.gibson commentedSo this stalled out.
Comment #38
vonFrakas CreditAttribution: vonFrakas commenteddrunken monkey's excellent Search API Pages module provides a search form block (once you configure a search page):
drupal.org/project/search_api_page
I found this module while watching his screencast here: https://vimeo.com/15556855
These links can also be found on the Search API project page.
Comment #39
thePanz CreditAttribution: thePanz commentedThere is an (outdated) module here: https://drupal.org/sandbox/incrn8/1315802
I am working at porting it to latest D7 release of ApacheSorl.
Or it is better to work for an integrated solution instead of a separated module?
Comment #40
drikc CreditAttribution: drikc commentedThe attached patch add a search form block for each existing search page.
Comment #41
drikc CreditAttribution: drikc commentedThis patch fix the #40 (an issue with the keys selection in item menu).
Comment #42
thePanz CreditAttribution: thePanz commentedI created this sandbox project: https://drupal.org/sandbox/thepanz/2239871 please stay tuned few days for first code commit.
Comment #43
drikc CreditAttribution: drikc commented@thePanz, did you tried the patch in #42? Despite it didn't involve much codes I've packed this also as a sandbox module as I didn't want to patch apachesolr for a project.
Comment #44
thePanz CreditAttribution: thePanz commented@drikc: I didn't test your patch, no time to test it right now
Here: https://drupal.org/sandbox/thepanz/2239871 you can find my module with latest updates, it allow multiple page-blocks to work together, and (with a patch) to correctly integrate with ApacheSolr Autocomplete module.
We should join our forces to provide a common solution for this issue :)
Regards
ps: my module also includes CTools-Exportables settings
Comment #45
asb CreditAttribution: asb commented@thePanz: Do I understand it correctly, that your sandbox module (#2239871) is for D7 only and the other sandbox module (#1315802) from 2011 was for D6, but is even two years older than the current recommended release for 'apachesolr' (6.x-1.8 from 2013-Apr-11, which is about one year old)?
So basically there is nothing available for Drupal 6/Pressflow that provides the requested functionality and works out of the box? (I'm asking because I'm struggling to get Apachesolr integrated into Drupal; 6.x-1.8 seems not to integrate much anywhere).
Comment #46
cgmonroe CreditAttribution: cgmonroe commentedTried the patch in #41 and it would not display the search form on all pages. This was because the More Like This code will run even if the block delta is for the search form.
The fix for this was to move the hook_block_view code above the MLT code and wrap it in a test for search_form_* delta requests.
Here is an updated patch for this.
Comment #47
Koen.Pasman CreditAttribution: Koen.Pasman commentedAmazing how a topic of 6 years old can still be relevant :)
Anyway, I needed per ApacheSolr search a block, and the patch in #46 does this wonderfully well, thanks a bunch!
Comment #48
NitebreedPatch does the job!
Comment #49
janusman CreditAttribution: janusman commentedRe-phrasing title. NOW I get it :)
Comment #50
vistree CreditAttribution: vistree commentedThis is great. Patch solves my need!
Comment #51
thePanz CreditAttribution: thePanz commentedWhat about integrating the module https://www.drupal.org/sandbox/thepanz/2239871 with your patch (it includes also CTools exportables integration) :)
Comment #52
ckngTested #46 working.
Comment #53
jsst CreditAttribution: jsst at Ibuildings commentedI too can confirm patch #46 is legit! I've updated the issue summary to reflect the current situation.
Comment #54
jsst CreditAttribution: jsst at Ibuildings commentedComment #55
jos_s CreditAttribution: jos_s commentedPatch #46 indeed gives me search boxes for each search page, but I experience some issues:
The standard search block is not affected by this.
Comment #56
arbel CreditAttribution: arbel commentedI have the same issues as Jos_s, getting error messages when trying to access blocks page.
Comment #57
nixar CreditAttribution: nixar commentedSame as #55 (I didn't try the suggested solution of changing the table structure)
Comment #58
tlor24 CreditAttribution: tlor24 commentedThis works great but if you need to have multiple search blocks on the main navigation, you will run into the issue of both search form using the same search path.
In our case, we had the default search form up in the header, one apachesolr search block form in one dropdown menu, and another apachesolr search block form in another dropdown menu. In this case, there are three search form all searching in differen solr environment but somehow uses the same search path even with the solr environment setup correctly in the solr page config.
Hopefully this will save some headaches for others.
Here is an updated code from patch 46.
Comment #59
BlackIris CreditAttribution: BlackIris commentedJust a heads up, plugged in this patch to our site and immediately ran into this error:
PDOException: SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'delta' at row 1: INSERT INTO {block} (module, delta, theme, status, weight, region, pages, cache) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7); Array ( [:db_insert_placeholder_0] => apachesolr_search [:db_insert_placeholder_1] => search_form_taxonomy_search_designs_only [:db_insert_placeholder_2] => pixel_minimal [:db_insert_placeholder_3] => 0 [:db_insert_placeholder_4] => 0 [:db_insert_placeholder_5] => -1 [:db_insert_placeholder_6] => [:db_insert_placeholder_7] => -1 ) in drupal_write_record() (line 7361 of /srv/www/pixelscrapper.com/public_html/includes/common.inc).
The problem was we had some long page names, and the $delta ended up being too long, causing the block page to be inaccessible. Upon changing the page names worked fine. Something probably needs to be entered into the code to check for this.
Comment #60
JordanMagnuson CreditAttribution: JordanMagnuson commentedI also ran into the issue in #59. We need to check strlen($delta) and abbreviate in some way if too long (could chop $delta down to size and add number at end if necessary to prevent conflicts in $delta name).
Comment #61
herved CreditAttribution: herved commentedHello everyone,
I noticed that the $keys passed to apachesolr_search_custom_page_search_form() are not retrieved successfully.
It should be offset by -1 if I'm not mistaken but here is a better approach using apachesolr_has_searched() and apachesolr_current_query().
Issues reported in #58 and #59 are still valid though :\
Comment #62
Greg BoggsThis patch combines #58 and #61 to work with the latest dev release of apachesolr. I did not experience problems with my delta being too long, so I didn't attempt to add code for that. We should follow up with a different issue about maximum page name length.