I am trying to use facet in solr, i want to make a search on my database and i need to get articles that belong to specific date and specific publisher.
i used this url on the browser:
localhost:8888/solr//collection1/select/?q=:&version=2.2&start=0&rows=10&indent=on&facet=true&fq=publisher_name:"Saudi Press Agency (SPA)"&fq=datecreated:20110725
and it works fine. I am using (search()) function in apache_solr_service class in my php code. and i set the array as below:
array('facet'=>'true','fq'=>"datecreated:".$date,'fq'=>"publisher_name:\"".$publisher.'"')
I know it wont give me the expected results because of fq index, it will overwrite the value of fq into publisher_name
but how can i set this query with two facet queries
This might help:
http://code.google.com/p/solr-php-client/wiki/FAQ#How_Can_I_Use_Additional_Parameters_%28like_fq,_facet,_etc%29
This is what the code should look like (please check for syntax errors, my PHP is rusty):
array('facet'=>'true','fq'=>array('datecreated:'.$date,'publisher_name:"'.$publisher.'"')
You could also write it like this:
array('fq'=>'+datecreated:'.$date.' +publisher_name:"'.$publisher.'"')
http://wiki.apache.org/solr/CommonQueryParameters#fq
use AND operator:
array('fq'=> 'datecreated:'.$date.' AND publisher_name:"'.$publisher.'"');
Related
I'm currently using and experimenting with xCrud. I'm now wondering, since there is no documentation about those features, if it would be easily possible to have multiple search bars where you can search for different things.
Right now my xCrud file looks like that
<?php
$xcrud->table('table1');
$xcrud->join('ID','table2','ID');
echo $xcrud->render();
?>
Maybe you can use this feature for search different things:
$xcrud->search_columns('productVendor,quantityInStock,buyPrice','quantityInStock');
By default, the xcrud search bar allows you to search all columns in your rendered table. It also allows you to select specific fields to search. The $xcrud->search_columns() function mentioned by #eneskomur is useful when you are displaying data using $xcrud->subselect().
I've been given a query to use in some PHP code but the problem is, the person that gave me the query is using MS Access and I'm using MySQL so everything isn't quite translating. In his query there is this
... Mid([GTIN],2,10) AS items_bar ...
MySQL doesn't like this part and I'm not sure what it is supposed to be doing. Is there an easy translation for this to MySQL?
It is selecting a sub-string of the GTIN element.
Instead of using this:
Mid([GTIN],2,10) AS items_bar
Use this:
substring(GTIN,2,10) as items_bar
I want to implement a advanced search functionality in my program but i don't want to create an interface like this (it's just example):
What i want is just a text box where user can write queries like this (assume it's a 'contacts' applicaton):
contact_name:john,michael,-michelle age:<=20,=>15 location:usa
What i thought so far:
First, explode the text by spaces, and then by colon. So, first item will be "search fields" and the second array will be values to look for. But problems come with operators like <=, - and *. They are not fixed width, so i can't know how much character should i do "substr" for operator.
By the way: If this search operation has a general name like "token based search" or something like that, i can search for a library which already does job.
I guess you can use some regex with callbacks.
Something like :
"`[a-z]+:([*<=>])([a-z],)+ `U"
It's just an example, you have to complete if to fit your needs.
Good luck with that.
You will have to build something like your advanced search (maybe) using auto-suggest for building user query: this way you will have more control over query structure.
If you attempt to parse freehand queries you leave yourself open to query misinterpretation:
Will you consider below query valid
contact_name:john,michael,-michelle age:<=20,=>15 location:usa
and the following representation of the same invalid?
contact_name:john, michael,-michelle age:<=20,=>15 location:usa
(insert any number of spaces just about anywhere)
Try to search for "query builders" or something similar, but considering that the implementation is very application specific I am not sure if you will find anything useful.
I have a website which allows users to submit photos of wildlife. Once uploaded, they can identify the specie on the photo, for example "Polar bear".
This triggers me to get information from Wikipedia about that specie, using that search term:
$query = "http://en.wikipedia.org/w/api.php?action=query&rvprop=content&format=json&titles=" . $query;
$pages = file_get_contents($query);
Such a query returns one of the following:
An array of pageids, which I can then query for that page's content
Nothing, because there simply isn't any match
a REDIRECT result, which allows me to resolve the page with the proper name
The problem I have has to do with casing. For example, the search term "Milky stork", returns nothing, not even a redirect. "Milky Stork" does work. Uppercasing each word in the query is not a solution either, as it could be that some pages are in lowercase, whereas the uppercase query does not work. There's no consistency.
I'm looking for a way to make this more robust. It shouldn't be that a query fails because of wrong casing, which cannot even be predicted on the user's side.
Does anyone know of a solution for this? Other than trying every possible combination of casings?
Note: Some may suggest to use dbpedia instead, but this is no solution for my total needs.
Unfortunatelly, there is no easy solution - read http://www.mediawiki.org/wiki/API:Opensearch#Note_on_case_sensitivity
You can try instead use opensearch to find appropriate casing (if normal query returns nothing usable):
http://en.wikipedia.org/w/api.php?action=opensearch&search=milky+stork&namespace=0&suggest=
will give you
["milky stork",["Milky Stork"]]
I think trying every possible combination is a viable solution. So, your query might look like:
http://en.wikipedia.org/w/api.php?action=query&rvprop=content&format=json&titles=Milky stork|Milky Stork
Note that the first letter is not case-sensitive on Wikipedia.
You know when you start searching in an autocomplete search box, you get a list of possible results. From those results, say you click one of the items on the list, I want to take that item and perform another search to give another list of results. Just exaclty like how google works. if you dont understand me try typing into google search box something like 'ja'. It will give a list of possible results,when you select one of them, it does another search and gives another set of results.
Pls does anyone know how to do this with scriptalous autocomplete? or anyother way Any example on the net, will really really appreciate it.
I ma using codeigniter frame work (php) by the way
You can definitely do it. Personally I would do it in jQuery using the Autocomplete from jQuery UI.
http://jqueryui.com/demos/autocomplete/
You could get it to load the results like it usually does but format them differently or extend the jquery ui. Would be fairly simple.
Since its possible in jQuery its definitely possible to do with the scriptaculous autocompleter but I am not familiar with it.
You would look at the place where the output is displayed:
<div id="autocomplete_choices" class="autocomplete"></div>
If you can style this the way you want it instead of it being like a dropdown then you will have your instant.