getValue(), $b->getValue())); } /** * Creates a new text node with the same content and the provided context. * * /!\ The original node context will not be preserved (ie. not merged). * * @param Context $context Context to add on the new node * @return TextNode A text node with a context */ public function withContext(Context $context) { return new self($this->getValue(), $context); } public function buildQuery(QueryContext $context) { $query_builder = function (array $fields) use ($context) { $index_fields = []; foreach ($fields as $field) { foreach ($context->localizeField($field) as $f) { $index_fields[] = $f; } } if (!$index_fields) { return null; } return [ 'multi_match' => [ 'fields' => $index_fields, 'query' => $this->text, 'operator' => 'and', 'lenient' => true, ] ]; }; $unrestricted_fields = $context->getUnrestrictedFields(); $compatible_unrestricted_fields = Field::filterByValueCompatibility($unrestricted_fields, $this->text); $query = $query_builder($compatible_unrestricted_fields); $private_fields = $context->getPrivateFields(); $compatible_private_fields = Field::filterByValueCompatibility($private_fields, $this->text); foreach (QueryHelper::wrapPrivateFieldQueries($compatible_private_fields, $query_builder) as $private_field_query) { $query = QueryHelper::applyBooleanClause($query, 'should', $private_field_query); } // Concepts handling $concept_queries = $this->buildConceptQueriesForFields($unrestricted_fields); foreach ($concept_queries as $concept_query) { $query = QueryHelper::applyBooleanClause($query, 'should', $concept_query); } $query_builder = function (array $fields) { $concept_queries = $this->buildConceptQueriesForFields($fields); $query = null; foreach ($concept_queries as $concept_query) { $query = QueryHelper::applyBooleanClause($query, 'should', $concept_query); } return $query; }; foreach (QueryHelper::wrapPrivateFieldQueries($private_fields, $query_builder) as $private_field_query) { $query = QueryHelper::applyBooleanClause($query, 'should', $private_field_query); } return $query; } public function __toString() { return sprintf('', Term::dump($this)); } }