Expand my Community achievements bar.

SOLVED

How to use QueryBuilder API to search a keyword a minimum of 2 times in the Page content.

Avatar

Level 2

QueryBuilder APi list all the pages  as a search results if it finds the keyword atleast once in the Search criteria in the Page content.

But if we need to search for twice occurance in the page content, How to get the keyword search result count to find how many times the keyword exist in the page content?

You help in this regard will be really appreciated.

1 Accepted Solution

Avatar

Correct answer by
Employee

I don't know whether this helps or not but if you do this query:

path=/your/path property=text property.operation=like property.value=%keyword% orderby:path p.limit=-1

You should see the list of components where the keyword appears ordered by path, which means that if you look at the list of results, you should see pages where the keyword appears in more than one component.

It would be bad luck if it appears twice in the same component, but you could do this to find that out:

path=/your/path property=text property.operation=like property.value=%keyword%keyword%

Hope that helps
 

View solution in original post

12 Replies

Avatar

Level 10

I doubt if you have that option in Querybuilder (others can comment). but once you get the resultset from the querybuilder, you can use string operation and filter the result set

Avatar

Correct answer by
Employee

I don't know whether this helps or not but if you do this query:

path=/your/path property=text property.operation=like property.value=%keyword% orderby:path p.limit=-1

You should see the list of components where the keyword appears ordered by path, which means that if you look at the list of results, you should see pages where the keyword appears in more than one component.

It would be bad luck if it appears twice in the same component, but you could do this to find that out:

path=/your/path property=text property.operation=like property.value=%keyword%keyword%

Hope that helps
 

Avatar

Level 2

gcarlino wrote...

I don't know whether this helps or not but if you do this query:

  1. path=/your/path
  2. property=text
  3. property.operation=like
  4. property.value=%keyword%
  5. orderby:path
  6. p.limit=-1

You should see the list of components where the keyword appears ordered by path, which means that if you look at the list of results, you should see pages where the keyword appears in more than one component.

It would be bad luck if it appears twice in the same component, but you could do this to find that out:

 
  1. path=/your/path
  2. property=text
  3. property.operation=like
  4. property.value=%keyword%keyword%

Hope that helps
 

 

Sorry I tried the solution provided but it doesn't solve my problem. Please let me know the correct syntax please. and also what is the exact sytax for sorting by path? I am not able to set the sorting by path in my code.

Also without sorting my path i am not getting any result for these query parameters mentioned in your solution.

I want to understand how to find a keyword occurs twice in a page content, it may be twice in one component or not does not matter for me, as my requirement is to consider only pages which has the keyword which appears more than one time in the page content.

Any pointer to achieve this solution will greatly appreciated.

Thanks in advance.

Avatar

Level 2

bsloki wrote...

I doubt if you have that option in Querybuilder (others can comment). but once you get the resultset from the querybuilder, you can use string operation and filter the result set

 


Can you please elaborate more  on this approach . If the result of the querybuilder picks all the pages with minimum  one occurrence of the search keyword in the entire page. So from this result how do we use the string operation and i dentify which of the results have more than one occurance of the keyword?

Avatar

Employee

I will give you a specific example of what I'm trying to say. I'm doing this in a default installation, on a local instance, here: http://localhost:4502/libs/cq/search/content/querydebug.html

You enter this and click Search button:

path=/content/geometrixx property=text property.operation=like property.value=%shape% orderby:path p.limit=-1

I want to find pages where the word shape appears more than once in the geometrixx pages.
I see 17 results, ordered by path. Every time one page appear more than once in the list of results, I can say that shape is here more than once.
So in this case, we have these pages:

It's of course not ideal.

Avatar

Level 2

gcarlino wrote...

I will give you a specific example of what I'm trying to say. I'm doing this in a default installation, on a local instance, here: http://localhost:4502/libs/cq/search/content/querydebug.html

You enter this and click Search button:

  1. path=/content/geometrixx
  2. property=text
  3. property.operation=like
  4. property.value=%shape%
  5. orderby:path
  6. p.limit=-1

I want to find pages where the word shape appears more than once in the geometrixx pages.
I see 17 results, ordered by path. Every time one page appear more than once in the list of results, I can say that shape is here more than once.
So in this case, we have these pages:

It's of course not ideal.

 


Thanks a lot for giving a best possible solution to implement the solution. It would be really great if you throw some light on how to segregate the 4 results from 17 results?

Thanks

Avatar

Level 2

gcarlino wrote...

I will give you a specific example of what I'm trying to say. I'm doing this in a default installation, on a local instance, here: http://localhost:4502/libs/cq/search/content/querydebug.html

You enter this and click Search button:

  1. path=/content/geometrixx
  2. property=text
  3. property.operation=like
  4. property.value=%shape%
  5. orderby:path
  6. p.limit=-1

I want to find pages where the word shape appears more than once in the geometrixx pages.
I see 17 results, ordered by path. Every time one page appear more than once in the list of results, I can say that shape is here more than once.
So in this case, we have these pages:

It's of course not ideal.

 


How to get only 4 results which we require. as per your example, How to segregate from 17 results?

Avatar

Employee

Actually I just realized that what I told you does not really help. I was just looking at some kind of workaround.
It only searches in components with text property, but for example not in title components. Plus it's case sensitive so it will find for example shape but not Shape.

So I tried this:

path=/content/geometrixx fulltext=*shape shape* type=cq:Page p.limit=-1

As you can see, it finds more results, and it shows pages, not components. 

You could try this with your use case maybe.

Avatar

Employee

Here is the list of results i see (with comments inline):

You can see that the keyword is in 3 components of http://localhost:4502/content/geometrixx/en/company.html so this page is to keep.

All the pages above are not to keep because only one component has the keyword.

http://localhost:4502/content/geometrixx/en/services/certification.html is to keep too.

http://localhost:4502/content/geometrixx/en/services.html is to keep too.

http://localhost:4502/content/geometrixx/en/services/strategic.html is to keep too.

not to keep.

So really not ideal, as you can see. Plus it does not look at titles, since the property is jcr:title and not text. So you would have to compare this with:

path=/content/geometrixx property=jcr:title property.operation=like property.value=%shape% orderby:path p.limit=-1

An you would also have ideally to look for shape and Shape in both cases..

Avatar

Level 2

Hi ,

thanks for your alternative thinking.

I had tried this before  as my requirement is for a fulltext search only. But it doesnot meet my requirement as this search works only for one occurance of the search Keyword.

But I need  only pages in the result which has the search keyword occur atleast more than once the page.

Any help in this regard is appreciated.

Thanks

Avatar

Level 2

I understand that if more than one component has keyword than I need to choose the page. But my question is more on how? what is the code syntax to  get only the page name from the URL and skip other URLS in the resultset?

Your help is really appreciated.

 

thanks

Avatar

Employee

I don't know how to do that. As Bsloki said, I doubt if you have that option in Querybuilder. I was just trying to help you with a workaround.