Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
open-source
MetaGer
Commits
d251cf41
Commit
d251cf41
authored
Oct 14, 2016
by
Karl
Browse files
MetaGer.php Methoden zu großen teilen abgedeckt, Result.php angefangen
parent
091592f7
Changes
8
Hide whitespace changes
Inline
Side-by-side
app/MetaGer.php
View file @
d251cf41
...
...
@@ -393,7 +393,7 @@ class MetaGer
*/
foreach
(
$sumas
as
$suma
)
{
if
(
$this
->
sumaIsSelected
(
$suma
,
$request
)
||
(
$this
->
isBildersuche
()
||
(
!
$this
->
isBildersuche
()
&&
$this
->
sumaIsAdsuche
(
$suma
,
$overtureEnabled
))
&&
(
!
$this
->
sumaIsDisabled
(
$suma
)))
{
if
(
$this
->
sumaIsOverture
(
$suma
))
{
...
...
@@ -536,7 +536,7 @@ class MetaGer
public
function
isBildersuche
()
{
return
$this
->
fokus
!
==
"bilder"
;
return
$this
->
fokus
=
==
"bilder"
;
}
public
function
sumaIsAdsuche
(
$suma
,
$overtureEnabled
)
...
...
@@ -973,7 +973,7 @@ class MetaGer
public
function
rankAll
()
{
foreach
(
$this
->
engines
as
$engine
)
{
$engine
->
rank
(
$this
);
$engine
->
rank
(
$this
->
getQ
()
);
}
}
...
...
app/Models/Result.php
View file @
d251cf41
...
...
@@ -69,12 +69,10 @@ class Result
* + 0.02 * Sourcerank (20 - Position in Ergebnisliste des Suchanbieters)
* * Engine-Boost
*/
public
function
rank
(
\
App\MetaGer
$metager
)
public
function
rank
(
$eingabe
)
{
$rank
=
0
;
$eingabe
=
$metager
->
getQ
();
# Boost für Source Ranking
$rank
+=
(
$this
->
sourceRank
*
0.02
);
...
...
@@ -130,7 +128,7 @@ class Result
$tmpLink
=
str_replace
(
urlencode
(
$char
),
""
,
$tmpLink
);
}
}
if
(
strlen
(
$this
->
descr
)
>
8
0
&&
strlen
(
$link
)
>
0
)
{
if
(
strlen
(
$this
->
descr
)
>
0
/*80*/
&&
strlen
(
$link
)
>
0
)
{
return
$count
/
((
strlen
(
$link
))
*
60
);
# ???
}
else
{
return
0
;
...
...
@@ -249,7 +247,7 @@ class Result
* "http://www.foo.bar.de/test?ja=1" -> "foo.bar.de"
* gebracht.
*/
p
rivate
function
getStrippedHost
(
$link
)
p
ublic
function
getStrippedHost
(
$link
)
{
if
(
strpos
(
$link
,
"http"
)
!==
0
)
{
$link
=
"http://"
.
$link
;
...
...
@@ -265,13 +263,13 @@ class Result
* "http://www.foo.bar.de/test?ja=1" -> "foo.bar.de/test"
* gebracht.
*/
p
rivate
function
getStrippedLink
(
$link
)
p
ublic
function
getStrippedLink
(
$link
)
{
if
(
strpos
(
$link
,
"http"
)
!==
0
)
{
$link
=
"http://"
.
$link
;
}
$host
=
$this
->
s
trippedHost
;
$host
=
$this
->
getS
trippedHost
(
$link
)
;
$path
=
@
parse_url
(
$link
,
PHP_URL_PATH
);
return
$host
.
$path
;
}
...
...
@@ -281,7 +279,7 @@ class Result
* "http://www.foo.bar.de/test?ja=1" -> "bar.de"
* gebracht.
*/
p
rivate
function
getStrippedDomain
(
$link
)
p
ublic
function
getStrippedDomain
(
$link
)
{
if
(
preg_match
(
"/([^\.]*\.[^\.]*)$/si"
,
$link
,
$match
))
{
return
$match
[
1
];
...
...
@@ -291,7 +289,7 @@ class Result
}
# Erstellt aus einem Link einen Proxy-Link für unseren Proxy-Service
p
rivate
function
generateProxyLink
(
$link
)
p
ublic
function
generateProxyLink
(
$link
)
{
if
(
!
$link
)
{
return
""
;
...
...
app/Models/Searchengine.php
View file @
d251cf41
...
...
@@ -118,10 +118,10 @@ abstract class Searchengine
}
# Ruft die Ranking-Funktion aller Ergebnisse auf.
public
function
rank
(
\
App\MetaGer
$metager
)
public
function
rank
(
$eingabe
)
{
foreach
(
$this
->
results
as
$result
)
{
$result
->
rank
(
$
metager
);
$result
->
rank
(
$
eingabe
);
}
}
...
...
config/sumas.xml.example
View file @
d251cf41
...
...
@@ -5,7 +5,7 @@
name="suchmaschine"
host="www.suchmaschine.de"
skript="/suche/"
formData="sprache=de&sortieren=true&
&
queue=<<QUERY>>"
formData="sprache=de&sortieren=true&queue=<<QUERY>>"
package="suchmaschine"
displayName="Meine Suchmaschine"
homepage="www.suchmaschine.de/welcome"
...
...
database/factories/ModelFactory.php
View file @
d251cf41
...
...
@@ -9,15 +9,28 @@
| you a convenient way to create models for testing and seeding your
| database. Just tell the factory how a default model should look.
|
*/
$factory
->
define
(
App\User
::
class
,
function
(
Faker
\
Generator
$faker
)
{
static
$password
;
*/
$factory
->
define
(
app\Models\parserSkripte\Base
::
class
,
function
(
Faker
\
Generator
$faker
)
{
return
[
'name'
=>
$faker
->
name
,
'email'
=>
$faker
->
unique
()
->
safeEmail
,
'password'
=>
$password
?:
$password
=
bcrypt
(
'secret'
),
'remember_token'
=>
str_random
(
10
),
"provider"
=>
null
,
"titel"
=>
"Hotels in L'Alpe-d'Huez"
,
"link"
=>
"http://r.search.yahoo.com/cbclk/dWU9QUIxMzdDQTVGRUE1NDk4QiZ1dD0xNDc2NDMwMTM0MDY3JnVvPTUzNjEzNzI2OTYmbHQ9MiZlcz01LmtfeFdJR1BTOWpkdU95/RV=2/RE=1476458934/RO=10/RU=http%3a%2f%2f1616540.r.msn.com%2f%3fld%3dd3L21YyadK5JKikZbdYGL_WTVUCUwdKsA4ixeD_Iy-fyOol49ZUDwtvNaQrgo9_hrBZE29ZA8_kcVZvUh8zA3VBZsCAZK8rx10IhFt_RT45dthIWzATMhQpwXLvlSEiWjbX3oR-mghf0LQjcyYIqYSxSurjZ0%26u%3dhttp%253a%252f%252fwww.booking.com%252fcity%252ffr%252fl-alpe-d-huez.de.html%253faid%253d349014%2526label%253dmsn-w0pcQaojEix%2al5%2ajWskE5Q-5361372696%2526utm_campaign%253dFrance%2526utm_medium%253dcpc%2526utm_source%253dbing%2526utm_term%253dw0pcQaojEix%2al5%2ajWskE5Q/RK=0/RS=OWBpMcIG_XjwGHTMqrfc7GScvPg-"
,
"anzeigeLink"
=>
"www.booking.com"
,
"descr"
=>
"Schnell und sicher ein Hotel buchen. Alle Hotels mit Spezial-Angeboten."
,
"gefVon"
=>
"Yahoo"
,
"sourceRank"
=>
0
,
"partnershop"
=>
false
,
"image"
=>
""
,
"proxyLink"
=>
"https://proxy.suma-ev.de/cgi-bin/nph-proxy.cgi/en/I0/http/r.search.yahoo.com/cbclk/dWU9QUIxMzdDQTVGRUE1NDk4QiZ1dD0xNDc2NDMwMTM0MDY3JnVvPTUzNjEzNzI2OTYmbHQ9MiZlcz01LmtfeFdJR1BTOWpkdU95/RV=2/RE=1476458934/RO=10/RU=http%3a%2f%2f1616540.r.msn.com%2f%3fld%3dd3L21YyadK5JKikZbdYGL_WTVUCUwdKsA4ixeD_Iy-fyOol49ZUDwtvNaQrgo9_hrBZE29ZA8_kcVZvUh8zA3VBZsCAZK8rx10IhFt_RT45dthIWzATMhQpwXLvlSEiWjbX3oR-mghf0LQjcyYIqYSxSurjZ0%26u%3dhttp%253a%252f%252fwww.booking.com%252fcity%252ffr%252fl-alpe-d-huez.de.html%253faid%253d349014%2526label%253dmsn-w0pcQaojEix%2al5%2ajWskE5Q-5361372696%2526utm_campaign%253dFrance%2526utm_medium%253dcpc%2526utm_source%253dbing%2526utm_term%253dw0pcQaojEix%2al5%2ajWskE5Q/RK=0/RS=OWBpMcIG_XjwGHTMqrfc7GScvPg-"
,
"engineBoost"
=>
1.2
,
"valid"
=>
true
,
"host"
=>
"r.search.yahoo.com"
,
"strippedHost"
=>
"booking.com"
,
"strippedDomain"
=>
"booking.com"
,
"strippedLink"
=>
"booking.com"
,
"rank"
=>
0
,
"price"
=>
0
,
"additionalInformation"
=>
[],
];
});
tests/MetaGerPhpTest.php
View file @
d251cf41
...
...
@@ -14,12 +14,19 @@ class MetaGerPhpTest extends TestCase
{
$this
->
fullRunTest
();
$this
->
specialSearchTest
();
$this
->
createSearchEngines
Test
();
$this
->
specialSuma
Test
();
$this
->
linkGeneratorTest
();
#$this->getHostCountTest();
$this
->
addLinkTest
();
$this
->
adjustFocusTest
();
$this
->
checkCanNotSitesearchTest
();
$this
->
isBildersucheTest
();
$this
->
loadMiniSucherTest
();
$this
->
getImageProxyLinkTest
();
$this
->
showQuicktipsTest
();
# Brauchen Engine Dummy
#$this->popAdTest();
#$this->productsTest();
}
public
function
fullRunTest
()
...
...
@@ -77,11 +84,6 @@ class MetaGerPhpTest extends TestCase
$this
->
assertEquals
(
"i want phrase"
,
$metager
->
getPhrases
()[
0
]);
}
public
function
createSearchEnginesTest
()
{
$this
->
specialSumaTest
();
}
public
function
addLinkTest
()
{
$metager
=
new
MetaGer
();
...
...
@@ -109,22 +111,22 @@ class MetaGerPhpTest extends TestCase
$metager
=
new
Metager
();
$request
=
new
Request
([
'eingabe'
=>
'test'
]);
$metager
->
parseFormData
(
$request
);
$this
->
l
in
k
CallbackTester
(
$metager
,
"generateSearchLink"
,
[
"news"
],
'
/^.*?eingabe=test&focus=news&out=results$/
'
);
$this
->
l
in
k
CallbackTester
(
$metager
,
"generateQuicktipLink"
,
[],
'/
\/
qt
/
'
);
$this
->
l
in
k
CallbackTester
(
$metager
,
"generateSiteSearchLink"
,
[
"wolf.de"
],
'
/^.*?eingabe=test\+
site%3Awolf.de
&focus=web$/
'
);
$this
->
l
in
k
CallbackTester
(
$metager
,
"generateRemovedHostLink"
,
[
"wolf.de"
],
'
/^.*?eingabe=test\+
-host%3Awolf.de
$/
'
);
$this
->
l
in
k
CallbackTester
(
$metager
,
"generateRemovedDomainLink"
,
[
"wolf.de"
],
'
/^.*?eingabe=test\+
-domain%3Awolf.de
$/
'
);
$this
->
conta
inCallbackTester
(
$metager
,
"generateSearchLink"
,
[
"news"
],
'
focus=news
'
);
$this
->
conta
inCallbackTester
(
$metager
,
"generateQuicktipLink"
,
[],
'/qt'
);
$this
->
conta
inCallbackTester
(
$metager
,
"generateSiteSearchLink"
,
[
"wolf.de"
],
'site%3Awolf.de'
);
$this
->
conta
inCallbackTester
(
$metager
,
"generateRemovedHostLink"
,
[
"wolf.de"
],
'-host%3Awolf.de'
);
$this
->
conta
inCallbackTester
(
$metager
,
"generateRemovedDomainLink"
,
[
"wolf.de"
],
'-domain%3Awolf.de'
);
}
public
function
l
in
k
CallbackTester
(
$
metager
,
$funcName
,
$input
,
$expectedOutput
)
public
function
conta
inCallbackTester
(
$
object
,
$funcName
,
$input
,
$expected
In
Output
)
{
$output
=
call_user_func_array
(
array
(
$
metager
,
$funcName
),
$input
);
$this
->
assert
RegExp
(
$expectedOutput
,
$output
);
$output
=
call_user_func_array
(
array
(
$
object
,
$funcName
),
$input
);
$this
->
assert
Contains
(
$expected
In
Output
,
$output
);
}
public
function
getHostCountTest
()
...
...
@@ -158,4 +160,54 @@ class MetaGerPhpTest extends TestCase
$enabledSearchengines
=
simplexml_load_file
(
"tests/testSumas.xml"
)
->
xpath
(
"suma"
);
# Eine spezielle test sumas.xml
$this
->
assertFalse
(
$metager
->
checkCanNotSitesearch
(
$enabledSearchengines
));
}
public
function
isBildersucheTest
()
{
$metager
=
new
MetaGer
();
$request
=
new
Request
([
"focus"
=>
"bilder"
]);
$metager
->
parseFormData
(
$request
);
$this
->
assertTrue
(
$metager
->
isBildersuche
());
}
public
function
loadMiniSucherTest
()
{
$metager
=
new
MetaGer
();
$sumas
=
simplexml_load_file
(
"tests/testSumas.xml"
);
$subcollections
=
[
"minism1"
,
"minism2"
];
$minisucher
=
$metager
->
loadMiniSucher
(
$sumas
,
$subcollections
);
$this
->
assertContains
(
"rows=10"
,
$minisucher
[
"formData"
]
->
__toString
());
$this
->
assertContains
(
"fq=subcollection:%28minism1+OR+minism2%29"
,
$minisucher
[
"formData"
]
->
__toString
());
}
public
function
getImageProxyLinkTest
()
{
$metager
=
new
MetaGer
();
$this
->
containCallbackTester
(
$metager
,
"getImageProxyLink"
,
[
"www.bilder.de/bild1.png"
],
"url=www.bilder.de%2Fbild1.png"
);
}
public
function
showQuicktipsTest
()
{
$metager
=
new
MetaGer
();
$request
=
new
Request
([
"quicktips"
=>
"yo"
]);
$metager
->
parseFormData
(
$request
);
$this
->
assertFalse
(
$metager
->
showQuicktips
());
}
public
function
popAdTest
()
{
$metager
=
new
MetaGer
();
$this
->
assertNull
(
$metager
->
popAd
());
$engines
=
[];
$engines
[]
=
factory
(
app\Models\parserSkripte\Base
::
class
)
->
make
([],
null
);
$metager
->
combineResults
(
$engines
);
$ad
=
$metager
->
popAd
();
$this
->
assertNull
(
$metager
->
popAd
());
}
public
function
productsTest
()
{
$metager
=
new
MetaGer
();
$metager
->
hasProducts
();
$metager
->
getProducts
();
}
}
tests/ResultPhpTest.php
0 → 100644
View file @
d251cf41
<?php
use
App\MetaGer
;
use
App\Models\Result
;
use
Illuminate\Http\Request
;
class
ResultPhpTest
extends
TestCase
{
/**
* A basic test example.
*
* @return void
*/
public
function
test
()
{
$this
->
rankingTest
();
$this
->
isValidTest
();
$this
->
linkGeneratorsTest
();
}
public
function
getDummyResult
()
{
$provider
=
file_get_contents
(
"tests/testSumas.xml"
);
$titel
=
"Titel"
;
$link
=
"link.de"
;
$anzeigeLink
=
"link.de/anzeige"
;
$descr
=
"Beschreibung: i want phrase"
;
$gefVon
=
""
;
$sourceRank
=
1
;
return
new
Result
(
$provider
,
$titel
,
$link
,
$anzeigeLink
,
$descr
,
$gefVon
,
$sourceRank
);
}
public
function
getDummyMetaGer
()
{
$metager
=
new
MetaGer
();
$request
=
$this
->
createDummyRequest
();
$metager
->
parseFormData
(
$request
);
$metager
->
checkSpecialSearches
(
$request
);
return
$metager
;
}
public
function
createDummyRequest
()
{
$query
=
[];
$query
[
"eingabe"
]
=
'suchwort -blackword -host:blackhost -domain:blackdomain site:wantsite "i want phrase"'
;
$query
[
"focus"
]
=
"angepasst"
;
$query
[
"encoding"
]
=
"utf8"
;
$query
[
"lang"
]
=
"all"
;
$query
[
"time"
]
=
"1000"
;
$query
[
"sprueche"
]
=
"on"
;
$query
[
"resultCount"
]
=
"20"
;
$query
[
"tab"
]
=
"on"
;
$query
[
"onenewspage"
]
=
"on"
;
return
new
Request
(
$query
);
}
public
function
rankingTest
()
{
$result
=
$this
->
getDummyResult
();
$result
->
rank
(
"link"
);
# 0.38, 0.38512820512820511 mit url-boost auch bei description länge > 0 statt > 80
$this
->
assertEquals
(
0.4
,
$result
->
getRank
(),
"Not within Range of Actual Value"
,
0.1
);
$result
->
rank
(
"titel"
);
# 0.38419999999999999
$this
->
assertEquals
(
0.4
,
$result
->
getRank
(),
"Not within Range of Actual Value"
,
0.1
);
$result
->
rank
(
"beschreibung"
);
# 0.38280000000000003
$this
->
assertEquals
(
0.4
,
$result
->
getRank
(),
"Not within Range of Actual Value"
,
0.1
);
$result
->
rank
(
"baum"
);
# 0.38
$this
->
assertEquals
(
0.4
,
$result
->
getRank
(),
"Not within Range of Actual Value"
,
0.1
);
}
public
function
isValidTest
()
{
$result
=
$this
->
getDummyResult
();
$metager
=
$this
->
getDummyMetaGer
();
$this
->
assertTrue
(
$result
->
isValid
(
$metager
));
}
public
function
linkGeneratorsTest
()
{
$result
=
$this
->
getDummyResult
();
$this
->
equalCallbackTester
(
$result
,
"getStrippedHost"
,
[
"http://www.foo.bar.de/test?ja=1"
],
'foo.bar.de'
);
$this
->
equalCallbackTester
(
$result
,
"getStrippedLink"
,
[
"http://www.foo.bar.de/test?ja=1"
],
'foo.bar.de/test'
);
$this
->
equalCallbackTester
(
$result
,
"getStrippedDomain"
,
[
"http://www.foo.bar.de/test?ja=1"
],
'bar.de'
);
$this
->
equalCallbackTester
(
$result
,
"generateProxyLink"
,
[
"news"
],
'focus=news'
);
}
public
function
equalCallbackTester
(
$object
,
$funcName
,
$input
,
$expectedInOutput
)
{
$output
=
call_user_func_array
(
array
(
$object
,
$funcName
),
$input
);
$this
->
assertEquals
(
$expectedInOutput
,
$output
);
}
}
tests/testSumas.xml
View file @
d251cf41
<?xml version="1.0" encoding="UTF-8"?>
<sumas>
<suma
name=
"
suchmaschine
"
name=
"
minism
"
host=
"www.suchmaschine.de"
skript=
"/suche/"
formData=
"sprache=de&sortieren=true&
&
queue=<<QUERY>>"
formData=
"sprache=de&sortieren=true&queue=<<QUERY>>
&rows=<<COUNT>>&fq=subcollection:<<SUBCOLLECTIONS>>
"
package=
"suchmaschine"
displayName=
"Meine Suchmaschine"
homepage=
"www.suchmaschine.de/welcome"
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment