I am using Solarium to access Solr from PHP. When I perform a normal select query using Solarium everything works fine.
Problem: When I attempt to do a MoreLikeThis query, I get the following error when trying to execute the query. What went wrong, and how can it be fixed?
Solr HTTP error: Not Found (404)
Location:
/home/mysite/public_html/application/libraries/Solarium/Result.php on line 98
PHP Code
$client = new Solarium_Client($config);
$query = $client->createMoreLikeThis()
->setQuery('id:' . $product_id)
->setMltFields('title, description')
->setMinimumDocumentFrequency(1)
->setMinimumTermFrequency(1)
->setInterestingTerms('details')
->setMatchInclude(false)
->setRows(10);
$resultset = $client->select($query);
I probed into the Solarium_Client_Response_Object at /solarium/Client.php and found the response received to be
Solarium_Client_Response Object
(
[_headers:protected] => Array
(
[0] => HTTP/1.1 404 Not Found
[1] => Server: Apache-Coyote/1.1
[2] => Content-Type: text/html;charset=utf-8
[3] => Content-Length: 979
[4] => Date: Mon, 27 Aug 2012 12:03:42 GMT
[5] => Connection: close
)
[_body:protected] =>
[_statusCode:protected] => 404
[_statusMessage:protected] => Not Found
)
You need to have the morelikethis handler configured in Solr. You probably have a select handler, so the standard select works. But for the morelikethis querytype you need to have another handler configured.
For more info see: http://wiki.apache.org/solr/MoreLikeThisHandler
Related
I am making a links-checker tool to avoid broken links in our site content and it works when the page doesn't exist or can't be loaded - except when the external site replaces it with a screen saying something like 'This page doesn't seem to exist. Search for the content you are looking for from our menu...'.
Apart from the html/css/js code for this tool, here is the main PHP code that checks the links
$headers = get_headers($url);
$headers = (is_array($headers)) ? implode( "\n ", $headers) : $headers;
$exists = (bool)preg_match('#^HTTP/.*\s+[(200|301|302)]+\s#i', $headers);
$status = (is_array($headers)) ? $headers[0] : $headers;
Then js use this information including $status but it's not returning error code when the external site shows a 'not found' screen (e.g. http://www.drdansiegel.com/resources/healthy_mind_platter).
You get back redirects before resolving to the 404. I would invert your logic, check to see if you have a 404 or 400 ever present.
$notexists = (bool)preg_match('#^HTTP/.*\s40[04]\s#mi', $headers);
Also, you should use the m modifier so the leading anchor matches each line, not the whole string.
Additionally, note a character class is a list of characters, you can't do groupings in it as you have. [(200|301|302)] says a (, 2, 0, 0 (again), |, 3, 0 (again), etc. are all allowed. You would write that as (200|301|302) if you wanted 200, 301, or 302 to be allowed characters. You could use a character class for the last integer on the redirect status code (and should add 7 and 8 to that as though are valid redirects as well). So it could be (200|30[1278]).
Here's what your $headers contained from example link:
Array
(
[0] => HTTP/1.1 301 Moved Permanently
[1] => Server: nginx
[2] => Date: Sat, 15 May 2021 01:57:44 GMT
[3] => Content-Type: text/html
[4] => Content-Length: 162
[5] => Connection: close
[6] => Location: https://www.drdansiegel.com/resources/healthy_mind_platter
[7] => HTTP/1.1 301 Moved Permanently
[8] => Server: nginx
[9] => Date: Sat, 15 May 2021 01:57:45 GMT
[10] => Content-Type: text/html; charset=UTF-8
[11] => Content-Length: 0
[12] => Connection: close
[13] => Expires: Sat, 15 May 2021 02:57:45 GMT
[14] => Cache-Control: max-age=3600
[15] => X-Redirect-By: WordPress
[16] => Location: https://drdansiegel.com/resources/healthy_mind_platter
[17] => HTTP/1.1 404 Not Found
[18] => Server: nginx
[19] => Date: Sat, 15 May 2021 01:57:46 GMT
[20] => Content-Type: text/html; charset=UTF-8
[21] => Connection: close
[22] => Vary: Accept-Encoding
[23] => Expires: Wed, 11 Jan 1984 05:00:00 GMT
[24] => Cache-Control: no-cache, must-revalidate, max-age=0
[25] => Link: <https://drdansiegel.com/wp-json/>; rel="https://api.w.org/"
)
Hopefully someone can help.. I'm using jQuery dropzone.js to upload the video and I can upload videos fine, but I can't "complete" the process so the videos always remain in a processing/uploading state. I'm performing the correct procedures according to the Vimeo API docs. Here are some headers/responses if they help, I've replaced some values with xxxx:
Upload request headers:
PUT /upload?ticket_id=xxxx&video_file_id=514311645&signature=acd2a6c4ba8c147651604793b081e053&v6=1 HTTP/1.1
Host: 1511923755.cloud.vimeo.com
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Firefox/45.0 FirePHP/0.7.4
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Content-Type: video/mp4
Referer: http://local.xxxx.co.uk/vimeo
Content-Length: 29158540
Origin: http://local.xxxx.co.uk
x-insight: activate
Connection: keep-alive
Upload Response headers:
HTTP/1.1 200 OK
Server: Vimeo/1.0
Content-Type: text/plain
Access-Control-Allow-Origin: *
Timing-Allow-Origin: *
Access-Control-Expose-Headers: Range
Access-Control-Allow-Headers: Content-Type, Content-Range, X-Requested-With
X-Requested-With: XMLHttpRequest
Access-Control-Allow-Methods: POST, PUT, GET, OPTIONS
Content-Length: 0
Connection: close
Date: Thu, 14 Apr 2016 08:05:19 GMT
X-Backend-Server: kopiluwak
Upload response:
<pre>Array
(
[body] =>
[status] => 308
[headers] => Array
(
[] =>
[HTTP/1.1 308 Resume Incomplete] =>
[Server] => Vimeo/1.0
[Content-Type] => text/plain
[Access-Control-Allow-Origin] => *
[Timing-Allow-Origin] => *
[Access-Control-Expose-Headers] => Range
[Access-Control-Allow-Headers] => Content-Type, Content-Range, X-Requested-With
[X-Requested-With] => XMLHttpRequest
[Access-Control-Allow-Methods] => POST, PUT, GET, OPTIONS
[Content-Length] => 0
[Connection] => close
[Range] => bytes=0-29158540
[Date] => Thu, 14 Apr 2016 08
[X-Backend-Server] => kopiluwak
)
)
</pre>
CURL DELETE:
<pre>Array
(
[47] => 1
[10036] => DELETE
[10015] =>
[10023] => Array
(
[0] => Accept: application/vnd.vimeo.*+json; version=3.2
[1] => User-Agent: vimeo.php 1.0; (http://developer.vimeo.com/api/docs)
[2] => Authorization: Bearer xxxx
)
)
</pre>
Response from DELETE:
<pre>Array
(
[body] => Array
(
[error] => Invalid state
)
[status] => 500
[headers] => Array
(
[Server] => nginx
[Content-Type] => application/vnd.vimeo.error+json
[Cache-Control] => no-cache, max-age=315360000
[Strict-Transport-Security] => max-age=15120000; includeSubDomains; preload
[Expires] => Sun, 12 Apr 2026 08
[Accept-Ranges] => bytes
[Via] => 1.1 varnish
[Fastly-Debug-Digest] => 771e16bfeec90f734db73b1b0ee67af1dae1f86d0e6c56d4585eb9958a1684b7
[Content-Length] => 25
[Date] => Thu, 14 Apr 2016 08
[Connection] => keep-alive
[X-Served-By] => cache-iad2138-IAD, cache-lcy1126-LCY
[X-Cache] => MISS, MISS
[X-Cache-Hits] => 0, 0
[X-Timer] => S1460621123.195320,VS0,VE593
[Vary] => Accept,Vimeo-Client-Id,Accept-Encoding
)
)
</pre>
I just replied to the same issue over on the Vimeo forum, and another SO thread I read - I had the same issue and am simply posting it here as there didn't seem to be a solution on this particular thread.
Also, regarding your post - there's not a lot of information provided in your post. Your delete request is not all that's required - the assumption would be that you created a valid ticket request, uploaded properly, THEN tried the del request you posted.
Your response is similar to mine below - if your upload script tried to get a ticket AFTER you already got one on your backend, this issue would popup as it did in my code.
Vimeo post:
https://vimeo.com/forums/api/topic:278394
My solution:
I solved my version of the issue - I think Vimeo corrected some stuff on their API recently because my code did not have a bug and then suddenly one appeared recently. I would bet they added rate limiting on their API gateway or potentially overwriting existing requests to clean up old requests...
Anyhow, here is my fix:
In order to complete a video upload via "Resumable HTTP PUT uploads" (developer.vimeo.com/api/upload/videos), there are 5 steps.
I do everything but the upload through my PHP backend. I was requesting a ticket through PHP as to not expose some secret info through my modified JS frontend (github.com/websemantics/vimeo-upload) but I had not edited out the ticket request properly through the JS code, so the current bug was probably being triggered on that second invalid request (i.e. overwriting or rate limiting my initial valid request through PHP). Once I bypassed the JS "upload" function properly and jumped right to JS "sendFile_", the upload works properly again.
Hope that helps somebody out there!
From cURL I´m getting back an response array where I´d like to test the body against a regex pattern. Here is a sample array:
Array ( [body] => 9068205463|admin [headers] => Array ( [0] => HTTP/1.1 200 OK [1] => Date: Mon, 04 May 2015 16:45:56 GMT [2] => Server: Apache [3] => Vary: Accept-Encoding [4] => Content-Encoding: gzip [5] => Content-Length: 38 [6] => Connection: close [7] => Content-Type: text/html ) [engine] => cURL [cached] => )
Here is what my php if statement looks like:
if (!preg_match("/^[0-9]{10}\|[a-zA-Z]+$/", $result['body'])) {
die ("preg_match failed");
}
Question: Why is Die() fired?
Testing pattern here works like expected.
http://www.phpliveregex.com/p/b2W
Strange as this is working on my localhost but not on a production server.
Php Version is: PHP 5.3.10-1ubuntu3.18 with Suhosin-Patch
You probably have some spaces in your value and that's the reason why it doesn't matches the pattern.
To fix this simply use trim() in preg_match(), e.g.
if (!preg_match("/^[0-9]{10}\|[a-zA-Z]+$/", trim($result['body']))) {
//^^^^^
die ("preg_match failed");
}
I have a question would like to ask you, it was about php. My problem when I tried to use php function to extend image extension from an url which has form below :
http://lh3.googleusercontent.com/i_qpu5lXHddZgNaEbzEEz1CaArLCHEmVNuhwVOuDUl0aIyZHuez3s4Uf878y1n9CqB5rld2a7GSAoWzoMgrC
so , for above url is made by Google which is not show use the file name and extesion name. of course I have try to use this below function but still not work :
$image_name = basename($url);
could anyone help me.
If you are downloading the image, you can get the extension using finfo_file().
Else you can look for the content type in the headers sent by the server using get_headers()
example code
<?php
$url = 'http://lh3.googleusercontent.com/i_qpu5lXHddZgNaEbzEEz1CaArLCHEmVNuhwVOuDUl0aIyZHuez3s4Uf878y1n9CqB5rld2a7GSAoWzoMgrC';
print_r(get_headers($url));
?>
sample output
Array
(
[0] => HTTP/1.1 200 OK
[1] => Access-Control-Allow-Origin: *
[2] => ETag: "v1"
[3] => Expires: Wed, 22 Apr 2015 09:10:30 GMT
[4] => Cache-Control: public, max-age=86400, no-transform
[5] => Content-Disposition: inline;filename="unnamed.png"
[6] => Content-Type: image/png
[7] => Date: Tue, 21 Apr 2015 09:10:30 GMT
[8] => Server: fife
[9] => Content-Length: 20365
[10] => X-XSS-Protection: 1; mode=block
[11] => Alternate-Protocol: 80:quic,p=1
)
I am learning PHP and I'm trying to understand the array below,
I need to grab content-type, it should give me
text/xml;charset=UTF-8 and then
grab the encoding which is UTF-8
Anyone good with arrays could you please help?
array(
[0] => HTTP/1.1 200 OK
[1] => Date: Sat, 30 Aug 2014 17:10:12 GMT
[2] => Server: Apache
[3] => X-Gas_TTL: 900
[4] => Cache-Control: max-age=900
[5] => X-GasHost: gas1.usw
[6] => X-Cooking-With: Gasoline-Local
[7] => X-Gasoline-Age: 844
[8] => Last-Modified: Sat, 30 Aug 2014 16:56:08 GMT
[9] => Content-Type: text/xml;charset=UTF-8
[10] => Vary: Accept-Encoding
)
Thank you in advance
Regards,
Mona
.*?Content-Type:\s*(.*?=(.*?))\n.*
With s flag on this will give what's required.
See demo.
http://regex101.com/r/bJ6rZ5/1
The array must be in a variable ( I assume, since you seem to have printed it ), so you simply print/echo the value you're after.
echo $someArrayVariable[9];
Where someArrayVariable is a variable that contains the array.
That is assuming it is in a variable in the first place.