How to perform exact search using solr QueryManager in a XWIki Extension?


I have a piece of code to perform some custom solr search in one of my API implemented in an XWiki extension

		Query slrQuery = this.queryManager.createQuery(String.format("*%s*", driveId), "solr");
	        List<String> filterQuery = new ArrayList<String>();
	        // We want only visible documents with a CollabClass
	        List<String> qf = new ArrayList<String>();

	        slrQuery.bindValue("qf", qf);
            QueryResponse response = null;
            SolrDocumentList documents = null;

            response = (QueryResponse) slrQuery.execute().get(0);
            documents = response.getResults();

I read that I should use a KeywordTokenizer to perform exact match in solr

But how can I configure that in XWiki with embedded solr ? Or is it possible to perform the exact search just on this query ? I don’t wan’t it apply to the default XWiki solr search.

No, because the way Solr matches the query against the specified fields (DriveRepositoryId) depends on how those fields are indexed, so it depends on the Solr schema. You need to see in which ways the `DriveRepositoryId`` is indexed (the same information can be indexed in multiple ways to support multiple types of queries) and whether one of those index fields supports exact matching. Otherwise you need to write code that adds the missing index field for exact matching, but this is more complex.

Have you tried suffixing the property name with _string when setting the query fields (e.g. DriveRepositoryId_string)?