Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
MetaGer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open-source
MetaGer
Commits
5cb1fcc7
Commit
5cb1fcc7
authored
8 years ago
by
Karl
Browse files
Options
Downloads
Patches
Plain Diff
Kommentare
parent
7bd5af48
No related branches found
Branches containing commit
No related tags found
1 merge request
!1365
Resolve "Filter Options for MetaGer"
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/Models/Result.php
+0
-2
0 additions, 2 deletions
app/Models/Result.php
app/Models/Searchengine.php
+74
-38
74 additions, 38 deletions
app/Models/Searchengine.php
with
74 additions
and
40 deletions
app/Models/Result.php
+
0
−
2
View file @
5cb1fcc7
...
@@ -40,8 +40,6 @@ class Result
...
@@ -40,8 +40,6 @@ class Result
$this
->
rank
=
0
;
$this
->
rank
=
0
;
$this
->
partnershop
=
$partnershop
;
$this
->
partnershop
=
$partnershop
;
$this
->
image
=
$image
;
$this
->
image
=
$image
;
#die($this->anzeigeLink . "\r\n" . $this->strippedHost);
}
}
public
function
rank
(
\App\MetaGer
$metager
)
public
function
rank
(
\App\MetaGer
$metager
)
...
...
This diff is collapsed.
Click to expand it.
app/Models/Searchengine.php
+
74
−
38
View file @
5cb1fcc7
...
@@ -14,30 +14,46 @@ abstract class Searchengine
...
@@ -14,30 +14,46 @@ abstract class Searchengine
use
DispatchesJobs
;
use
DispatchesJobs
;
protected
$ch
;
# Curl Handle zum erhalten der Ergebnisse
protected
$ch
;
# Curl Handle zum erhalten der Ergebnisse
public
$fp
;
protected
$getString
=
""
;
# Der String für die Get-Anfrage
protected
$getString
=
""
;
protected
$engine
;
# Die ursprüngliche Engine XML
protected
$engine
;
public
$enabled
=
true
;
# true, wenn die Suchmaschine nicht explizit disabled ist
protected
$counter
=
0
;
public
$results
=
[];
# Die geladenen Ergebnisse
protected
$socketNumber
=
null
;
public
$ads
=
[];
# Die geladenen Werbungen
public
$enabled
=
true
;
public
$loaded
=
false
;
# wahr, sobald die Ergebnisse geladen wurden
public
$results
=
[];
public
$cached
=
false
;
public
$ads
=
[];
public
$write_time
=
0
;
public
$ip
;
# Die IP aus der metager
public
$connection_time
=
0
;
public
$gefVon
;
# Der HTML-Code für die Verlinkung des Suchanbieters
public
$loaded
=
false
;
public
$uses
;
# Die Anzahl der Nutzungen dieser Suchmaschine
public
$cached
=
false
;
public
$homepage
;
# Die Homepage dieser Suchmaschine
public
$name
;
# Der Name dieser Suchmaschine
public
$disabled
;
# Ob diese Suchmaschine ausgeschaltet ist
public
$useragent
;
# Der HTTP Useragent
public
$startTime
;
# Die Zeit der Erstellung dieser Suchmaschine
public
$hash
;
# Der Hash-Wert dieser Suchmaschine
public
$fp
;
# Wird für Artefakte benötigt
protected
$socketNumber
=
null
;
# Wird für Artefakte benötigt
protected
$counter
=
0
;
# Wird eventuell für Artefakte benötigt
public
$write_time
=
0
;
# Wird eventuell für Artefakte benötigt
public
$connection_time
=
0
;
# Wird eventuell für Artefakte benötigt
public
function
__construct
(
\SimpleXMLElement
$engine
,
MetaGer
$metager
)
public
function
__construct
(
\SimpleXMLElement
$engine
,
MetaGer
$metager
)
{
{
# Versucht möglichst viele attribute aus dem engine XML zu laden
foreach
(
$engine
->
attributes
()
as
$key
=>
$value
)
{
foreach
(
$engine
->
attributes
()
as
$key
=>
$value
)
{
$this
->
$key
=
$value
->
__toString
();
$this
->
$key
=
$value
->
__toString
();
}
}
# Standardhomepage metager.de
if
(
!
isset
(
$this
->
homepage
))
{
if
(
!
isset
(
$this
->
homepage
))
{
$this
->
homepage
=
"https://metager.de"
;
$this
->
homepage
=
"https://metager.de"
;
}
}
# Speichert die XML der Engine
$this
->
engine
=
$engine
->
asXML
();
$this
->
engine
=
$engine
->
asXML
();
# Cache Standarddauer 60
if
(
!
isset
(
$this
->
cacheDuration
))
{
if
(
!
isset
(
$this
->
cacheDuration
))
{
$this
->
cacheDuration
=
60
;
$this
->
cacheDuration
=
60
;
}
}
...
@@ -51,12 +67,12 @@ abstract class Searchengine
...
@@ -51,12 +67,12 @@ abstract class Searchengine
return
;
return
;
}
}
# User-Agent definieren:
$this
->
useragent
=
"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.1"
;
$this
->
useragent
=
"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.1"
;
$this
->
ip
=
$metager
->
getIp
();
$this
->
ip
=
$metager
->
getIp
();
$this
->
gefVon
=
"<a href=
\"
"
.
$this
->
homepage
.
"
\"
target=
\"
_blank
\"
>"
.
$this
->
displayName
.
"</a>"
;
$this
->
gefVon
=
"<a href=
\"
"
.
$this
->
homepage
.
"
\"
target=
\"
_blank
\"
>"
.
$this
->
displayName
.
"</a>"
;
$this
->
startTime
=
microtime
();
$this
->
startTime
=
microtime
();
# Suchstring generieren
$q
=
""
;
$q
=
""
;
if
(
isset
(
$this
->
hasSiteSearch
)
&&
$this
->
hasSiteSearch
===
"1"
)
{
if
(
isset
(
$this
->
hasSiteSearch
)
&&
$this
->
hasSiteSearch
===
"1"
)
{
if
(
strlen
(
$metager
->
getSite
())
===
0
)
{
if
(
strlen
(
$metager
->
getSite
())
===
0
)
{
...
@@ -76,26 +92,30 @@ abstract class Searchengine
...
@@ -76,26 +92,30 @@ abstract class Searchengine
abstract
public
function
loadResults
(
$result
);
abstract
public
function
loadResults
(
$result
);
# ???
public
function
getNext
(
MetaGer
$metager
,
$result
)
public
function
getNext
(
MetaGer
$metager
,
$result
)
{
{
}
}
# Prüft, ob die Suche bereits gecached ist, ansonsted wird sie als Job dispatched
public
function
startSearch
(
\App\MetaGer
$metager
)
public
function
startSearch
(
\App\MetaGer
$metager
)
{
{
if
(
$this
->
canCache
&&
Cache
::
has
(
$this
->
hash
))
{
if
(
$this
->
canCache
&&
Cache
::
has
(
$this
->
hash
))
{
$this
->
cached
=
true
;
$this
->
cached
=
true
;
$this
->
retrieveResults
(
$metager
);
$this
->
retrieveResults
(
$metager
);
}
else
{
}
else
{
# Die Anfragen an die Suchmaschinen werden nun von der Laravel-Queue bearbeitet:
/* Die Anfragen an die Suchmaschinen werden nun von der Laravel-Queue bearbeitet:
# Hinweis: solange in der .env der QUEUE_DRIVER auf "sync" gestellt ist, werden die Abfragen
* Hinweis: solange in der .env der QUEUE_DRIVER auf "sync" gestellt ist, werden die Abfragen
# nacheinander abgeschickt.
* nacheinander abgeschickt.
# Sollen diese Parallel verarbeitet werden, muss ein anderer QUEUE_DRIVER verwendet werden.
* Sollen diese Parallel verarbeitet werden, muss ein anderer QUEUE_DRIVER verwendet werden.
# siehe auch: https://laravel.com/docs/5.2/queues
* siehe auch: https://laravel.com/docs/5.2/queues
*/
$this
->
dispatch
(
new
Search
(
$this
->
resultHash
,
$this
->
host
,
$this
->
port
,
$this
->
name
,
$this
->
getString
,
$this
->
useragent
));
$this
->
dispatch
(
new
Search
(
$this
->
resultHash
,
$this
->
host
,
$this
->
port
,
$this
->
name
,
$this
->
getString
,
$this
->
useragent
));
}
}
}
}
# Ruft die Ranking-Funktion aller Ergebnisse auf.
public
function
rank
(
\App\MetaGer
$metager
)
public
function
rank
(
\App\MetaGer
$metager
)
{
{
foreach
(
$this
->
results
as
$result
)
{
foreach
(
$this
->
results
as
$result
)
{
...
@@ -103,6 +123,7 @@ abstract class Searchengine
...
@@ -103,6 +123,7 @@ abstract class Searchengine
}
}
}
}
# Magic ???
private
function
setStatistic
(
$key
,
$val
)
private
function
setStatistic
(
$key
,
$val
)
{
{
...
@@ -112,6 +133,7 @@ abstract class Searchengine
...
@@ -112,6 +133,7 @@ abstract class Searchengine
$this
->
$key
=
$newVal
;
$this
->
$key
=
$newVal
;
}
}
# Entfernt wenn gesetzt das disabled="1" für diese Suchmaschine aus der sumas.xml
public
function
enable
(
$sumaFile
,
$message
)
public
function
enable
(
$sumaFile
,
$message
)
{
{
Log
::
info
(
$message
);
Log
::
info
(
$message
);
...
@@ -125,6 +147,7 @@ abstract class Searchengine
...
@@ -125,6 +147,7 @@ abstract class Searchengine
fclose
(
$this
->
fp
);
fclose
(
$this
->
fp
);
}
}
# Öffnet einen neuen Socket für diese Engine
public
function
getSocket
()
public
function
getSocket
()
{
{
$number
=
Redis
::
hget
(
'search.'
.
$this
->
hash
,
$this
->
name
);
$number
=
Redis
::
hget
(
'search.'
.
$this
->
hash
,
$this
->
name
);
...
@@ -136,6 +159,7 @@ abstract class Searchengine
...
@@ -136,6 +159,7 @@ abstract class Searchengine
}
}
}
}
# Fragt die Ergebnisse von Redis ab und lädt Sie
public
function
retrieveResults
(
MetaGer
$metager
)
public
function
retrieveResults
(
MetaGer
$metager
)
{
{
if
(
$this
->
loaded
)
{
if
(
$this
->
loaded
)
{
...
@@ -169,6 +193,7 @@ abstract class Searchengine
...
@@ -169,6 +193,7 @@ abstract class Searchengine
Redis
::
del
(
$this
->
host
.
"."
.
$this
->
socketNumber
);
Redis
::
del
(
$this
->
host
.
"."
.
$this
->
socketNumber
);
}
}
# Erstellt den für die Get-Anfrage genutzten Host-Link
protected
function
getHost
()
protected
function
getHost
()
{
{
$return
=
""
;
$return
=
""
;
...
@@ -181,26 +206,7 @@ abstract class Searchengine
...
@@ -181,26 +206,7 @@ abstract class Searchengine
return
$return
;
return
$return
;
}
}
public
function
getCurlInfo
()
# Erstellt den für die Get-Anfrage genutzten String
{
return
curl_getinfo
(
$this
->
ch
);
}
public
function
getCurlErrors
()
{
return
curl_errno
(
$this
->
ch
);
}
public
function
addCurlHandle
(
$mh
)
{
curl_multi_add_handle
(
$mh
,
$this
->
ch
);
}
public
function
removeCurlHandle
(
$mh
)
{
curl_multi_remove_handle
(
$mh
,
$this
->
ch
);
}
private
function
generateGetString
(
$query
,
$url
,
$language
,
$category
)
private
function
generateGetString
(
$query
,
$url
,
$language
,
$category
)
{
{
$getString
=
""
;
$getString
=
""
;
...
@@ -218,32 +224,39 @@ abstract class Searchengine
...
@@ -218,32 +224,39 @@ abstract class Searchengine
}
}
# Wir müssen noch einige Platzhalter in dem GET-String ersetzen:
# Wir müssen noch einige Platzhalter in dem GET-String ersetzen:
# Useragent
if
(
strpos
(
$getString
,
"<<USERAGENT>>"
))
{
if
(
strpos
(
$getString
,
"<<USERAGENT>>"
))
{
$getString
=
str_replace
(
"<<USERAGENT>>"
,
$this
->
urlEncode
(
$this
->
useragent
),
$getString
);
$getString
=
str_replace
(
"<<USERAGENT>>"
,
$this
->
urlEncode
(
$this
->
useragent
),
$getString
);
}
}
# Query
if
(
strpos
(
$getString
,
"<<QUERY>>"
))
{
if
(
strpos
(
$getString
,
"<<QUERY>>"
))
{
$getString
=
str_replace
(
"<<QUERY>>"
,
$this
->
urlEncode
(
$query
),
$getString
);
$getString
=
str_replace
(
"<<QUERY>>"
,
$this
->
urlEncode
(
$query
),
$getString
);
}
}
# IP
if
(
strpos
(
$getString
,
"<<IP>>"
))
{
if
(
strpos
(
$getString
,
"<<IP>>"
))
{
$getString
=
str_replace
(
"<<IP>>"
,
$this
->
urlEncode
(
$this
->
ip
),
$getString
);
$getString
=
str_replace
(
"<<IP>>"
,
$this
->
urlEncode
(
$this
->
ip
),
$getString
);
}
}
# Language
if
(
strpos
(
$getString
,
"<<LANGUAGE>>"
))
{
if
(
strpos
(
$getString
,
"<<LANGUAGE>>"
))
{
$getString
=
str_replace
(
"<<LANGUAGE>>"
,
$this
->
urlEncode
(
$language
),
$getString
);
$getString
=
str_replace
(
"<<LANGUAGE>>"
,
$this
->
urlEncode
(
$language
),
$getString
);
}
}
# Category
if
(
strpos
(
$getString
,
"<<CATEGORY>>"
))
{
if
(
strpos
(
$getString
,
"<<CATEGORY>>"
))
{
$getString
=
str_replace
(
"<<CATEGORY>>"
,
$this
->
urlEncode
(
$category
),
$getString
);
$getString
=
str_replace
(
"<<CATEGORY>>"
,
$this
->
urlEncode
(
$category
),
$getString
);
}
}
# Affildata
if
(
strpos
(
$getString
,
"<<AFFILDATA>>"
))
{
if
(
strpos
(
$getString
,
"<<AFFILDATA>>"
))
{
$getString
=
str_replace
(
"<<AFFILDATA>>"
,
$this
->
getOvertureAffilData
(
$url
),
$getString
);
$getString
=
str_replace
(
"<<AFFILDATA>>"
,
$this
->
getOvertureAffilData
(
$url
),
$getString
);
}
}
return
$getString
;
return
$getString
;
}
}
# Wandelt einen String nach aktuell gesetztem inputEncoding dieser Searchengine in URL-Format um
protected
function
urlEncode
(
$string
)
protected
function
urlEncode
(
$string
)
{
{
if
(
isset
(
$this
->
inputEncoding
))
{
if
(
isset
(
$this
->
inputEncoding
))
{
...
@@ -253,6 +266,7 @@ abstract class Searchengine
...
@@ -253,6 +266,7 @@ abstract class Searchengine
}
}
}
}
# Liefert Sonderdaten für Yahoo
private
function
getOvertureAffilData
(
$url
)
private
function
getOvertureAffilData
(
$url
)
{
{
$affil_data
=
'ip='
.
$this
->
ip
;
$affil_data
=
'ip='
.
$this
->
ip
;
...
@@ -271,4 +285,26 @@ abstract class Searchengine
...
@@ -271,4 +285,26 @@ abstract class Searchengine
{
{
return
$this
->
enabled
;
return
$this
->
enabled
;
}
}
# Artefaktmethoden
public
function
getCurlInfo
()
{
return
curl_getinfo
(
$this
->
ch
);
}
public
function
getCurlErrors
()
{
return
curl_errno
(
$this
->
ch
);
}
public
function
addCurlHandle
(
$mh
)
{
curl_multi_add_handle
(
$mh
,
$this
->
ch
);
}
public
function
removeCurlHandle
(
$mh
)
{
curl_multi_remove_handle
(
$mh
,
$this
->
ch
);
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment