I am building an application which requires search.
I am using sphinx 2.0x and it has been giving me results.
Now, I want to filter through as we do using where in MySQL example, select * from properties wheretype= 'house' I am trying to add a filter on Sphinx search.
I am using https://github.com/CakeNKeyboard/Sphinx-CakePHP and the API that I have, (just checked) requires filter's second argument to be an array and assert requires to know if that is a number. I do not like to touch the api file nor behaviour file.
Checked this : Sphinx 2.0.2 Filtering sql_attr_string Attributes made sense!
But where do I add WHERE MATCH ??? I am using behaviour for this and api file asserts if value is number but I want to check on string.
Please help.
MATCH(..) is the 'full-text' query itself.
So in the API, its the ->Query call.
SphinxQL also makes extended match mode as the default, so to use the # syntax in the API, you also need to explicitly request SPH_MATCH_EXTENDED
Related
I use last version of API Platform, and I was wondering if I could change the way to handle arrays in query string.
Default behavior relies on PHP way to handle arrays :
/customers?cars[]=audi&cars[]=mercedes&cars[]=bmw
According to Swagger documentation : https://swagger.io/docs/specification/serialization/, it can handle different ways :
/users?id=3,4,5
/users?id=3|4|5
Can I use this format using API Platform? I didn't find anything in the options, I suppose I can "trick" using Events (DeserializeListener maybe).
This input format seems supported by Swagger: the style name of the parameter is deepObject.
There are many ways to support multiple inputs in query because the query is in fact a simple string containing var=value, therefore you can imagine whatever you want since var may be duplicated. PHP use the array-style (or deepObject) approach by default, and this is fine.
API Platform as support for this kind of "multiple filter" query by default: https://api-platform.com/docs/core/filters/#search-filter
If you want to use the following approach: /users?id=3|4|5, you can define a custom filter with ease and use the request directly to explode the id parameter and complete your query internally.
I am using Bitnami Apache Solr 7.4.0(Latest)
I indexd documents
Now in admin Panel for query search i need to write field:value format
But I just want to search with only value
Example:
q=field:value (It works)
q=value (It give 0 result)
So what should i configure in schema.xml file that i can search through only by Value of the field
In Solr Admin --> Query page, you can add the field name to df to which you want to route your queries. df means default search field.In order to use you dont need to use dismax or edismax parsers. df will work with Standard Query parser itself. So, I hope this is what you are looking for. Thanks.
You don't need to modify the schema. You can create your own request handler which can perform query operations based on your requirements by creating a new requestHandler in the solrconfig.xml file. For more details on how to do this see here.
That being said, I would suggest you first go through the basics of querying in solr and understand how the different parameters like q, qf, defType etc. work and what different query parsers (standard, dismax etc.) are available for use. See this.
There is nothing special to configure, but you have to use the edismax or dismax query parsers. These query parses are made to support free form user input, and you can use it with just q=value. You tell Solr to use the edismax query parser by providing defType=edismax in the query URL.
Since the field to search no longer is part of the actual query, you tell the edismax handler which field to search by giving the qf parameter. You can give multiple fields in qf, and you can give each field different weights by using the syntax field^<weight>.
So to get the same result as in your first example:
?q=value&defType=edismax&qf=field
I'm using the example application from github.com/searchly/searchly-php-sample with Searchly service.
I've came a simple where I want the search results to return all the aggregations(continued as 'aggs') from the search results, not only the ones I specified.
Currently the code for the aggs is:
$searchParams['body']['aggs']['resolution']['terms']['field'] = 'resolution';
this returns the resolution agg but I can not find the way for it to return all of the possible aggs from the search results.
Is it possible or does it require me to save the aggs some where and then just list them when I do the actual search request?
Thank you!
As far as I know there is no way to do this directly - you have to specify each field you are interested in.
However if you can build up a list of all the fields in the index then you could generate the required aggregations fairly easily.
So, how to build up that list? I can think of three ways that might work
A) build it up by doing some pre-processing before you index each document into ElasticSearch
B) Use the GET MAPPING api to see what fields have been created by dynamic mapping (http://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-mapping.html)
C) Use a Scripted Metric Aggregation and write scripts that build up a de-duped list of fields in the documents (http://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-scripted-metric-aggregation.html)
In Elastic Search I need to obtain a list of available Aggregations (formally Facets?) for the current result-set.
For example, if I do a search for "car" in a set of cars which have defined MAKE and MODEL fields, I would like it to not only give me a result set of cars, but also a list of makes and models I can filter by.
From what I can read, you have to request the aggregations you want. That can't be right because if I was eBay and I had a catalogue with hundreds of possible attributes, all of which are searchable, then telling the search engine what facets I would like to search by would be unscalable.
I'm Using:
Elastic Search
PHP Elastica Client
I would expect to simply be able to call Elastica/ResultSet.php::getAggregations() on Line 194 here:
https://github.com/ruflin/Elastica/blob/master/lib/Elastica/ResultSet.php#L194
Point of reference:
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations.html
Could someone please clarify what I need to do to achieve this?
In Elasticsearch, you have to explicitly mention which fields you want to aggregate upon. Why don't you implement a client side (client of Elasticsearch) logic of getting all the field names and build an Elasticsearch search request with aggregations for all those fields?
In solr PECL php package,to the solrQuery class we can add parameters using solrparam::set methods as name value pair.So Inorder to build a query we can use this SolrParams class.
I am just trying to figure out what are the use cases of all the methods in solrquery object.
like
***"SolrQuery::addFacetDateField — Maps to facet.date
SolrQuery::addFacetDateOther — Adds another facet.date.other parameter
SolrQuery::addFacetField — Adds another field to the facet
SolrQuery::addFacetQuery — Adds a facet query
SolrQuery::addField — Specifies which fields to return in the result
SolrQuery::addFilterQuery — Specifies a filter query
SolrQuery::addHighlightField — Maps to hl.fl"***
....etc.
We can simply use the solrparam to add parameters to the query, then what is the use of these.
Thanks
These methods were added to ease the use of Solr Functions, Unfortunately the current documentation misses a lot of use cases, that I'm currently working on.
It's much easier and more consistent to use methods for query functionalities like date facet without going into the Solr Documentation each time to pull parameter names. It's also less error prone.
For the time being, if you wish to learn more about these functionalities, you can check the Solr Wiki http://wiki.apache.org/solr/SimpleFacetParameters#facet.date.other
The SolrParams is the ancestor of SolrQuery, SolrQuery has much more features than the bare bones(SolrParams). In the documentation its passed for SolrClient::query() as the query method accepts argument of type SolrParams (which means SolrParams any of its descendents).
There is nothing special about those methods. You can use the API in both ways without any penalty. Using SolrQuery methods makes your code more explicit so it's better for readability I presume.