solarium
Just trying out Solr in combination with Solarium for a search form on a website.
I would like to search for a combination of words like "word1 word2 word3" in all columns, and get results sorted by the highest search score.
I successfully imported all the data in the solr database and the simple select example from solarium outputs the following:
NumFound: 21421
With a few detailed results.
As soon as i start to add the search words to the search i get 0 results. When i specify the search column like "body:word1" the search does work and returns results. am i doing something wrong in de search code or do i have my configuration wrong ?
Search code:
// create a client instance
$client = new Solarium_Client($config);
// get a select query instance
$query = $client->createSelect();
$query->setFields(array('id','title','description','body'));
#$query->setQuery("searchTerm"); //this does not work
#$query->setQuery("body:searchTerm"); //this does work
// this executes the query and returns the result
$resultset = $client->select($query);
// display the total number of documents found by solr
echo 'NumFound: '.$resultset->getNumFound();
schema.xml
<?xml version="1.0" encoding="UTF-8" ?>
<schema name="example" version="1.5">
<field name="_version_" type="long" indexed="true" stored="true"/>
<field name="_root_" type="string" indexed="true" stored="false"/>
<field name="id" type="string" indexed="true" stored="true" required="true" multiValued="false" />
<field name="title" type="text_general" indexed="true" stored="true" multiValued="true"/>
<field name="description" type="text_general" indexed="true" stored="true"/>
<field name="body" type="text_general" indexed="true" stored="true"/>
<field name="content" type="text_general" indexed="false" stored="true" multiValued="true"/>
<field name="text" type="text_general" indexed="true" stored="false" multiValued="true"/>
<uniqueKey>id</uniqueKey>
<fieldType name="string" class="solr.StrField" sortMissingLast="true" />
<!-- boolean type: "true" or "false" -->
<fieldType name="boolean" class="solr.BoolField" sortMissingLast="true"/>
<fieldType name="int" class="solr.TrieIntField" precisionStep="0" positionIncrementGap="0"/>
<fieldType name="float" class="solr.TrieFloatField" precisionStep="0" positionIncrementGap="0"/>
<fieldType name="long" class="solr.TrieLongField" precisionStep="0" positionIncrementGap="0"/>
<fieldType name="double" class="solr.TrieDoubleField" precisionStep="0" positionIncrementGap="0"/>
<fieldType name="tint" class="solr.TrieIntField" precisionStep="8" positionIncrementGap="0"/>
<fieldType name="tfloat" class="solr.TrieFloatField" precisionStep="8" positionIncrementGap="0"/>
<fieldType name="tlong" class="solr.TrieLongField" precisionStep="8" positionIncrementGap="0"/>
<fieldType name="tdouble" class="solr.TrieDoubleField" precisionStep="8" positionIncrementGap="0"/>
<fieldType name="text_general" class="solr.TextField" positionIncrementGap="100">
<analyzer type="index">
<tokenizer class="solr.StandardTokenizerFactory"/>
<filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" />
<filter class="solr.LowerCaseFilterFactory"/>
</analyzer>
<analyzer type="query">
<tokenizer class="solr.StandardTokenizerFactory"/>
<filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" />
<filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
<filter class="solr.LowerCaseFilterFactory"/>
</analyzer>
</fieldType>
<!-- lowercases the entire field value, keeping it as a single token. -->
<fieldType name="lowercase" class="solr.TextField" positionIncrementGap="100">
<analyzer>
<tokenizer class="solr.KeywordTokenizerFactory"/>
<filter class="solr.LowerCaseFilterFactory" />
</analyzer>
</fieldType>
</schema>
Source: (StackOverflow)
I want to use yii2-solr extension in one of my projects. How can I configure this extension. Nothing is mentioned on the extension page. Has anyone used this extension? Any help would be appreciable. Thank you.
I found the extension on github repo . In readme file it is mention to configure it as follows:
'solr' => [
'class' => 'sammaye\solr\Client',
'options' => [
'endpoint' => [
'solr1' => [
'host' => '10.208.225.66',
'port' => '8983',
'path' => '/solr'
]
]
]
],
But after doing all this I am getting the following error:
Class 'Solarium\Client' not found
In one of its Client.php file the line is:
use Solarium\Client as SolrClient;
I checked all the files but Solarium namespace is not there.
Source: (StackOverflow)
I'm using Solarium with Solr 4 and I need to delete with multiple criteria. The docs show how to delete with a query
$client = new Solarium\Client($config);
$update = $client->createUpdate();
$update->addDeleteQuery('type:comment');
$update->addCommit();
$result = $client->update($update);
This works fine. But if I need a different criteria, eg writer_id:123, I'm not sure what to do. If I add another addDeleteQuery line the final raw query looks like:
<update>
<delete>
<query>type:comment</query>
</delete>
<delete>
<query>writer_id:123</query>
</delete>
<commit/>
</update>
It seems this will delete them independently. I'm not sure if it matters but the defaultOperator from the schema is AND. Looks like from http://www.solarium-project.org/forums/topic/change-operator/ that it's not easily overridable yet. I'm not sure how to apply the solution there to delete, if that would work even work here.
How can I delete items in solr using multiple criteria?
Source: (StackOverflow)
How am I supposed to use the Solarium Library https://packagist.org/packages/solarium/solarium
With PHP Composer? http://getcomposer.org/
composer require solarium/solarium
- It installed properly then I added to my php file
include_once './vendor/autoload.php';
- Then how do I initialize the Autoloader? Before composer I would perform the following require and all the functions would then be available.
require_once(dirname(__FILE__) . '/../Solarium/Autoloader.php');
- I tried the following but it gives me
Fatal error: Cannot redeclare class Solarium\Autoloader on Solarium\Autoloader.php on line 53
new Solarium\Autoloader();
Source: (StackOverflow)
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
)
Source: (StackOverflow)
I am using https://github.com/nelmio/NelmioSolariumBundle and I am trying to conect with solarium y my symfony2 application.
I have installed solarium with the composer.json but then I get
Class 'Solarium_Plugin_Abstract' not found in .../vendor/bundles/Nelmio/SolariumBundle/Logger.php on line 12
I don't understand why in the Logger there is:
use Solarium_Plugin_Abstract
But in the folders I find:
myproject/vendor/solarium/library/Solarium/Plugin/Abstract.php
I have declared in my autoload.php
'Solarium' => DIR.'/../vendor/solarium/library',
Should't be: use Solarium/Pluguin/Abstract ?
What I am doing wrong?
Source: (StackOverflow)
I'm trying to get Solarium running on Centos 6.5 with an rpm install of PHP (5.3.3) and Apache HTTPD.
I have followed the instructions on the website, creating a folder /var/www/php (which is in the include path in php.ini) and downloading composer. Then I've entered the following into composer.json:
{
"require": {
"solarium/solarium": "3.*"
}
}
and run "php composer.phar install".
I am now trying to run the examples in the Solarium examples folder (specifically the 1.1 Solr Ping example). To do this I have amended init.php to include the line:
require('vendor/autoload.php');
I have confirmed that vendor/autoload.php is being run by adding a print statement to it.
However, when I run the example I get:
Fatal error: Class 'Solarium_Version' not found in /var/www/html/test/1.1-check-solarium-and-ping.php on line 7
or if I comment out line 7:
Fatal error: Class 'Solarium_Client' not found in /var/www/html/test/1.1-check-solarium-and-ping.php on line 10
So it seems that the Solarium files are not being loaded as intended.
Not sure if this is a Solarium or Composer problem (I suspect the latter). Can any one suggest a way to debug this?
Issuing the command "php composer.phar dump-autoload" only generates the message:
Generating autoload files
Is that correct (I assume not based on the description of the command)?
Running:
php composer.phar diagnose
Gives:
Checking composer.json: FAIL
name : is missing and it is required
description : is missing and it is required
No license specified, it is recommended to do so. For closed-source software you may use "proprietary" as license.
Checking platform settings: FAIL
Your PHP (5.3.3) is quite old, upgrading to PHP 5.3.4 or higher is recommended.
Composer works with 5.3.2+ for most people, but there might be edge case issues.
Checking git settings: OK
Checking http connectivity: OK
Checking disk free space: OK
Checking composer version: FAIL
Your are not running the latest version
None of which look fatal. Is that correct?
Many thanks
Paul
UPDATE:
Some more info. Adding some print statements to vendor/composer/autoload_real.php gives:
($map created by autoload_namespaces.php)
Symfony\Component\EventDispatcher\ -
Array ( [0] => /var/www/php/vendor/symfony/event-dispatcher )
Solarium\ -
Array ( [0] => /var/www/php/vendor/solarium/solarium/library )
($classMap created by autoload_classmap.php)
classMap -
Array ( )
The empty array for classmap seems odd. Is that correct?
Thanks
P
Source: (StackOverflow)
My main problem is, that i dont have access to Solarium (a third party libary) in my symfony2-project and I do not understand why.
I have a symfony2 application and want to write my own Solr connector. Therefore I want to use Solarium. (IMPORTANT: I dont want to use other bundles for this)
First I installed it via composer
"require": {
//...
"solarium/solarium": "3.3.0.x-dev"
}
Then i called:
php composer.phar install
php composer.phar update
Second i created a new directory for my connector in my bundle:
/src/COMPANY/ThatIsMyBundle/SolrSearch/
In this directory is my class SolrConnector.php
namespace COMPANY\ThatIsMyBundle\SolrSearch;
use Solarium\Client;
//use Solarium\Core\Client;
class SolrConnector {
private $solr_client;
function __construct($settings)
{
$solr_config = array(
'endpoint' => array(
'protokolldb' => array(
'host' => $settings['solrHost'],
'port' => $settings['solrPort'],
'path' => $settings['path'],
'core' => $settings['core'],
'timeout' => $settings['timeout']
)
)
);
$this->solr_client = new Client($solr_config);
}
/**
* Check if Solr is on.
*/
function executePing() {
$ping = $this->solr_client->createPing();
try {
$this->solr_client->ping($ping);
echo "Solr is fine.\n";
} catch (Exception $e) {
echo "Solr is unaccessible. Look up whats wrong with Solr and restart this script.\n ".$e->getMessage();
}
}
}
I got this error message from symfony:
Attempted to load class "Client" from namespace "Solarium" in "(my
specific path to the project)/SolrSearch/SolrConnector.php line 32."
Do you need to "use" it from another namespace?
What i have to do to use Solarium in my Symfony2 Bundle?
I think it is a namespace/use/require problem.
I googled it for hours... with no solution.
Things i tried:
adding
require('../vendor/autoload.php);
same error.
Source: (StackOverflow)
I'm implementing a grouped search in Solr. I'm looking for a way of summing one field and sort the results by this sum. With the following data example I hope it will be clearer.
{
[
{
"id" : 1,
"parent_id" : 22,
"valueToBeSummed": 3
},
{
"id" : 2,
"parent_id" : 22,
"valueToBeSummed": 1
},
{
"id" : 3,
"parent_id" : 33,
"valueToBeSummed": 1
},
{
"id" : 4,
"parent_id" : 5,
"valueToBeSummed": 21
}
]
}
If the search is made over this data I'd like to obtain
{
[
{
"numFound": 1,
"summedValue" : 21,
"parent_id" : 5
},
{
"numFound": 2,
"summedValue" : 4,
"parent_id" : 22
},
{
"numFound": 1,
"summedValue" : 1,
"parent_id" : 33
}
]
}
Do you have any advice on this ?
Source: (StackOverflow)
I'm new in Solr search, Can anyone help me to add multiple fields OR condition I got solutions in solr but I can't implement this in solarium.
I have fields
1. name
2. username
3. email
I want to convert this in Solarium filter query like I use single field for this
$query->createFilterQuery('name')->setQuery('name:*' . $keyword . '*');
I want its result like
fq=(name:*abc* OR username:*abc* OR email:*email*)
Please help me to add multiple fields with OR operator for match if any one matches in any of three field then return me result.
Source: (StackOverflow)
I'm just starting Solr and using the ExtractingRequestHandler to index PDF files using the curl command:
curl "http://localhost:8983/solr/update/extract?literal.id=doc1&commit=true" -F "myfile=@file.pdf"
I used Solarium as a Solr client to query and list the results.
But all these steps are still useless as long as the user can't know which file the word he's searching is coming from.
So I just want to show a part of the text where the keyword is located on the file, as well as the link of the file to download it for example.
Any help will be strongly appreciated.
Source: (StackOverflow)
I want to get my value of the field ‘Latitude’
and ‘Longitude’
into a variable in order to pass it as an argument in below function:
// add a filterquery to find products in a range of 25km, using the helper to generate the 'geofilt'
filter
$query->createFilterQuery('city')->setQuery($helper->geofilt(doubleval('latitude'),doubleval('longitude'),'geo',25));
//Sort the results by location
$query->addSort(($helper->geodist('geo','latitude','longitude')), Solarium_Query_Select::SORT_ASC);
This is not giving me any results and passing the pt=0,0
as shown below:
fq={!geofilt+pt%3D0,0+sfield%3Dgeo+d%3D25}
So how can i get the field values of ‘latitude’
and ‘longitude’
in geofilt()
So that i can get results and value with in that 'latitude'
and 'longitude'
?
Source: (StackOverflow)
I want to update parts of a document in Apache Solr 4.0 with PHP Solarium, and not update the whole document. I know its possible in Solr (documentation in Solr), I just cant find any documentation on how to do this in Solarium. all the existing Solarium documentation point me to updating the whole document, which is problematic and unnecessary.
Source: (StackOverflow)
I am using solr in my application and want it to ignore some of trivial search queries like "a", "an", "the" etc. I want it to return nothing if it encounters such querie strings. Is there anything like dictionary or knowledge base that I can confiure with the words that I feel trivial. Or any other suggestion?
Is my question somehow related with solr stop words?
Source: (StackOverflow)
I would to ask if someone knows how to specify a field using 'qs' parameter. I mean, for example, a have a document with this fields and content
- id: 1
- name: Football
- keywords: football, goal, goalkeeper
- phrase_keywords: premier league, champions league, golden awards,
Then i make a search by: 'premier awards' using Dismax with parameter qs: 20. So, parameters will be like:
defType:q=foo&defType=dismax&q:"premier awards"&qs:20
Results will be "name" content, right, but i just apply qs:20 to field phrase keywords, because if a search: 'goal league' is doenst match any result, although if i break the search in: "goal premier" OR goal OR premier.
Because i would like to search like this:
phrase_keywords:"goal premier" or keywords:goal OR keywords:premier
but in phrase_keywords with "qs" (proximity) and for keyword a normal search.
Source: (StackOverflow)