How to Use Drupal Search In Standalone PHP Page? - search

I followed the instructions # Drupal: how to access to Drupal's APIs with a standalone php script? , however, my search query is returning 0 results (an empty array). I have confirmed that the same search term returns a result if executed from my drupal web page.
<?php
chdir("drupal");
define("DRUPAL_ROOT",".");
require_once './includes/bootstrap.inc';
include 'drupal/modules/search/search.api.php';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
$keys = array("harry","potter");
$result = hook_search_execute($keys);
print_r($result);
?>
Can anyone give me some pointers as to why this isn't working? Many thanks!

The problem is that you are calling hook_search_execute directly--this is only meant for API documentation.
So, no need to include search.api.php. Instead, take a look at search_data(), which calls a specific module (user module, or node module, for example) invoking that hook. If you are trying to search nodes, you can call node_search_execute() directly.

Related

How do I get the Alias Path/Node Alias in C# Kentico 12 MVC

I am using the standard DocumentHelper.GetDocuments to find a page, and for top level pages, the .WhereEquals("NodeAlias", pageAlias) is working fine, where pageAlias is along the lines of "Test-Page".
Once I start resolving child pages (so pageAlias = "Test-Page/Another-Page") DocumentHelper is returning null.
I am wondering if I can see the NodeAlias for the pages in C# somehow?
This should allow me to map the pages better.
"NodeAlias" is typically just the URL friendly alias for the page - "Another-page" for example. I believe you may be looking for "NodeAliasPath" which will give you the full alias path - "/Test-Page/Another-Page"

Searching Single Pages with Dynamic Content

I have a slight problem I have been trying to address for a client I have been working with. We have 4 sets of single pages that are loading content from a database using PHP based upon a get string that is provided. These pages that are generated are optimized well for SEO and have alt tags for images and Content that we need to be able to search using a search feature.
Now i had assumed (An everyone knows what assuming gets you) that these pages by default would be able to be searched by the concrete 5 built in search feature. But it doesn't work. If I search for a word that I know is definitely on one of these pages even multiple times no results are found.
How can I make Concrete5 search these pages. If its no do able by a default or by a plugin, then can someone please offer some advice on how to fix this. This is an important feature and must be completed.
EDIT: See my comment below. I still need some help or direction here as CSE inst much of an option.
EDIT2: It may be viable for me to install a crawler and a custom search engine to address my problems. I was thinking of spider. Any other suggestions on that or other options are much appreciated!
Unfortunately C5 doesn't provide a way to do this -- the only way to tap into the search index is with blocks. And even if you created a phony block just to pass content from the single_page through to the search index, there's no way to say that some content is from one URL while other content is from another URL (which you'd need to do since your single_page controller is handling many different URL's).
I don't know of a way to achieve what you want to do (and it appears that nobody else does either -- http://www.concrete5.org/community/forums/customizing_c5/make-content-in-single-pages-searchable/ ), other than building your own internal search engine.
EDIT: I just did some digging, and thought that perhaps you could manually insert records into the PageSearchIndex table and specify the searchable content and the desired path there -- but this won't work because it relies on one cID (collection id, a.k.a. page id) per entry -- so you'd only be able to insert one record for the top-level single_page path.
I think the simplest solution here would be to create your own searching infrastructure for your single_pages (like some kind of function in the controller that would return an array of page paths and searchable content for each one), then override the search block and perform an additional search of your single_page -- then combine the results on the search results page there. Or just use google site search for your site, which will actually crawl the pages and hence find your various single_page urls: https://www.google.com/cse/
Best of luck.
I have not tested this, but maybe you can put a function getSearchableContent() in the single pages controller like you do for blocks. This would return the string to be searched. Would look something like this:
function getSearchableContent() {
// ... compose searchstring depending on the queried content.
return $searchstring;
}
But I don't know if this works for dynamic content. If not, I'd look into C5's search index core classes and try to extend them for your project.

Putting islandora results in a view or block

I am new to islandora. I have it integrated with solr and it works fine but the results only show on the page with the following URL:
somesite.com/islandora/search
This is fine but I would like the results to show on a different page inside a view or a block.
Is this actually possible?
After reading the documentation it doesn't seem like it is. But I believe this should be a rather slandered requirement.
I have tried using URL Aliases, with no luck.
Has anyone done this??
If you have integrated the apache solr with sit Search then there is a module named Search API Page Block, which can help you showing result in block but it will only work for title of the nodes.
As it explains -
Currently, this module is only useful when placing search result
blocks on node pages, since it currently only uses $node->title as the
search keywords. Future development can lead to other uses, including
using Taxonomy terms, Context module, or custom fields to set the
keywords.

Codeigniter : how to pass hidden parameters in the url and make them available for parsing

I have an url like this :
www.domain.com/catalog/category_name/category_id/product_name/product_id
example :
www.domain.com/catalog/notebook/93/4_cpu_quad_core/56
and want it to turn into :
www.domain.com/catalog/category_name/product_name/
example :
www.domain.com/catalog/notebook/4_cpu_quad_core
The two ID parameters have to be passed to the application and parsed with PHP as I need it to get the correct category and product.
I have tried several ways using .htaccess and route.php config but no success !!
Can someone explain in simple manner how to pass these parameters to the web server while making these hidden in the url ?
I was just wondering if it is possible to pass hidden parameters in the url and make them available in the backend application (i.e. java or php).
Well! i wrote a function in the file system/core/uri.php
function assing_segment($num,$value)
{
$this->segments[$num] = $value;
return $this->segments[$n];
}
And call to this function either in the view or controller
$this->uri->assing_segment(5,$myvalue);
This will reassign segment 5 with my value
Can someone explain in simple manner how to pass these parameters to the web server while making these hidden in the url ?
There is no way to "hide" parts of the request. You can remove them, but then your application won't see them at all. For example, you can make all your URLs appear to be like www.domain.com/catalog/category_name/product_name/, but your php script isn't going to see anything about any IDs, since they're gone.

How to read and modify the contents of any page?

This is my first app so please pardon my lack of knowledge. As a demo app i would like to achieve the following things :
Stage 1 :
1 Read the contents of a page
2 Look for a regex match in the contents of that page
3 Replace them with something else
Stage 2 :
1 On submitting () text to a web page
2 Read the text that's about to get submitted
3 Look for a regex and replace it .
Could some one point in the direction of a similar app or make a small guide ? Any help is appreciated .
first of all, you need to insert a Content Script, the only way to access the page's content.
http://code.google.com/chrome/extensions/content_scripts.html
You can make a content script only extension to begin, but for more advanced extensions you should read about programmatic injection.
http://code.google.com/chrome/extensions/content_scripts.html#pi
From a content script you can access the page's DOM, and add listener to events in the usual way. For example, you can use document.getElementById() or element.addListener() .
There are many ways to look for a regexp, it depends the way you want to search the page, for example yo can use
document.body.innerHTML.replace(...);
Rob W gave you a nice hint to intercept submitting text with
chrome.webRequest

Resources