I am having a hard time trying to use MatchAll in elastic search using elastica, currently I have the following querystring:
$pictureQuery = new \Elastica\Query\QueryString();
$pictureQuery->setParam('query', $searchquery);
$pictureQuery->setParam('fields', array(
'caption'
));
$items = $itemFinder->find($pictureQuery);
the issue with this query is that it only returns 10 results. I wanted to return all results, in this case MatchAll. I am however having issues on how to get all matching results, how do I do so?
Elasticsearch returns by default the top 10 results (the more relevant).
That's the expected behavior.
Elasticsearch allows to change page size (size) and change page (from). Have a look at From/Size API.
In Elastica, I guess it's here: http://elastica.io/api/classes/Elastica.Query.html#method_setSize
Related
I am try to getting started with Sphinx. I add some results to index, download sphinxapi.php, and when I do this:
$cl = new SphinxClient();
$cl->SetServer( "localhost", 9312 );
// SPH_MATCH_ALL will match all words in the search term
$cl->SetMatchMode(SPH_MATCH_ALL);
$result = $cl->Query("test");
I getting this (row with id = 5 where title = test):
array (size=1)
5 => // id of post in database
array (size=2)
'weight' => string '2' (length=1)
'attrs' =>
array (size=0)
empty
But why I didnt get row from database with id = 6, where title field equal to test1 ?
And $cl->SetMatchMode(SPH_MATCH_ALL); fire error:
DEPRECATED: Do not call this method or, even better, use SphinxQL instead of an API
I comment this line in code of api file:
trigger_error ( 'DEPRECATED: Do not call this method or, even better, use SphinxQL instead of an API', E_USER_DEPRECATED );
But I dont know if it fine. Can somebody help me to understand what I am doing wrong? Thanks!
To get 'substring' matches, you need to specifically enable them.
http://sphinxsearch.com/docs/current.html#conf-min-prefix-len
(or min_infix_len)
If you dont want to see the depreciated notice, then set error_reporting
http://php.net/manual/en/function.error-reporting.php
(but even better is to rewrite the code to avoid calling the depreciated method)
warning setmatchmode
SetMatchMode are deprecated, you can still use it but it can be removed in next versions.
More info about it in:
http://sphinxsearch.com/docs/current.html#api-func-setmatchmode
http://sphinxsearch.com/blog/2013/09/11/deprecations-and-changes-in-the-2-2-series/
extracted from sphinx forum (barryhunter):
Changing the 'match mode' actually did TWO things, it changed the matching >behaviour - by
rewriting the query itself. AND changing the ranking mode.
By decoupling these concepts, I guess the idea is reduce confusion.
(for example, as soon as you choose a different matching mode, you can't >actully choose a
ranking mode)
... the match modes made sence before the 'extended syntax' was fully developed, but now
everything can be done directly via the extended syntax.
about search results
barryhunter answer is right
I suggest to read more about charset tables, morphology and stemming because i think are a better way to achieve success search than wilcard searches.
http://sphinxsearch.com/docs/current.html#conf-charset-table
http://sphinxsearch.com/docs/current.html#conf-morphology
I use this script to get the collection of my mongo database: http://datatables.net/development/server-side/php_mongodb
My question is: how to retrieve the rows where foo == 'mystring' only?
As you will notice (on line 29) from the source code in the file the mongo collection has been given the name: $m_collection as such:
$m_collection->find(array('foo' => 'mystring'))
Should work.
If this is not what you are looking for maybe you can be more specific and explain exactly what you are trying to do.
UPDATE
It has come to my attention you might want to instead edit the $searchTermsAll variable to search by this field in a doc. By the looks of it this PHP class links in the same as it would normally for SQL as such you should need to do anyhting special and can just enable filtering on datatables and add the value mystring to the foo field.
However to know if it is the right answer you will need to clarify.
UPDATE 2
A more destructive way of doing this that should keep filtering is to replace line 99 with:
$cursor = $m_collection->find(array_merge($searchTerms,
array('foo' => 'mystring')), $fields);
That will always make sure that your condition is added to the search terms but keeps the users own search terms.
Use as below
$cursor = $collection->find(array("foo" => "mystring"));
Here is more details: http://www.php.net/manual/en/mongo.queries.php
I have a problem with UpdateAttributes, it seem to not work for me.
When I issue:
$ret = $sphinx->UpdateAttributes ( "products", array ("status"), array(506607786 => array(10)) );
it returns 1, but search still returns status as old value for this.
When I try
$ret = $sphinx->UpdateAttributes ( "products", array ("status", "image_id"), array(506607786 => array(10, 6666)) );
it returns 0 (false)
Does this function even work ?
Ok I have found (sphinx docs are ugly) that when issuing updateAtrributes() from PHP app then I will not see the results in search command line. However one problem still
exist - I'm not able to update 2 attributes in one updateAtrributes() - seperatly they are fine - any clues why ?
When UpdateAttributes returns 0 (not false) it does not mean it didn't work, what it means is it didn't find anything to update, basically no updates commited. A return of -1 actually means this function did not work.
Make sure that 506607786 is actually an id in your Sphinx index and that products is the name of your index.
To make the question more helpful you can provide an example row from your table, preferrably the one used in this function defined as 506607786. You cna also provide a full set of your code to make it easier.
As a side note: UpdateAttributes does not act like a realtime index. You will need to filter on these attributes specifically in your query in order for sphinx to take their new values into consideration.
I'm using the latest php mongo driver along with the latest mongodb 2.0. I'm trying to run a base query of host=x return the results then refine the search with other terms.
It's not returning any valid results.
I was thinking something like this, but its obviously not working:
$basefilter = array('host' => new MongoRegex("/1.1.1.1|2.2.2.2/i"));
$filter = array('host' => new MongoRegex("/2.2.2.2/i"));
$basereturn = $collection->find($basefilter);
$initreturn = $basereturn->find($filter);
$return = $initreturn->sort(array('date' => -1))->limit($limit)->skip($skip);
I want to just be able to refine my search. How can this be done?
You can't run a find over a cursor. find only works over collections. I suspect the above fatals out. You can map/reduce into a collection and run find on it.
you probably should scape your regex you have there since the dot is an operator in regex, so that should have been:
$basefilter = array('host' => new MongoRegex("/(1\.1\.1\.1)|(2\.2\.2\.2)/i"));
I am using SOLR PHP client to query data from a solr service. My code looks similar to the below in that I'm passing in a query to search on multiple IDs (in my case, a lot). The problem arises for me when I'm searching for too many IDs at once. I get a 'Request Entity Too Large' when passing in too many IDs. Is there a way to get around this? From what I see in various examples, the syntax seems to be 'id:1 OR id:2 OR id:3 etc.' when searching on multiple values. This there a different syntax that would reduce the size of the request being passed into the service? e.g. In SQL we can say, 'id in (1,2,3,etc.)'. Can we do something similar for the SOLR query?
<?php
require_once( 'SolrPHPClient/Apache/Solr/Service.php' );
$solr = new Apache_Solr_Service( 'localhost', '8983', '/solr' );
$offset = 0;
$limit = 10;
$queries = array(
'id: 1 OR id: 2 OR id:3 OR id:4 OR id:5 OR id:6 or id:7 or id:8' // in my case, this list keeps growing and growing
);
foreach ( $queries as $query ) {
$response = $solr->search( $query, $offset, $limit );
if ( $response->getHttpStatus() == 200 ) {
print_r( $response->getRawResponse() );
}
else {
echo $response->getHttpStatusMessage();
}
}
?>
Solr supports searching through POST HTTP requests instead of GET requests which will allow you to have a much bigger query. I don't know how to enable this in the PHP client you're using.
However this is only a bandaid. The real problem is that you seem to be misusing Solr. You will likely run into other limits and performance issues, simply because Solr wasn't designed to do what you're trying to do. You wouldn't use PHP to write an operating system, right? It's the same with this.
I recommend creating a new question with the real issue you have that led you to run this kind of queries.
Solr supports range queries, i.e. id:[1 TO 10], or id:[* TO *] to match all. Since it looks like many of your "ORs" are with respect to sequential IDs, this should help.