NAME
DDG::Request - A request to DuckDuckGo itself, so the query itself and parameter around the query defining him
VERSION
version 1018
SYNOPSIS
my $req = DDG::Request->new( query_raw => "Peter PAUL AND MARY!" );
print $req->query_clean; # "peter paul and mary"
DESCRIPTION
This is the main request class which reflects a query and all parameter that are relevant for plugins to work with the request. It does not reflect a web request itself to DuckDuckGo, for this we have internal classes. The request class is the abstracted level all services can independently work with, on any medium, so also on the API, or via console based tests without web environment. This class is also base for run on a DDG::Block.
Beside the information of the query itself, a DDG::Request can also contain the language, the region and the geo location (which is calculated out of the IP).
ATTRIBUTES
query_raw
This is the only required attribute. It is the query in the most raw form. If the query is given over special ways (like coming out of a hard url like https://duckduckgo.com/Star_Trek_Voyager), then those most get converted to the text that is normally shown on the query line then, before given to "query_raw".
query_raw_parts
This attribute gets generated out of the "query_raw", which gets split into all whitespace and non-whitespace content. For example the query:
DDG::Request->new( query_raw => "A++ B++" );
would give you the following arrayref on "query_raw_parts":
[
'A++',
' ',
'B++',
]
It preserves the exactly content of the query also the current amount of whitespaces. Always the even index positions of the arrayref is the non whitespace content. So if you have the query:
DDG::Request->new( query_raw => " A++ B++ " );
leads to this "query_raw_parts" to fulfill this:
[
'',
' '
'A++',
' ',
'B++',
' ',
]
query_parts
This functions filters out the whitespace parts and empty parts of "query_raw_parts".
query_parts_lc
This takes the arrayref of "query_parts" and makes a lowercase arrayref version of it.
triggers
Triggers generate a hashref construction which makes it very easy to parse a query very effective through the accessing it word by word and so just analyzing against as less combinations as possible.
It uses "query_raw_parts" for this, but ignores the whitespace parts. Then it passes every part through "generate_triggers" which gives back all possible variants of the specific given part.
matched_trigger
Uses "remainder" and "query_raw" to derive the trigger. Will only work when using the remainder handle.
query
Takes "query_parts" and join them with one space.
query_lc
Takes "query" and lowercases it.
query_nowhitespace
Takes "query" and removes all whitespaces.
query_nowhitespace_nodash
Takes "query" and removes all whitespaces and dashes.
query_clean
Takes "query_lc" and removes all whitespaces and all non alphanumeric ascii.
words
Takes "query_clean" and generates an arrayref of the non-whitespace parts.
wordcount
Is the count of the elements in "words"
seen_plugins
This array contains all the plugins which already worked with this request. This means all the plugins which are triggered. If they gave back a result or not, doesn't matter here. This list is used by "allow_duplicate" in DDG::Block.
METHODS
generate_triggers
This function takes a part of "query_raw_parts" and generates all possible variants of it, also doing some magic with dash given words to give both single or combined without dash or only with space. For specific analyze what triggers are generated out of a part please read the function.
generate_remainder
The method takes 2 index positions of "query_raw_parts" to give out the other parts of the query which is ot between them, so removes those parts and generates out of the rest again a string which can be given to a plugin for example.
It doesnt check which one is bigger, the first one must always be lower then the second one given. You can also just give one index position.
When called will set the remainder attribute for later use, e.g. "matched_trigger".
AUTHOR
DuckDuckGo <open@duckduckgo.com>
COPYRIGHT AND LICENSE
This software is Copyright (c) 2013 by DuckDuckGo, Inc. https://duckduckgo.com/.
This is free software, licensed under:
The Apache License, Version 2.0, January 2004