Enabling Solr or ElasticSearch in your PHP application isn't that hard these days anymore. There are multiple libraries available which can turn any collection of data into a searchable index making it as accessible as the PHP language itself. But how do you become a pro in creating the right schema, query and data analyzer?
This talk will take the attendee knee deep into the problems we faced in analyzing, faceting, getting the right user experience and of course the relevant results for the second-hand car site AutoTrack where you have to ability to search on more then 200 different attributes of a car! Now you may calculate how many unique different search queries that sums up to…
12. imap://mvdpolder@mail.enrise.com:993/fetch%3EUID%3E/INBOX%3E13466?part=1.2&type=image/jpeg&filename=foto.JPG
DID YOU READ THE SCHEMA.XML?
1 <?xml version="1.0" encoding="UTF-8" ?>
2 <schema name="example" version="1.5">
3 <!--
4 This is the Solr schema file. This file should be named "schema.xml" and
5 should be in the conf directory under the solr home
6 (i.e. ./solr/conf/schema.xml by default)
7 or located where the classloader for the Solr webapp can find it.
8
9 This example schema is the recommended starting point for users.
10 It should be kept correct and concise, usable out-of-the-box.
11
12 For more information, on how to customize this file, please see
13 http://wiki.apache.org/solr/SchemaXml
14 -->
15 <types>
16 <!-- There is 61Kb of example schema -->
17 </types>
18 <fields>
19 <!-- documented in this file! -->
20 </fields>
21 <uniqueKey>id</uniqueKey>
22 <defaultSearchField>text</defaultSearchField>
23 </schema>
22. imap://mvdpolder@mail.enrise.com:993/fetch%3EUID%3E/INBOX%3E13466?part=1.2&type=image/jpeg&filename=foto.JPG
IS IT THAT EASY WITH SOLARIUM?
1 // get a select query instance
2 $client = new SolariumClient($config);
3 $query = $client->createSelect();
4
5 // define the output field
6 $query->setFields(array('auto_id', 'merk_model_uitvoering',
7 'aanbieder_informatie', 'score'));
8 $query->setSorts(array('score' => 'desc'));
9
10 // set the query
11 $query->setQuery('audi +avant +abs');
12
13 $resultset = $client->select($query);
select?q=audi +avant +abs
&fl=auto_id,merk_model_uitvoering,aanbieder_informa
tie,score&sort=score desc
23. imap://mvdpolder@mail.enrise.com:993/fetch%3EUID%3E/INBOX%3E13466?part=1.2&type=image/jpeg&filename=foto.JPG
HOW DO I USE THE DISMAX REQUEST HANDLER?
1 // define the output field
2 $query->setFields(array('auto_id', 'merk_model_uitvoering',
3 'aanbieder_informatie', 'score'));
4 $query->setSorts(array('score' => 'desc'));
5
6 // get the dismax component and set a boost query
7 $dismax = $query->getDisMax();
8 $dismax->setQueryFields('uitvoering^2.3 text^0.9');
9 // set the query
10 $query->setQuery('audi +avant +abs');
11
12 $resultset = $client->select($query);
select?q=audi +avant +abs&
fl=auto_id,merk_model_uitvoering,aanbieder_informat
ie,score&sort=score
desc&defType=dismax&qf=uitvoering^2.3 text^0.9
24. imap://mvdpolder@mail.enrise.com:993/fetch%3EUID%3E/INBOX%3E13466?part=1.2&type=image/jpeg&filename=foto.JPG
WHAT IS A BOOST FUNCTION?
1 // define the output field
2 $query->setFields(array('auto_id', 'merk_model_uitvoering',
2 'score'));
3 $query->setSorts(array('score' => 'asc'));
4
5 // get the dismax component and set a boost function
6 $dismax = $query->getDisMax();
7 $dismax->setBoostFunctions(
8 ‘sqedist(x_coordinaat,y_coordinaat,155000,463000)');
9
10 // set the query
11 $query->setQuery('audi +avant +abs');
select?q=audi +avant +abs
&fl=auto_id,merk_model_uitvoering,score&sort=score
asc&defType=dismax&bf=sqedist(x_coordinaat,y_coordi
naat,155000,463000)
28. imap://mvdpolder@mail.enrise.com:993/fetch%3EUID%3E/INBOX%3E13466?part=1.2&type=image/jpeg&filename=foto.JPG
HOW DO I CREATE A RANGE QUERY?
1 // get the facetset component
2 $facetSet = $query->getFacetSet();
3
4 // create a facet field instance and set options
5 $facet = $facetSet->createFacetRange('topsnelheid');
6 $facet->setField('topsnelheid');
7 $facet->setStart(120);
8 $facet->setGap(10);
9 $facet->setEnd(250);
10
11 // this executes the query and returns the result
12 $resultset = $client->select($query);
select?facet=true&facet.range={!key=topsnelheid}
topsnelheid&f.topsnelheid.facet.range.start=90&f.to
psnelheid.facet.range.end=250&f.topsnelheid.facet.r
ange.gap=10
31. imap://mvdpolder@mail.enrise.com:993/fetch%3EUID%3E/INBOX%3E13466?part=1.2&type=image/jpeg&filename=foto.JPG
WHAT IS A FACET MULTI QUERY?
1 // get the facetset component
2 $facetSet = $query->getFacetSet();
3
4 // create a facet field instance and set options
5 $facet = $facetSet->createFacetMultiQuery(
6 array('key' => 'topsnelheid'));
7 $facet->createQuery(
8 'topsnelheid[*TO140]', 'topsnelheid:[* TO 140]');
9 $facet->createQuery(
10 'topsnelheid[141TO150]', 'topsnelheid:[141 TO 150]');
11
12 // this executes the query and returns the result
13 $resultset = $client->select($query);
select?facet=true&facet.query={!
key=topsnelheid[*TO140]}topsnelheid:[* TO
140]&facet.query={!key=topsnelheid[141TO150]}
topsnelheid:[141 TO 150]
40. imap://mvdpolder@mail.enrise.com:993/fetch%3EUID%3E/INBOX%3E13466?part=1.2&type=image/jpeg&filename=foto.JPG
IS IT EASY TO CREATE A PIVOT FACET?
1 $query->setQuery('+cabriolet +abs');
2
3 // get the facetset component
4 $facetSet = $query->getFacetSet();
5
6 // create a facet pivot instance
7 $facet = $facetSet->createFacetPivot('merk-model');
8 $facet->addFields('merk,model');
9
10 // this executes the query and returns the result
11 $resultset = $client->select($query);
select?q=+cabriolet +abs
&facet=true&facet.pivot=merk,model