Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
MetaGer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
54
Issues
54
List
Boards
Labels
Service Desk
Milestones
Merge Requests
6
Merge Requests
6
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
open-source
MetaGer
Commits
d251cf41
Commit
d251cf41
authored
Oct 14, 2016
by
Karl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MetaGer.php Methoden zu großen teilen abgedeckt, Result.php angefangen
parent
091592f7
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
203 additions
and
44 deletions
+203
-44
app/MetaGer.php
app/MetaGer.php
+3
-3
app/Models/Result.php
app/Models/Result.php
+7
-9
app/Models/Searchengine.php
app/Models/Searchengine.php
+2
-2
config/sumas.xml.example
config/sumas.xml.example
+1
-1
database/factories/ModelFactory.php
database/factories/ModelFactory.php
+21
-8
tests/MetaGerPhpTest.php
tests/MetaGerPhpTest.php
+71
-19
tests/ResultPhpTest.php
tests/ResultPhpTest.php
+96
-0
tests/testSumas.xml
tests/testSumas.xml
+2
-2
No files found.
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
)
>
80
&&
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
->
strippedHost
;
$host
=
$this
->
getStrippedHost
(
$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
->
link
CallbackTester
(
$metager
,
"generateSearchLink"
,
[
"news"
],
'
/^.*?eingabe=test&focus=news&out=results$/
'
);
$this
->
link
CallbackTester
(
$metager
,
"generateQuicktipLink"
,
[],
'/
\/qt/
'
);
$this
->
link
CallbackTester
(
$metager
,
"generateSiteSearchLink"
,
[
"wolf.de"
],
'
/^.*?eingabe=test\+site%3Awolf.de&focus=web$/
'
);
$this
->
link
CallbackTester
(
$metager
,
"generateRemovedHostLink"
,
[
"wolf.de"
],
'
/^.*?eingabe=test\+-host%3Awolf.de$/
'
);
$this
->
link
CallbackTester
(
$metager
,
"generateRemovedDomainLink"
,
[
"wolf.de"
],
'
/^.*?eingabe=test\+-domain%3Awolf.de$/
'
);
$this
->
contain
CallbackTester
(
$metager
,
"generateSearchLink"
,
[
"news"
],
'
focus=news
'
);
$this
->
contain
CallbackTester
(
$metager
,
"generateQuicktipLink"
,
[],
'/
qt
'
);
$this
->
contain
CallbackTester
(
$metager
,
"generateSiteSearchLink"
,
[
"wolf.de"
],
'
site%3Awolf.de
'
);
$this
->
contain
CallbackTester
(
$metager
,
"generateRemovedHostLink"
,
[
"wolf.de"
],
'
-host%3Awolf.de
'
);
$this
->
contain
CallbackTester
(
$metager
,
"generateRemovedDomainLink"
,
[
"wolf.de"
],
'
-domain%3Awolf.de
'
);
}
public
function
linkCallbackTester
(
$metager
,
$funcName
,
$input
,
$expected
Output
)
public
function
containCallbackTester
(
$object
,
$funcName
,
$input
,
$expectedIn
Output
)
{
$output
=
call_user_func_array
(
array
(
$
metager
,
$funcName
),
$input
);
$this
->
assert
RegExp
(
$expected
Output
,
$output
);
$output
=
call_user_func_array
(
array
(
$
object
,
$funcName
),
$input
);
$this
->
assert
Contains
(
$expectedIn
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
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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