Closed (fixed)
Project:
Search API Pages
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
12 Dec 2011 at 05:54 UTC
Updated:
19 Aug 2014 at 14:08 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
rooby commentedHere is a patch to provide this.
* It adds an option to select what happens on an empty search (based on what apachesolr has).
* It adds a minor db update to set the default of the new option for existing pages.
* Adds some new empty search functionality to the search page view function.
There is one issue that this has, which is when using the option where facets display but no search results display, the current search facet block displays with [all items] in it, even though no results display.
This is because the search_api_facetapi module has a hack to add this to the current search block when there is nothing in the current search block.
- I don't know why this hack exists because I don't know why you want the current search block to display if it is empty. That is a question for drunken monkey.
However you can use hook_search_api_facetapi_keys_alter() to alter this.
See the search_api_facetapi.api.php file in the search_api_facetapi module for details.
It should also be possible to hack it out using hook_block_view_alter().
Comment #2
rooby commentedOops, I missed the whole point of the patch.
This one actually gives you results when you are searching on facets only.
Comment #3
owen barton commentedJust tested this and it works for me - thanks!
Leaving at needs review until the "[all items]" question is resolved.
Comment #4
mxwitkowski commentedHello -- this patch works quite nicely, but the Apache Solr Search Advanced Options have 4 options for the Behavior on empty search
Can the option to show enabled facets' blocks under the search box (and not show those facets in their configured region) be added to this patch? That would match the functionality and provide a very important option.
Comment #5
rooby commentedI don't see any reason why it couldn't be added.
The only reason I omitted it was because it is the most complex of the options, and I didn't have the extra time to spend on it (because the project I needed it for didn't need that option).
Comment #6
javdich commentedHey I really want to test out this functionality as this is what I'm looking to do. However im new to patching files... any chance this has been committed to the dev branch yet?
Comment #7
javdich commentedOk I finally figured out how to patch a module... After quickly testing this patch, so far so good. However I get a message at the top of the search page saying The following search keys are too short or too common and were therefore ignored: "".
I assume this is cause I am only using facets and don't have anything typed in the search box. Is there any way to remove the message?
Comment #8
rooby commentedIt hasn't been committed yet.
I don't think this module currently has a maintainer, because drunken monkey has been sick and unable to work on it.
Since it is a small module I'd be willing to help out with maintainership but I don't have masses of time I could allocate to it.
It would be in my best interest to allocate some time though as I am working on a long term project that needs some issue queue patches committed.
In regards to the current search block issue mentioned in #1 & #3, I have not checked since the new facetapi current search block but it might be resolved/resolvable now.
Comment #9
l0calh0rst commentedA quick question concerning patch in #2: how can i change the sort order of the empty search result?
Comment #10
rooby commentedI use the http://drupal.org/project/search_api_sorts module.
Comment #11
l0calh0rst commentedThat does the job perfectly. Thx.
Comment #12
rooby commentedAlso, I find the sort module better with the patch in #1369220: Rethink the UI of the sort block instead of copying facets
Comment #13
koechsle commentedWhat is the status on this functionality?
I think a lot of sites would need this. We do. Currently I have just hacked the module and moved it to modules/custom/ to avoid losing it when upgrading.
Comment #14
rooby commentedStill not committed yet.
As a tip for upgrading modules with hacks I recommend keeping a patch file of the hacks in the directory of the module, either from drupal.org or custom patches if you have other hacks.
Then you always know exactly what has been changed by looking in any path files.
Commit the patches to your version control and then remove them when they are no longer necessary.
Then if you are lucky you just have to apply the patch again when you update.
Also, if you have developer documentation, note what has been hacked, and why, linking to relevant drupal.org issues etc.
Comment #15
marcoka commentedits not possible to apply it to the latest version. it may be not commited because this feature belongs into facet api? i dont know.
Comment #16
rooby commentedNope, it belongs in this module.
The module maintainer probably just hasn't had time to review it.
Comment #17
drunken monkeyYes, that's exactly it. I'm very sorry, but I was first injured and am now still pretty busy looking at all the issues I missed.
In any case, this looks very good, well done! The hack with using
$_GET['f']for determining whether facets are set is a bit dirty (the parameter could, e.g., be called something else) – could you maybe try to find out whether there's a cleaner way?Also, it seems this needs a re-roll – I know, it's my own fault, but could you please take care of that?
Other than that, I'd happily commit this patch. Thanks a lot for your efforts!
Comment #18
rooby commentedThanks for the feedback.
I will get you a new patch sometime this week.
Comment #19
scor commentedstraight reroll of #2
Comment #20
milesw commented#19 works, thanks for the reroll, scor. However, I get the same message mentioned in #7...
The following search keys are too short or too common and were therefore ignored: "".Updated patch to only show this message when
$page->options['empty_behavior'] == 'none'Comment #21
ohthehugemanatee commentedUpdated the above patch to squash form_validate errors when submitting a search with no keywords.
IE if a given search page allows "facet only" behavior, you should be able to submit the search form with an empty keywords field.
This was useful for me because I use search_api_location (https://drupal.org/sandbox/madmatter23/1799850), which modifies the search form rather than adding a facet. I'm sure there are other similar use cases.
Comment #22
roderik de langen commentedHere is an updated patch for the latest dev version
I also fixed one small bug where the not operator was missing in the validate function
Comment #23
jhodgdonYou'll need to take this bit out of the patch:
Also, this patch still has the $_GET['f'] in it that was complained about earlier by the maintainer (see comment #17). So it probably needs to figure out a better way to verify that facets have been set.
Comment #24
roderik de langen commentedWeird how that info part came into the patch, anyways attached is the one without it.
And I totally read over that comment (#17), will try to break my brain on that point.
Comment #25
drunken monkeyI don't think you even need to, or should – just execute the search in any case, and maybe check afterwards whether filters were set and a result should be displayed. As ohthehugemanatee points out, things like location search could also add some filter that could lead to the search being valuable even though no keys were given.
On the other hand, things like node access could also set filters, so maybe that's not so ideal after all … Maybe just check for any additional
GETparameters?In any case, I don't think
search_api_page_search_execute_empty_search()is needed – just set$limitto 0 for the search.Comment #26
jagermonster commentedI have removed the search_api_page_search_execute_empty_search() and instead using search_api_page_search_execute() with limit set to 0 to create the facet only search page
Find attached the patch. its basically identical to search_api_page-show_empty_search_results-22-1235026.patch exept for the change to use the search_api_page_search_execute() function instead
Comment #27
drunken monkeyThanks for reworking your patch!
However, there's still a lot of issues I found with it:
Please use single quotes where possible.
Please use the proper format for documentation comments and leave an empty line above it.
According to the API, you shouldn't use module (especially CRUD) functions in update hooks. Please rewrite to use just database functions.
Or, just leave the update hook out entirely, and check for the existence of the option everywhere you use it. To make it easier, you can also just use an empty string instead of
'none'as the first option, so can just useempty()for checking for that.Why not just check for
'none'here, instead of both of the others?I wouldn't explicitly check for
$_GET['f']here, as that's pluggable. Just execute the search in any case and afterwards check whether there were filters set. (#1390598: Add a way to easily identify facet filters inside the query would of course help with that.)Why wouldn't we want to display ignored keywords for other settings of the empty behavior?
Please keep to the coding standards.
Also, use
NULLhere instead of an empty string (also insearch_api_page_search_execute()below).Comment #28
j3ll3nlWill there be new work on this?
I would really like to have this funcitonality in production env.
Comment #29
acrazyanimal commented@'drunken monkey' Hey there I am working on re-rolling the patch with the changes you've suggested in #27 above. I agree that it makes sense in 5. that $GET['f'] not be included here, but I am having trouble figuring out how to determine if any other add-ons (such as the facet api) have added additional filters on the query. I checkout out the Search API issue link you posted (#1390598: Add a way to easily identify facet filters inside the query) and scoured through the commits around that time, but don't see how this was implemented.
Can you point me in the right direction of how I can determine this so that I add a conditions in the following if...
to something more like:
Here is an update of the patch, but with the $GET['f'] still in there. Otherwise it cannot work as is. However, if you can point me to the right place then I can update that if with something not involving a facetapi specific query param.
Comment #30
acrazyanimal commentedComment #31
drunken monkeyThanks a lot for re-rolling and working on this!
Attached is a version which fixes this last problem (as well as a few coding standards problems) and would be ready to be committed in my opinion.
Please test/review!
Comment #32
summit commented@drunken monkey ...Sorry...no attachment
greetings, Martijn
Comment #33
kostajh commented@drunken monkey I'd be happy to test the latest patch once you submit it.
Comment #34
drunken monkeyOops, sorry! Here it is.
Comment #35
acrazyanimal commentedIt works for me just great. I've marked it RTBC, but you may want additional feedback from others.
Comment #36
drunken monkeyThanks for testing!
However, upon re-testing finally before committing I saw that empty searches actually produce a "No valid keywords present." warning when using the database backend. That of course shouldn't happen – it seems we were sending an empty string instead of
NULLas the keywords for empty searches, causing this problem.The attached patch should fix this problem, too. Please test/review!
Comment #37
mparker17SearchApiQueryFilterInterface::getFilters()will actually return an array with BOTHSearchApiFilterobjects AND arrays (consisting of a field, a value and an operator)... the logic to determine if a search had facet filters set (insearch_api_page_query_has_facets()) wouldn't recognize thearray(field, value, operator)case.I've improved the logic to ask the
FacetapiAdapterobject for it's active items.Comment #38
mparker17Comment #39
mparker17Whoops, looks like I used some functions from the
facetapimodule and forgot to check that it's installed and enabled first.Fixed patch attached.
Comment #40
mparker17While I can't review my own code, I can review the code in the patch in #36 to help move this issue forward...
An empty value for this option could have problems in some browsers.
According to the HTML4.01 specification, "If a control doesn't have a current value when the form is submitted, user agents are not required to treat it as a successful control." and "A form data set is a sequence of control-name/current-value pairs constructed from successful controls".
In other words, if a user selects "Just show the search box", a browser might not POST the
empty_behaviorcontrol at all, meaning form validation could fail if a user selects "Just show the search box".As far as I can tell, this currently wouldn't cause a problem because
empty_behavioris not a required field; however, it's conceivable that someone mighthook_form_alter()this form and makeempty_behaviorrequired.According to the Drupal coding standards, "Use an indent of 2 spaces, with no tabs.": this line has 6 spaces when it should have 4.
Other than those two things, the code in #36 looks good.
It works on my site; but I haven't yet tested all aspects of the patch.
Comment #41
drunken monkeyThanks a lot for your work! You're right, I was mistaken in assuming that all facet filters will be set as filter objects, I seem to have been confused myself there.
Your approach looks very clean and also seems to work fine, thanks! I just adjusted it to use the known "searcher" ID for the currently used index, since the previous code could have been a little buggy in situations with multiple searches on a single page.
Thanks also for spotting the indent error! This and a few other style issues should now also be fixed.
I'm pretty sure the empty key won't cause any problems, though.
Anyways, patch attached, please make sure it still works for you, everyone!
(Also, it's remarkable how popular this is, I don't think I've ever had a patch with so many contributors … We should really get this in now!)
Comment #42
mvci didn't do a thorough code review, but i can say that #41 worked for me -- thanks!
Comment #43
drunken monkeyWould have been good to get a few more reviews, but it'll probably be alright.
So, (finally) committed.
Thanks again everyone for all your help! Never had such a large commit message. ;)
Comment #46
betz commentedOne thing to notice, and is quite important in my case, is that if you start your browsing with filtering some facets, and after that search for a term, the filtered facets are reset. This because the query parameters are ignored.
In
Attached a patch.
Comment #47
betz commentedComment #48
drunken monkeyThat's a completely different issue, please create a new one instead of resurrecting fixed ones.
Comment #49
betz commentedWell, don't want to nitpick, but its this fix that created that issue in the first place.