Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the possibility to search by ContentId or LocationId in the searc… #70

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,30 @@ const HEADERS_CREATE_VIEW = {
const QUERY_LIMIT = 50;
const ENDPOINT_CREATE_VIEW = '/api/ezp/v2/views';

/**
* Build the criterion for the search.
* Tries to find a search by contentId or locationId with 'location:123' or 'content:456' in the query
* If no such pattern is found, return a FullTextCriterion
* @function buildQueryCriterions
* @param {String} query
* @returns {Object}
*/
const buildQueryCriterions = query => {
const re = new RegExp(/(content|location):([0-9]+)/);
let criterion = {};
let searchParts = [];
if ((searchParts = re.exec(query)) !== null) {
if (parseInt(searchParts[2]) > 0) {
const criterion = {};
let criterionName = searchParts[1].toLowerCase()+'IdCriterion';
criterionName = criterionName.charAt(0).toUpperCase()+criterionName.substr(1);
criterion[criterionName] = parseInt(searchParts[2]);
return criterion;
}
}
return {FullTextCriterion: query};
};

/**
* Loads preselected location data
*
Expand Down Expand Up @@ -201,7 +225,7 @@ export const findContentBySearchQuery = ({ token, siteaccess }, query, callback)
Criteria: {},
FacetBuilders: {},
SortClauses: {},
Filter: { FullTextCriterion: query },
Filter: buildQueryCriterions(query),
limit: QUERY_LIMIT,
offset: 0,
},
Expand Down