@since eZ Find 2.0

More Like This similarity searches
@param query

@return
760837
public function buildMoreLikeThis( $queryType, $query, $params = array() )
    {
        eZDebugSetting::writeDebug( 'extension-ezfind-query-mlt', $queryType, 'mlt querytype' );
        eZDebugSetting::writeDebug( 'extension-ezfind-query-mlt', $query, 'mlt query' );
        eZDebugSetting::writeDebug( 'extension-ezfind-query-mlt', $params, 'mlt params' );
        $searchCount = 0;

        $eZFindIni = eZINI::instance( 'ezfind.ini' );

        $queryInstallationID = ( isset( $params['QueryInstallationID'] ) && $params['QueryInstallationID'] ) ? $params['QueryInstallationID'] : eZSolr::installationID();
        $offset = ( isset( $params['SearchOffset'] ) && $params['SearchOffset'] ) ? $params['SearchOffset'] : 0;
        $limit = ( isset( $params['SearchLimit']  ) && $params['SearchLimit'] ) ? $params['SearchLimit'] : 10;
        $subtrees = isset( $params['SearchSubTreeArray'] ) ? $params['SearchSubTreeArray'] : array();
        $contentClassID = ( isset( $params['SearchContentClassID'] ) && $params['SearchContentClassID'] <> -1 ) ? $params['SearchContentClassID'] : false;
        $sectionID = isset( $params['SearchSectionID'] ) && $params['SearchSectionID'] > 0 ? $params['SearchSectionID'] : false;
        $filterQuery = array();


        // Add subtree query filter
        if ( !empty( $subtrees ) )
        {
            $subtreeQueryParts = array();
            foreach ( $subtrees as $subtreeNodeID )
            {
                $subtreeQueryParts[] = eZSolr::getMetaFieldName( 'path' ) . ':' . $subtreeNodeID;
            }

            $filterQuery[] = implode( ' OR ', $subtreeQueryParts );
        }

        // Add policy limitation query filter
        $policyLimitationFilterQuery = $this->policyLimitationFilterQuery();
        if ( $policyLimitationFilterQuery !== false )
        {
            $filterQuery[] = $policyLimitationFilterQuery;
        }

        // Add content class query filter
        $classLimitationFilter = $this->getContentClassFilterQuery( $contentClassID );
        if ( $classLimitationFilter !== null )
        {
            $filterQuery[] = $classLimitationFilter;
        }

        // Add section to query filter.
        if ( $sectionID )
        {
            $filterQuery[] = eZSolr::getMetaFieldName( 'section_id' ) . ':' . $sectionID;
        }

        $languageFilterQuery = $this->buildLanguageFilterQuery();
        if ( $languageFilterQuery )
        {
            $filterQuery[] = $languageFilterQuery;
        }

        $paramFilterQuery = $this->getParamFilterQuery( $params );
        if ( $paramFilterQuery )
        {
            $filterQuery[] = $paramFilterQuery;
        }

        //add raw filters
        if ( $eZFindIni->hasVariable( 'SearchFilters', 'RawFilterList' ) )
        {
            $rawFilters = $eZFindIni->variable( 'SearchFilters', 'RawFilterList' );
            if ( is_array( $rawFilters ) )
            {
                $filterQuery = array_merge( $filterQuery, $rawFilters );
            }
        }

        // Build and get facet query prameters.
        $facetQueryParamList = $this->buildFacetQueryParamList( $params );

        // return only text searcheable fields by passing NULL
        $fieldTypeExcludeList = $this->fieldTypeExludeList( NULL );

        // Create sort parameters based on the parameters.
        $sortParameter = $this->buildSortParameter( $params );
        $iniExtractionFields = $eZFindIni->variable( 'MoreLikeThis', 'ExtractionFields' );

        if ( $iniExtractionFields == 'general' )
        {
            // the collector field for all strings in an object
            $queryFields = array( 'ezf_df_text' );
        }
        else
        {
            //the array_unique below is necessary because attribute identifiers are not unique .. and we get as
            //much highlight snippets as there are duplicate attribute identifiers
            //these are also in the list of query fields (dismax, ezpublish) request handlers
            $queryFields = array_unique( $this->getClassAttributes( $contentClassID, false, $fieldTypeExcludeList ) );
        }

        //query type can vary for MLT q, or stream
        //if no valid match for the mlt query variant is obtained, it is treated as text
        $mltVariant = 'q';
        switch ( strtolower( $queryType ) )
        {
            case 'nid':
                $mltQuery = eZSolr::getMetaFieldName( 'node_id' ) . ':' . $query;
                $mltQuery .= ' AND ' . eZSolr::getMetaFieldName( 'installation_id' ) . ':' . $queryInstallationID;
                break;
            case 'oid':
                $mltQuery = eZSolr::getMetaFieldName( 'id' ) . ':' . $query;
                $mltQuery .= ' AND ' . eZSolr::getMetaFieldName( 'installation_id' ) . ':' . $queryInstallationID;
                break;
            case 'url':
                $mltVariant = 'stream.url';
                $mltQuery = $query;
                break;
            case 'text':
            default:
                $mltVariant = 'stream.body';
                $mltQuery = $query;
                break;
        }

        // fetch the mlt tuning parameters from ini settings

        $mintf = $eZFindIni->hasVariable( 'MoreLikeThis', 'MinTermFreq' )  ? $eZFindIni->variable( 'MoreLikeThis', 'MinTermFreq' ) : 1;
        $mindf = $eZFindIni->hasVariable( 'MoreLikeThis', 'MinDocFreq' ) ? $eZFindIni->variable( 'MoreLikeThis', 'MinDocFreq' ) : 1;
        $minwl = $eZFindIni->hasVariable( 'MoreLikeThis', 'MinWordLength' ) ? $eZFindIni->variable( 'MoreLikeThis', 'MinWordLength' ) : 3;
        $maxwl = $eZFindIni->hasVariable( 'MoreLikeThis', 'MaxWordLength' ) ? $eZFindIni->variable( 'MoreLikeThis', 'MaxWordLength' ) : 20;
        $maxqt = $eZFindIni->hasVariable( 'MoreLikeThis', 'MaxQueryTerms' ) ? $eZFindIni->variable( 'MoreLikeThis', 'MaxQueryTerms' ) : 5;
        $boostmlt = $eZFindIni->hasVariable( 'MoreLikeThis', 'BoostTerms' ) ? $eZFindIni->variable( 'MoreLikeThis', 'BoostTerms' ) : 'true';

        // @todo decide which of the hard-coded mlt parameters should become input parameters or ini settings
        return array_merge(
            array(
                $mltVariant => $mltQuery,
                'start' => $offset,
                'rows' => $limit,
                'sort' => $sortParameter,
                'indent' => 'on',
                'version' => '2.2',
                'mlt.match.include' => 'false', // exclude the doc itself
                'mlt.mindf' => $mindf,
                'mlt.mintf' => $mintf,
                'mlt.maxwl' => $maxwl,
                'mlt.minwl' => $minwl, //minimum wordlength
                'mlt.maxqt' => $maxqt,
                'mlt.interestingTerms' => 'details', // useful for debug output & tuning
                'mlt.boost' => $boostmlt, // boost the highest ranking terms
                //'mlt.qf' => implode( ' ', $queryFields ),
                'mlt.fl' => implode( ' ', $queryFields ),
                'fl' =>
                eZSolr::getMetaFieldName( 'guid' ) . ' ' . eZSolr::getMetaFieldName( 'installation_id' ) . ' ' .
                eZSolr::getMetaFieldName( 'main_url_alias' ) . ' ' . eZSolr::getMetaFieldName( 'installation_url' ) . ' ' .
                eZSolr::getMetaFieldName( 'id' ) . ' ' . eZSolr::getMetaFieldName( 'main_node_id' ) . ' ' .
                eZSolr::getMetaFieldName( 'language_code' ) . ' ' . eZSolr::getMetaFieldName( 'name' ) .
                ' score ' . eZSolr::getMetaFieldName( 'published' ) . ' ' .
                eZSolr::getMetaFieldName( 'path_string' ) . ' ' . eZSolr::getMetaFieldName( 'is_invisible' ),
                'fq' => $filterQuery,
                'wt' => 'php' ),
            $facetQueryParamList );

        return $queryParams;
    }
