Reply
Contributor
Posts: 31
Registered: ‎08-01-2014
Accepted Solution

Custom Form for Search in hue

[ Edited ]

Hi,

I'm creating a new app in Hue to have a custom form input for solr searches

 

This is an example

Nuova immagine bitmap.jpg

 

I would to redirect a user that submit the form to search page present into hue and to put the "parsed" query into search box as:

 

search.jpg

 

Is it possible ?

 

Thanks

Alessio

Cloudera Employee
Posts: 11
Registered: ‎11-21-2013

Re: Custom Form for Search in hue

It's currently not possible, 

but it sounds like a good feature request, something like this I believe?

 

http://HUE_IP/search/?collection=50009&q=YOUR_SEARCH_QUERY

 

I created https://issues.cloudera.org/browse/HUE-3003 for this

 

Thanks!

e.

Contributor
Posts: 31
Registered: ‎08-01-2014

Re: Custom Form for Search in hue

Hi,

 

I modify the index function into 

/lib/hue/apps/search/src/search/views.py (cloudera parcels of CDH5.4)

 

Old Version:

def index(request):
  hue_collections = SearchController(request.user).get_search_collections()
  collection_id = request.GET.get('collection')

  if not hue_collections or not collection_id:
    return admin_collections(request, True)

  try:
    collection = hue_collections.get(id=collection_id)
  except Exception, e:
    raise PopupException(e, title=_("Dashboard does not exist or you don't have the permission to access it."))

  query = {'qs': [{'q': ''}], 'fqs': [], 'start': 0}
  return render('search.mako', request, {
    'collection': collection,
    'query': query,
    'initial': json.dumps({'collections': [], 'layout': []}),
    'is_owner': request.user == collection.owner
  })

New Version

def index(request):
  hue_collections = SearchController(request.user).get_search_collections()
  collection_id = request.GET.get('collection')

  if not hue_collections or not collection_id:
    return admin_collections(request, True)

  try:
    collection = hue_collections.get(id=collection_id)
  except Exception, e:
    raise PopupException(e, title=_("Dashboard does not exist or you don't have the permission to access it."))

  if request.method == 'GET' and 'q' in request.GET:
    q=str(request.GET.get('q'))
    query = {'qs': [{'q': q}], 'fqs': [], 'start': 0}
  else:
    query = {'qs': [{'q': ''}], 'fqs': [], 'start': 0}

  return render('search.mako', request, {
    'collection': collection,
    'query': query,
    'initial': json.dumps({'collections': [], 'layout': []}),
    'is_owner': request.user == collection.owner
  })

And so when I connect to 

      http://hue-server:8888/search/?collection=1&q=test 

 

The output is:

output.jpg

 

 

It seems to work

 

Thanks

Alessio

 

 

 

 

Cloudera Employee
Posts: 11
Registered: ‎11-21-2013

Re: Custom Form for Search in hue

Hi Alessio,

that would work with normal queries but not with UTF/weirdly encoded ones. Try to search for 比萨 for instance)

 

I'm working on it as we speak, so just wait a few hours and it should be out on github :)

Cloudera Employee
Posts: 11
Registered: ‎11-21-2013

Re: Custom Form for Search in hue

Highlighted
Contributor
Posts: 31
Registered: ‎08-01-2014

Re: Custom Form for Search in hue

Thanks :-)

 

Alessio