Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

Custom Form for Search in hue

Solved Go to solution

Custom Form for Search in hue

Contributor

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

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Custom Form for Search in hue

Cloudera Employee
5 REPLIES 5

Re: Custom Form for Search in hue

Cloudera Employee

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.

Re: Custom Form for Search in hue

Contributor

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

 

 

 

 

Re: Custom Form for Search in hue

Cloudera Employee

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 :)

Re: Custom Form for Search in hue

Cloudera Employee

Re: Custom Form for Search in hue

Contributor

Thanks :-)

 

Alessio