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
Related
I'm building an interactive search service for a client, and part of what we need is the ability to add "tags" to documents. These tags will be both pre-existing and custom-defined. The schema has been setup to support this, but I'm having issues with Solarium PHP on updating a resultset.
For example, if the user searches for "Overflow" in our database, and that returns 1-1000+ results, they need to ability to tag this entire resultset with any number of tags.
So I'm taking the resultset from execute() and am currently unable to alter the documents returned -- the exception being "A readonly document cannot be altered".
Any one have a workaround for this?
For an updateable document you should use this class: Solarium\QueryType\Update\Query\Document
Solarium uses this document type as default for select queries for two
reasons:
in most cases no update functionality is needed, so it will only be
overhead to discourage the use of Solr as a DB, as in reading -
altering - saving. Almost all schemas have index-only fields. There is
no way to read the value of there fields, so this data will be lost
when re-saving the document! Updates should normally be done based on
your origin data (i.e. the database). If you are really sure you want
to update Solr data, you can set a read-write document class as the
document type for your select query, alter the documents and use them
in an update query.
http://solarium.readthedocs.org/en/stable/documents/
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)
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
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.
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!