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.
Related
I have a table with a JSON column, it's type longtext (DC2Type:json). This table has an Entity in Doctrine ORM in my Symfony project. I would like to query based on fields inside the JSON column, using the Doctrine query builder I have in a variable $qb
How do I do this? Everything I found online says to install a 3rd-party package to enable this. Is there no way to just do it with Doctrine's query builder without installing another package?
One (maybe dumb) workaround I tried was to treat the column as a string, and do...
$qb->andWhere("my_data LIKE \"%id:\\\"1,%\"");
For example, if I wanted to query the JSON column my_data to find the blobs that contain id":1, in the string. This fails with a very strange syntax error, and isn't the right way to query a JSON field anyway. HOWEVER, doing the LIKE query directly in SQL client works the way I want, so I also don't know why this is failing in Doctrine.
EDIT: This is MySQL / MariaDB.
Doctrine Query Language is pretty limited. It covers only the most basic/common SQL functions, which is enough for like 99% use cases, but not all.
If you have a MariaDB version that natively supports JSON (so 10.2 or later) you can use native functions to work with the JSON data. (If you don't then your workaround is the only option regardless, with perhaps some additional filtering in the application).
To be able to use these functions in DQL you either need to define them yourself or indeed use a third party library like scienta/doctrine-json-functions (note that it has documentation for how to use it with Symfony, and it's really simple).
If you need just a single extra function and for some reason don't want the whole bundle, you could just copy that single class and use it as your own.
Alternatively you can forgo DQL and write SQL directly, but that way you can't hydrate into objects directly and use other Doctrine magic with the data. But it can be enough for simple use cases.
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 was wondering if there is a way to perform a find() and have Mongo automatically return the associated references without having to run getDBRef() once the parent record has been returned.
I don't see it anywhere in the PHP documentation. I can easily support using getDBRef but it doesn't seem as efficient as it could be.
Also...I'm surprised there's no way to select the specific data to return in the linked reference. I may as well just perform another manual find statement so I can control what the return is...but there has to be a more performance oriented way to do this.
Perhaps I should change my methodology and instead of using the PHP library classes for find, generate my own JavaScript command and run it using the MongoCode class? Would that work and if so...I'm wondering what it would look like. scratches head then heads to The Google
Thanks!
MongoDB does not support joins. Database References (DBRefs) just refers to the practice of a field storing an _id referencing another document. There is currently no specific server-side support for this, and hydrating the reference to a document does require another query. Some MongoDB drivers have convenience methods so you don't have to manually do the find. It is equally valid/performant if you want to do your own find() given a DBRef to lookup (or use other criteria to find related documents).
Depending on your use case and data modelling, a more efficient alternative to the DBRef linking could be embedding related data as a subdocument. See the MongoDB wiki info on Schema Design for more examples.
As far as performance goes, it would be better to use PHP queries than MongoCode (JavaScript which needs to be eval'ed on the server). MongoCode is really intended for more limited use such as within Map/Reduce functions. Refer to Server-Side Code Execution for some of the potential limitations with that approach.
Refer: http://docs.mongodb.org/manual/reference/database-references/
Manual references where you save the _id field of one document in another document as a reference. Then your application can run a second query to return the related data. These references are simple and sufficient for most use cases.
DBRefs are references from one document to another using the value of the first document’s _id field, collection name, and, optionally, its database name. By including these names, DBRefs allow documents located in multiple collections to be more easily linked with documents from a single collection.
To resolve DBRefs, your application must perform additional queries to return the referenced documents. Many drivers have helper methods that form the query for the DBRef automatically. The drivers do not automatically resolve DBRefs into documents.
So either way, no matter which type of referencing you are using, you need to do the dereferencing yourself.
Hope it helps!
I'm working on a php service.
I'd like to pass an object with the parameters to use in the "where" clause and also the "order" and "limit" params.
I'm wondering whether there is a standard way/library to make up the query based on the parameters given, or whether I'll need to roll one.
I'm using ezsql to connect to mysql.
Any pointers, much appreciated.
Writing one yourself shouldn't be too hard. If you don't want to do so (DRY, right?), you may check out sites like phpclasses.org or use an abstraction layer from Doctrine (take a look at its QueryBuilder if it is what you need)
Another suggestion if you would like to use already existing code: Zend Framework has a "query builder", Zend_Db_Select.
This does not require the whole Zend Framework, but it does have some depedencies you will have to include.
Documentation: http://framework.zend.com/manual/en/zend.db.select.html