Message Boards

Custom search and indexing

thumbnail
ali yeganeh, modified 4 Years ago.

Custom search and indexing

Regular Member Posts: 148 Join Date: 5/1/19 Recent Posts
Hi
According to the liferay tutorial in search and indexing section
I want search between a specific data of table  (  search in the query result )
For example, any user can search on their dashboard data
thumbnail
David H Nebinger, modified 4 Years ago.

RE: Custom search and indexing

Liferay Legend Posts: 14919 Join Date: 9/2/06 Recent Posts
And?
thumbnail
ali yeganeh, modified 4 Years ago.

RE: Custom search and indexing

Regular Member Posts: 148 Join Date: 5/1/19 Recent Posts
Hi David H Nebinger
What is your suggestion for me to be able to search the part of the table data that belongs to a particular user?
thumbnail
David H Nebinger, modified 4 Years ago.

RE: Custom search and indexing

Liferay Legend Posts: 14919 Join Date: 9/2/06 Recent Posts
I'm not really sure what you are asking about...

The indexing and search link you pointed to is for indexing your documents into elastic and allowing that to be used during search, part of asset-enabling your entities.

But then separately you're talking about doing queries based upon joins across it sounds like multiple tables, I'm assuming you're talking about doing an SQL query of some kind.

And "search the part of the table data that belongs to a particular user"? I'm guessing you are trying to say you want to do a query against a table where a user id column matches a value?

Sorry, but you're seemingly like all over the place about what you want?
thumbnail
ali yeganeh, modified 4 Years ago.

RE: Custom search and indexing

Regular Member Posts: 148 Join Date: 5/1/19 Recent Posts
Hi David
Assume I have a table
I want to search in this table, but only in restricted list of data
For example:
My table have this data: [1,2,3,4,5,6,7,8,9,10]
And my restricted list of data  is [5,8,9,10]
I want to search only on restricted list [5,8,9,10]
thumbnail
Olaf Kock, modified 4 Years ago.

RE: Custom search and indexing

Liferay Legend Posts: 6403 Join Date: 9/23/08 Recent Posts
Crossreferencing a crosspost. Don't crosspost!
thumbnail
Olaf Kock, modified 4 Years ago.

RE: Custom search and indexing

Liferay Legend Posts: 6403 Join Date: 9/23/08 Recent Posts
If I understand you correctly: As the search index typically doesn't have the same permissions model as the application (Liferay) does: You'd typically search on everything, but - before you present the result - filter by permissions.
thumbnail
ali yeganeh, modified 4 Years ago.

RE: Custom search and indexing

Regular Member Posts: 148 Join Date: 5/1/19 Recent Posts
ali yeganeh:


Assume I have a table
I want to search in this table, but only in restricted list of data
For example:
My table have this data: [1,2,3,4,5,6,7,8,9,10]
And my restricted list of data  is [5,8,9,10]
I want to search only on restricted list [5,8,9,10]

Hi dear Olaf Kock
Can I explicitly specify between what records to search?
thumbnail
Olaf Kock, modified 4 Years ago.

RE: Custom search and indexing

Liferay Legend Posts: 6403 Join Date: 9/23/08 Recent Posts
ali yeganeh:

Can I explicitly specify between what records to search?
On Elasticsearch, using the ES API? On Liferay's User Interface, using additional search terms? Is there any specific criteria for specifying the records you're searching in?
thumbnail
ali yeganeh, modified 4 Years ago.

RE: Custom search and indexing

Regular Member Posts: 148 Join Date: 5/1/19 Recent Posts
Now , I only used one keyword as criteria

SearchContext searchContext = SearchContextFactory.getInstance( request );
searchContext.setKeywords( keywords );
Hits hits = indexer.search( searchContext );

In the above source code I want set list of ID's to searchContext as a filter parameter
Is there a method on searchContext for restricting result by an array of ID's ?
thumbnail
Olaf Kock, modified 4 Years ago.

RE: Custom search and indexing

Liferay Legend Posts: 6403 Join Date: 9/23/08 Recent Posts
ali yeganeh:

Now , I only used one keyword as criteria

SearchContext searchContext = SearchContextFactory.getInstance( request );
searchContext.setKeywords( keywords );
Hits hits = indexer.search( searchContext );

In the above source code I want set list of ID's to searchContext as a filter parameter
Is there a method on searchContext for restricting result by an array of ID's ?
If the ids in question are also indexed as keywords, that seems possible indeed. It feels like it can quickly turn into an abuse of the search server, but possible: My vote is "yes"
thumbnail
ali yeganeh, modified 4 Years ago.

