Jump to content

search 'rar' and 'tar' result in 404


Macrura
 Share

Recommended Posts

I have a site with a search form similar to the skyscrapers profile.

the strange thing is that if you put in a keyword for 'guitar' and a 2nd keyword (anything), a 404 is triggered (!)...

I can't figure out why this is happening, there are no errors in the log and no messages in the console;

all other keywords work fine, just the word 'guitar' + another word triggers the 404 not found...

Link to comment
Share on other sites

did some more testing; it's not about the word guitar, it's all words ending in tar, and the word rar when placed in the querystring before another keyword, so that those endings are followed by a + sign.

the problem seems to be related to the get string using the + instead of the encoded version of the + which is %2B? if i use %2B in the querystring then it works;

also not sure why i have to to the str_replace on my keywords to get my selector to work

if($input->get->keywords) {
    $keywords = $sanitizer->selectorValue($input->get->keywords);
    $keysearch = str_replace(' ', '|', $keywords);
    $selector .= "title|body%=$keysearch, ";
    $summary["keywords"] = $sanitizer->entities($keywords);
    $input->whitelist('keywords', $keywords);
}

wouldn't the sanitizer selectorValue do this for me?

if i don't so that str_replace, my selector comes out like this and it doesn't work:

title|body%=guitar lessons

if i do the str_replace, my selector looks like this:

title|body%=guitar|lessons
Link to comment
Share on other sites

This one is solved as far as the 404 - i just received a reply from the hosting people:

I confirmed that those were blocked by our mod_security rules.

still would be good to figure out about sanitizing keywords fields the correct way...

  • Like 1
Link to comment
Share on other sites

 

if i don't so that str_replace, my selector comes out like this and it doesn't work:

title|body%=guitar lessons

if i do the str_replace, my selector looks like this:

title|body%=guitar|lessons

Those are two different selectors. The first is looking for pages with the phrase "guitar lessons" in title or body. The second is looking for pages with the words "guitar" OR "body" in the title or body. If the first one is failing, then that would be because the phrase "guitar lessons" don't appear in the body of any pages exactly like that (though this is not case sensitive). This sort of thing can be affected by spacing too, so if you see "guitar lessons" on a page, view the source and see if there are actually two spaces between the words or perhaps a pesky   or something. You might also want to consider if "title|body~=guitar lessons" might be better for your needs here. That would match pages having both of the words in either the title or body, but they wouldn't have to be phrased together. 

Link to comment
Share on other sites

Those are two different selectors. The first is looking for pages with

the phrase "guitar lessons" in title or body. The second is looking for

pages with the words "guitar" OR "body" in the title or body.

aah - right, got it - thanks; so the str_replace seems the right way to parse a bunch of words into a pipe separated list, for use in the selector...

which brings up another question - i have a keywords field in my template which is a page field (asm select multi) -- how can i compare the keywords entered by a search user with the keywords that are selected/entered in the page?  i get MySQL errors so far when trying to work with that keywords field... gonna be tricky i guess, i'm doing a skyscrapers style search box with several dropdown selects and a keywords field

Link to comment
Share on other sites

aah - right, got it - thanks; so the str_replace seems the right way to parse a bunch of words into a pipe separated list, for use in the selector...

Rather than str_replace'ing in pipes, I'd suggest just using the "~=" operator to perform your search. That way it will track down your words without them having to be next to each other. It also requires that all the words are actually present, unlike "|" which is essentially saying "this OR that". I gather you probably want "this AND that", so ~= would fit the bill. 

which brings up another question - i have a keywords field in my template which is a page field (asm select multi) -- how can i compare the keywords entered by a search user with the keywords that are selected/entered in the page?  i get MySQL errors so far when trying to work with that keywords field... gonna be tricky i guess, i'm doing a skyscrapers style search box with several dropdown selects and a keywords field

