+ if (preg_match_all('#nick:([^ ]*)#', $query, $matches)) {
+ foreach ($matches[1] as $authorName) {
+ $query = str_replace(
+ 'nick:' . $authorName,
+ 'author.name:' . $authorName,
+ $query
+ );
+ }
+ }
+
+ $qMust = array();//query parts for the MUST section
+
+ //modification date filters
+ if (preg_match('#after:([^ ]+)#', $query, $matches)) {
+ $dateAfter = $matches[1];
+ $query = trim(str_replace($matches[0], '', $query));
+ $qMust[] = array(
+ 'range' => array(
+ 'status.modate' => array(
+ 'gt' => $dateAfter . '||/d',
+ )
+ )
+ );
+ }
+ if (preg_match('#before:([^ ]+)#', $query, $matches)) {
+ $dateBefore = $matches[1];
+ $query = trim(str_replace($matches[0], '', $query));
+ $qMust[] = array(
+ 'range' => array(
+ 'status.modate' => array(
+ 'lt' => $dateBefore . '||/d',
+ )
+ )
+ );
+ }
+ if (preg_match('#date:([^ ]+)#', $query, $matches)) {
+ $dateExact = $matches[1];
+ $query = trim(str_replace($matches[0], '', $query));
+ $qMust[] = array(
+ 'range' => array(
+ 'status.modate' => array(
+ 'gte' => $dateExact . '||/d',
+ 'lte' => $dateExact . '||/d',
+ )
+ )
+ );
+ }
+
+ if (strpos($query, '/') !== false && strpos($query, '"') === false) {
+ //add quotes when there is a slash and no quotes
+ // https://stackoverflow.com/questions/31963643/escaping-forward-slashes-in-elasticsearch
+ $query = '"' . $query . '"';
+ }
+ $qMust[] = array(
+ 'query_string' => array(
+ 'default_field' => '_all',
+ 'default_operator' => 'AND',
+ 'query' => $query
+ )
+ );
+ $qMust[] = array(
+ 'term' => array(
+ 'status.findable' => true
+ )
+ );
+
+ if ($sort == '' && $GLOBALS['phinde']['defaultSort'] == 'date') {
+ $sort = 'date';
+ }
+ if ($sort == 'date') {
+ $sortCfg = array('status.modate' => array('order' => 'desc'));
+ } else {
+ $sortCfg = array();
+ }
+
+ $contentMatchSize = 100;
+ if ($GLOBALS['phinde']['showFullContent']) {
+ $contentMatchSize = 999999;
+ }
+