RE: Custom search and indexing

Regular Member Posts: 148 Join Date: 5/1/19 Recent Posts
What do you me it can quickly turn into an abuse of the search server ?
how can it possible ?
How can apply this solution in your answer ?
thumbnail
Olaf Kock, modified 4 Years ago.

RE: Custom search and indexing

Liferay Legend Posts: 6403 Join Date: 9/23/08 Recent Posts
ali yeganeh:

What do you me it can quickly turn into an abuse of the search server ?
Your example contains 4 out of the 10 available ids to search in. If you search for 1 keyword in 40% of the available 1.000.000 documents, your keyword query will explode, e.g. you'll search for 400.001 keywords (if you make the ids keywords).
If you continue to search among 4 documents out of 1.000.000, you don't really need a search server, but can just validate individually.
And for anything in between: "it depends".
Maybe it's time to ask for the underlying business problem: How will this manifest on the user interface?
thumbnail
ali yeganeh, modified 4 Years ago.

RE: Custom search and indexing

Regular Member Posts: 148 Join Date: 5/1/19 Recent Posts
Can I use liferay apis for build a search query and obtain search hits that match the query.
According to my problem that I want to Search among specific data of a table
if your answer is yes, please send me a sample code ?
thumbnail
ali yeganeh, modified 4 Years ago.

RE: Custom search and indexing

Regular Member Posts: 148 Join Date: 5/1/19 Recent Posts
Hi Mr. Olaf Kock
I still didn't get my answer
Please guide on my latest question
thumbnail
Olaf Kock, modified 4 Years ago.

RE: Custom search and indexing

Liferay Legend Posts: 6403 Join Date: 9/23/08 Recent Posts
You've posted some code for searching one keyword - if that weird suggestion of adding the IDs that you want to search amongst to the query, you'd just have a couple of extra keywords.
As an alternative: Search in everything, then filter afterwards. It all depends on the raw numbers: For searching among 4 entries you'd choose a different strategy than for searching in 40000 entries.
thumbnail
ali yeganeh, modified 4 Years ago.

RE: Custom search and indexing

Regular Member Posts: 148 Join Date: 5/1/19 Recent Posts
According to your description, i have done your alternative solution , i have 40000  search result and an array with 7 entries.
Afterward i compare  these arrays to restrict my result, this is a good idea to solve  my problem?
my code is:


//array has 7 entities
long[] myEntities  = { 1, 2, 3, 4, 5, 6, 7 };

// ids returns 40000 entities
searchContext.setKeywords( keywords );
Indexer indexer = IndexerRegistryUtil.getIndexer( Importation.class );
Hits hits = indexer.search( searchContext );

List<long>&nbsp;&nbsp;ids &nbsp; = new ArrayList&lt;&gt;();
for ( int i = 0 ; i &lt; hits.getDocs().length ; i++ )
{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Document doc = hits.doc( i );
&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; long entryId = GetterUtil.getLong( doc.get( Field.ENTRY_CLASS_PK ) );
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ids .add( entryId );
}
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;
//i compare two above results for restrict search result
List<long> list = new ArrayList&lt;&gt;();
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;
for ( int i = 0 ; i &lt; myEntities&nbsp; .length ; i++ )
&nbsp;&nbsp; &nbsp;if (&nbsp; ids &nbsp; .contains( myEntities[i] ) )
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;list.add( myEntities&nbsp; [i] );
</long></long>


 would you mind suggesting any idea if my solution is not efficient?
I want to use Queries and Filters in Liferay’s Search API   
please give me a sample or a document for using in this problem.
thumbnail
Olaf Kock, modified 4 Years ago.

RE: Custom search and indexing

Liferay Legend Posts: 6403 Join Date: 9/23/08 Recent Posts
One of my suggestions was rather to add your myEntries ids to the keywords that you're searching in. In the case of 40000 results and 7 elements in myEntries, that would be a better option.
Sorry, no code sample
thumbnail
ali yeganeh, modified 4 Years ago.

RE: Custom search and indexing

Regular Member Posts: 148 Join Date: 5/1/19 Recent Posts
Olaf Kock:

One of my suggestions was rather to add your myEntries ids to the keywords that you're searching in. In the case of 40000 results and 7 elements in myEntries, that would be a better option.
Sorry, no code sample

How do I set an array of IDs for Search Context and then search on that array will happen through a keyword that the user enters?
thumbnail
ali yeganeh, modified 4 Years ago.

RE: Custom search and indexing

Regular Member Posts: 148 Join Date: 5/1/19 Recent Posts
You didn't comment on the code I sent you
Do I filter the search result myself, right?