If the keywords are page references, then you probably have to stop thinking of them as keywords and more as categories or tags, at least from the development side, and code it the same way. I'm assuming your keywords field is named "keywords" and that the words are stored in the "title" field. You could attempt to match the title of the keyword pages for all the words: "keywords.title~=guitar lessons". You could attempt to match the the title of the keyword pages for any of the words: "keywords.title*=guitar|lessons". 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By donatas
      Hello,
      how would I do a multi-language website search with just a selector?
      I have many multi-lang fields and I want to do a search through all of them at once and through all of their language values.
      Is there a "selector way" of doing this? Maybe something like `title|title:de|title:it`? It seems I have seen this somewhere a long time ago but can't find in any documentation or forum search...
      Or the only way of doing it is by running separate searches for each language with output formatting off and then consolidating it all in one single results array?
      Because I still want to give users a result, even if it is in another language than current $user. Visitors mostly will be searching for specific terms that are very similar in all languages, but might be not used in one language version of a single page, for example. Or the user might not have switched language tohis prefered and did the search first, etc.. (many use cases in my situation)
      Example:
      $pages->find('title~='.$q) - maybe different operator is needed? /en/search/?q=visit = 1 results /it/search/?q=visit = 0 results Thanks for any advice!
    • By sebr
      Hi
      In my search page, I used a selector like this :
      $searchQuery = $sanitizer->entities($input->get('q')); $searchQuery = $sanitizer->selectorValue($searchQuery); $selector = 'title|subtitle|summary|html_body_noimg~=' . $searchQuery; $matches = $pages->find($selector); I don't have the same results if $searchQuery contains accent or not.
      For example,
      with « bâtiment » I have no result with « batiment » I have onea result : « Les bâtiments et les smart-city » Normally I should have the same results? How can I do that ?
      Thanks for your help
    • By michelangelo
      Hello guys, I am building a sort of an archive. Relatively simple, although I have about 8000 records, each with 15 fields (text, int, images, url). I created a crude search system with a form (emulating the famous Skyscrapper example) to filter through the system. Everything works but it is quite slow... I have 2 questions which are related:

      1. How can I search through the database?
      2. What is a good practice to display many records like these?
      -----------------------------------------
      1. I am retrieving the results with
      $songs = $pages->findMany('template=nk-song'); Then I do a foreach to render them all. I am unsure if that is a good way. If I render all of them on the page, it creates thousands of divs with a bit of text, and this can take a while (10s-15s).
       
      2. This one is even worse :D as every time I retrieve my desired records with something like this:
      $page->find("field_to_search_through~=my_query_string") I get between 20 and 200, but when I render them I am creating iframes with YouTube videos and that can take up to 10s to finish. I "solved" it by only loading the iframes if they are in view with IntersectionObserver on the client-side. But I feel there is a more precise PHP / ProcessWire approach.
       
      Just to clarify, I started doing all of this custom rendering and querying because tools like ElasticSearch or SearchEngine were a bit complicated and I needed a simple to retrieve information and then display it in my own way.
      Thank you!
    • By snobjorn
      I have a website with multiple content types that I want to be accessible through search. I really like the live search on processwire.com, that sorts content types while typing. I tried to find the code to recreate this, with no luck. Does anyone know if this is jquery, specific jquery plugins, json/xml cached files, and what kind of PHP code is used? Any tip that point me in the right direction would be much apperciated.
      The search result listing seems fairly easy to create with sorting through parameters.
    • By Anders
      I want to allow full text search on my site. There is a very nice solution that comes right out of the box:
      $selector = "title|body~=$q, limit=50"; This works, but to make it even better I would want to give higher weight to pages where the search term occurs in the title, than if it just occurs in the body. After all, a page with the title "Wine from France" is probably the best match for the search "france wine". How do I accomplish this in ProcessWire?
      I can see three possible paths, but I am not very fond of any of them:
      Do a direct SQL query, circumventing the API, along these lines. But I would prefer to abstract away the database layout if at all possible. Use something like ElasticSearch, but to be honest that would be to complicated to set up and maintain in the long run. Make multiple lookups, first for matches in the title, then for matches in the body, and merge and sort in PHP. My suspicion is that this would get complicated quite quickly. For instance, how do you deal with a page that has two of the three search terms in the title and the third in the body? Is there a magic option four I should look into? Or are any of the above options better than the others? Any input is welcome!
×
×
  • Create New...