300979
@Override
	public ConstrainedResultSet<ID> findIdsByUriQuery(final WebQuery query)
	{
		return (ConstrainedResultSet<ID>) find(query, JPASearchStrategy.ID);
	}
1179879
function search (query) {
  if (!allowSearch) {
    console.error('Assets for search still loading');
    return;
  }

  var resultDocuments = [];
  var results = index.search(query + '~2'); // fuzzy
  for (var i=0; i < results.length; i++){
    var result = results[i];
    doc = documents[result.ref];
    doc.summary = doc.text.substring(0, 200);
    resultDocuments.push(doc);
  }
  return resultDocuments;
}
1349639
public AtlasSearchResult dslSearch(final String query) throws AtlasServiceException {
        MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
        queryParams.add(QUERY, query);

        return callAPI(DSL_SEARCH, AtlasSearchResult.class, queryParams);
    }
905491
@Override
    public final Query createQuery(String query)
    {
        checkClosed();
        checkTransactionNeeded();
        return getPersistenceDelegator().createQuery(query);
    }
1070827
protected final List<T> findSortedByQuery(String query, String sort, Object... params) {
        return this.dataAccess.findSortedByQuery(query, sort, params);
    }
632269
@Override
    public List<Address> search(final String query) throws IOException {

        final NominatimSearchRequest q = new NominatimSearchRequest();
        q.setQuery(query);
        return this.search(q);
    }
