Dr.BYTE at web.de
2008-Aug-14 13:25 UTC
[Xapian-discuss] searching through different "fields"?
hey all, i want build up a user search with xapian and php5. but i don't know how searching thru different fields. result should show all records got "cars or party or friends" in the field "interessts" AND "pizza or spaghetti" in field "food". any suggestions? thank you, sven ____________________________________________________________________ Ihre Messenger, Communities und E-Mails jetzt in einem Programm! WEB.DE MultiMessenger http://www.produkte.web.de/messenger/?did=3071
On Thu, Aug 14, 2008 at 03:25:38PM +0200, Dr.BYTE at web.de wrote:> i want build up a user search with xapian and php5. but i don't know > how searching thru different fields. result should show all records > got "cars or party or friends" in the field "interessts" AND "pizza > or spaghetti" in field "food".You want to map each 'field' to a term prefix, and then give those prefixes meaningful names for your users. So you'll end up with something like "interests:(cars OR party OR friends) AND food:(pizza OR spaghetti)" for the above. If you're using omega, look at the documentation of the $setmap{} OmegaScript command (talking about the 'prefix' map), and the scriptindex documentation, which is the easiest way of generating prefixes for omega. If you aren't, look at the QueryParser documentation for an explanation of how prefix mapping works. J -- /--------------------------------------------------------------------------\ James Aylett xapian.org james at tartarus.org uncertaintydivision.org
<Dr.BYTE <at> web.de> writes:> > hey all, > > i want build up a user search with xapian and php5. but i don't know howsearching thru different fields.> result should show all records got "cars or party or friends" in the field"interessts" AND "pizza or> spaghetti" in field "food". > > any suggestions? > > thank you, > sven > ____________________________________________________________________ > Ihre Messenger, Communities und E-Mails jetzt in einem Programm! > WEB.DE MultiMessenger http://www.produkte.web.de/messenger/?did=3071 >Hi, I am relatively new with Xapian and also needed this functionality. Here is what I found out. There are two things you have to do: - When adding a posting, choose the right prefix - When searching, use these prefixes and maybe add the prefixes to your parser. By default, a prefix Z is used Other prefixes: S for title A for author X for custom prefixes if you want a category prefix, use XCATEGORY as prefix if you want a price prefix, use XPRICE // adding the posting on indexing $xapian_document->add_posting (XCATEGORYbooks, $position, $weight); // searching for it $parser->add_prefix ('category', 'XCATEGORY'); $query = $parser->parse_query ('category:books');
Dr.BYTE at web.de
2008-Aug-14 13:54 UTC
[Xapian-discuss] searching through different "fields"?
i don't use omega. i tried out to add terms: $doc->add_term('X1spaghetti pizza'); $doc->add_term('X2cars party friends'); and searching them by $query_parser->add_prefix('user_food', 'X1'); $query_parser->add_prefix('user_interessts', 'X2'); $query_parser->parse_query('user_interessts:(party OR friends)'); but i get no results. query description writes: Parsed query is: Xapian::Query((ZX1spaghetti:(pos=1) OR ZX1pizza:(pos=2))) am i on the right way? what do i wrong? ____________________________________________________________________ Ihre Messenger, Communities und E-Mails jetzt in einem Programm! WEB.DE MultiMessenger http://www.produkte.web.de/messenger/?did=3071
Please keep replies on-list so that others can help you, and benefit from the replies. On Thu, Aug 14, 2008 at 03:42:38PM +0200, Sven Kummer wrote:> i tried out to add terms: > $doc->add_term('X1spaghetti pizza'); > $doc->add_term('X2cars party friends');You're adding two terms there where you actually want to add five. Ignoring stemming, you want: X1spaghetti X1pizza X2cars X2party X2friends Possibly the easiest way of generating terms is to use the TermGenerator. The introductory docs are a little difficult to read as they are mostly documenting the changes from previous versions, but the API docs should help.> $query_parser->add_prefix('user_food', 'X1'); > $query_parser->add_prefix('user_interessts', 'X2'); > > $query_parser->parse_query('user_interessts:(party OR friends)'); > > but i get no results. query description writes: > > Parsed query is: Xapian::Query((ZX1spaghetti:(pos=1) OR ZX1pizza:(pos=2)))Well, it won't be that, it'll be (ZX2party:(pos=1) OR ZX2friends:(pos=2)) or something very similar. If you construct terms as above, you'll be fine. J -- /--------------------------------------------------------------------------\ James Aylett xapian.org james at tartarus.org uncertaintydivision.org
Dr.BYTE at web.de
2008-Aug-14 15:59 UTC
[Xapian-discuss] searching through different "fields"?
Sorry for reply out of the list. I believe to know what you mean. I tried to index content prefixed using the Termgenerator $gen = new XapianTermGenerator(); //...other options $gen->index_text('pizza spaghetti', 1, 'X1'); After this, it should be indexed as you suggest: X1pizza X1spaghetti Searching related users by query: $query_parser->add_prefix('user_food', 'X1'); $query = new XapianQuery($query_parser->parse_query('user_food:(spaghetti OR pizza)')); results in: Parsed query is: Xapian::Query((X1spaghetti:(pos=1) OR X1pizza:(pos=2))) This seems nice for me, but displays no results :(> Please keep replies on-list so that others can help you, and benefit > from the replies. > > On Thu, Aug 14, 2008 at 03:42:38PM +0200, Sven Kummer wrote: > > > i tried out to add terms: > > $doc->add_term('X1spaghetti pizza'); > > $doc->add_term('X2cars party friends'); > > You're adding two terms there where you actually want to add > five. Ignoring stemming, you want: > > X1spaghetti > X1pizza > X2cars > X2party > X2friends > > Possibly the easiest way of generating terms is to use the > TermGenerator. The introductory docs are a little difficult to read as > they are mostly documenting the changes from previous versions, but > the API docs should help. > > > $query_parser->add_prefix('user_food', 'X1'); > > $query_parser->add_prefix('user_interessts', 'X2'); > > > > $query_parser->parse_query('user_interessts:(party OR friends)'); > > > > but i get no results. query description writes: > > > > Parsed query is: Xapian::Query((ZX1spaghetti:(pos=1) OR > ZX1pizza:(pos=2))) > > Well, it won't be that, it'll be (ZX2party:(pos=1) OR > ZX2friends:(pos=2)) or something very similar. If you construct terms > as above, you'll be fine. > > J > > -- > /------------------------------------------------------------------------- > -\ > James Aylett xapian.org > james at tartarus.org uncertaintydivision.org > > _______________________________________________ > Xapian-discuss mailing list > Xapian-discuss at lists.xapian.org > http://lists.xapian.org/mailman/listinfo/xapian-discuss_______________________________________________________________________ EINE F?R ALLE: die kostenlose WEB.DE-Plattform f?r Freunde und Deine Homepage mit eigenem Namen. Jetzt starten! http://unddu.de/?kid=kid at mf2