How to get all the Ids of an object afte a user's search

Hello we are new to algolia and we are currently testing InstantSearch.js?
Can we somehow get the IDs of every item that someone searched? For example if I search notebook it will return 1000 records and it will show me the top 10 or whatever I choose to show. Can I somehow get only the IDs of all 1000 records. I don’t want to show all the records I just want the IDs of all the records so that I can redirect the customer to my search page with all those 1000 records
In my search page I would have more option like specs, more and larger photos etc, so I want to show to the customer the top 10 results of algolia and then if he wants I want to redirect him to my search page with the 1000 records that algoria gave me with the ID.

Is there some kind of foreach item and item.objectID that I can get all the ids of the items in every search the user does?

Hi @cosmodataepe

Why would you pass (up to) 1000 objectIDs to a search page? Then you would have to retrieve data for (up to) 1000 items to return on the search page. Why not simply send the user’s search query to the search page?

1 Like

Hello,
I also have difficulty in retrieving the user’s selection. I was able to find the variable “query” but it returns only the text that the user wrote in the textbox. How can i retrieve which categories or brands he checked from the Refinements?
Thank you

Could it be that you’re looking for routing (documentation here: Routing URLs | Building Search UI | Guide | Algolia Documentation)

Do you have a live example somewhere that can be looked at?

Let me explain what is my goal here. I want to replace my search bar with algolia. I want to show 5-6 results to the user when he searches something, and i want to put in the end a button “See all the products”. If he checkes the button, I will do a search to my website’s search(not algolia) and return him all the products from his search.

So I have the following code. I would like somehow to get the query and the search results that the user chooses, so that i can create a form and the button “See all the products”.

In this example I inserted an alert(query) which alerts what he put on the textbox. How can I get the choises of the Refinements.

Of course my purpose is not to alert all of those(i use it as an example), but eventually in every user’s search, I want to inform the secondary form.

I read the routing but I don’t know if it does what I want. It looks like it changes the url. Ok I see that somehow it takes the parametres but I don’t understand yet how.


const renderSearchBox = (renderOptions, isFirstRender) => {
  const { query, refine, clear, isSearchStalled, widgetParams } = renderOptions;

  if (isFirstRender) {
    const input = document.createElement('input');

    const loadingIndicator = document.createElement('span');
    loadingIndicator.textContent = 'Loading...';

    const button = document.createElement('button');
    button.textContent = 'X';

    input.addEventListener('input', event => {
		
      refine(event.target.value);
    });

    button.addEventListener('click', () => {
      clear();
	  //$('#show_results').hide();
    });

    widgetParams.container.appendChild(input);
    widgetParams.container.appendChild(loadingIndicator);
    widgetParams.container.appendChild(button);
	
  }

  widgetParams.container.querySelector('input').value = query;
alert(query);
  widgetParams.container.querySelector('span').hidden = !isSearchStalled;
};

// create custom widget
const customSearchBox = instantsearch.connectors.connectSearchBox(
  renderSearchBox
);

// instantiate custom widget
search.addWidgets([
  customSearchBox({
    container: document.querySelector('#searchbox'),
  })
]);

search.addWidgets([
  /*instantsearch.widgets.searchBox({
    container: '#searchbox',
  }),*/
  instantsearch.widgets.clearRefinements({
    container: '#clear-refinements',
  }),
  instantsearch.widgets.refinementList({
    container: '#brand-list',
    attribute: 'brand',
  }),
  instantsearch.widgets.refinementList({
    container: '#cat-list',
    attribute: 'cat_title',
  }),
  instantsearch.widgets.refinementList({
    container: '#isprosfora-list',
    attribute: 'is_prosfora',
  }),
  instantsearch.widgets.refinementList({
    container: '#prosfora-list',
    attribute: 'prosfora',
  }),
  instantsearch.widgets.hits({
    container: '#hits',
    templates: {
      item: `
	    <a href="https://www.****.gr/product/{{objectID}}/">
        <div>
          <img src="{{imagepath}}" align="left" alt="{{title}}" />
          <div class="hit-name">
            {{#helpers.highlight}}{ "attribute": "title" }{{/helpers.highlight}}
          </div>
          <div class="hit-description">
            {{#helpers.highlight}}{ "attribute": "description" }{{/helpers.highlight}}
          </div>
          <div class="hit-price">\${{finalpriceweb}}</div>
        </div>
		</a>
      `,
    },
  }),
  instantsearch.widgets.pagination({
    container: '#pagination',
  }),
]);

search.start();