194484
public Results search(Query query) throws IOException {
    return search(clientKey, Collections.<String, String>emptyMap(), query);
  }
226664
@Override
	public List<ScopDescription> filterByClassificationId(String query){

		try {
			ensureDesInstalled();
		} catch (IOException e) {
			throw new ScopIOException(e);
		}

		List<ScopDescription> matches = new ArrayList<ScopDescription>();
		for (Integer i : sunidMap.keySet()){
			ScopDescription sc = sunidMap.get(i);


			if( sc.getClassificationId().startsWith(query)){
				matches.add(sc);
			}
		}

		return matches;
	}
1068836
public static <T> Root<T> findRoot(CriteriaQuery<?> query, Class<T> clazz) {

        for (Root<?> r : query.getRoots()) {
            if (clazz.equals(r.getJavaType())) {
                return (Root<T>) r.as(clazz);
            }
        }
        return null;
    }
1117582
public static List<Map> findAll(String query) {
        return new DB(DB.DEFAULT_NAME).findAll(query);
    }
475950
public static <T> Root<T> findRoot(CriteriaQuery<T> query) {
        return findRoot(query, query.getResultType());
    }
227380
@NonNull
    public Expression match(@NonNull String query) {
        if (query == null) {
            throw new IllegalArgumentException("query is null.");
        }
        return new FullTextMatchExpression(this.name, query);
    }
42303
public final Map<String, Object> search(Class<?> clazz, String query, int start, int count, boolean fetchRelation)
    {
        if (indexer != null)
        {
            if (indexer.getClass().getName().equals(IndexingConstants.LUCENE_INDEXER))
            {
                return indexer != null ? ((com.impetus.kundera.index.lucene.Indexer) indexer).search(query, start,
                        count, fetchRelation, kunderaMetadata,
                        KunderaMetadataManager.getEntityMetadata(kunderaMetadata, clazz)) : null;
            }
            else
            {
                return indexer.search(clazz, KunderaMetadataManager.getEntityMetadata(kunderaMetadata, clazz), query,
                        start, count);
            }
        }
        return new HashMap<String, Object>();
    }
182156
@SuppressWarnings("unchecked")
    @Override
    public <R> R query(TemporalQuery<R> query) {
        if (query == TemporalQueries.chronology()) {
            return (R) getChronology();
        } else if (query == TemporalQueries.precision()) {
            return (R) ChronoUnit.DAYS;
        } else if (query == TemporalQueries.localDate()) {
            return (R) LocalDate.ofEpochDay(toEpochDay());
        } else if (query == TemporalQueries.localTime() || query == TemporalQueries.zone() ||
                query == TemporalQueries.zoneId() || query == TemporalQueries.offset()) {
            return null;
        }
        return super.query(query);
    }
671824
public static ElDescriptor analyzeQuery(final GenericsContext genericsContext, final String query) {
        final List<String> vars = ElUtils.findVars(query);
        ElDescriptor descriptor = null;
        if (!vars.isEmpty()) {
            descriptor = new ElDescriptor(vars);
            checkGenericVars(descriptor, genericsContext);
        }
        return descriptor;
    }
651335
public Map<String, List<String>> parseQuery(String query)
    {
        Map<String, List<String>> queryParams = new LinkedHashMap<>();
        if (query != null) {
            for (NameValuePair params : URLEncodedUtils.parse(query, StandardCharsets.UTF_8)) {
                String name = params.getName();
                List<String> values = queryParams.get(name);
                if (values == null) {
                    values = new ArrayList<>();
                    queryParams.put(name, values);
                }
                values.add(params.getValue());
            }
        }
        return queryParams;
    }