# How can I tell biblatex to filter entries based on URL and URLDATE?

I would like to create two separate lists of references using biblatex. The first one should contain literature references, the second one online references. My criterion is that any entry with both a Url and a Urldate in the BibTeX file should be an online source. So I defined a “bibcheck” like so:

\documentclass{article}

\usepackage[style=verbose]{biblatex}

\defbibcheck{online}{%
\ifboolexpr{
not test {\iffieldundef{Url}} and not test {\iffieldundef{Urldate}}
}{% Entry has both url and urldate -> it's a web source
}{%
\skipentry
}
}

\defbibcheck{hasurl}{%
\iffieldundef{Url}{\skipentry}{}%
}

\usepackage{filecontents}

\begin{filecontents}{\jobname.bib}
@misc{A01,
author = {Author, A.},
year = {2001},
title = {Alpha},
url = {http://www.google.com/},
urldate = {2012-06-21}
}
@misc{B02,
author = {Buthor, B.},
year = {2002},
title = {Bravo},
url = {http://www.google.com/}
}
@misc{C03,
author = {Cuthor, C.},
year = {2001},
title = {Charlie},
urldate = {2012-06-21}
}
@misc{D04,
author = {Duthor, D.},
year = {2001},
title = {Delta}
}
\end{filecontents}

\addbibresource{\jobname.bib}

\nocite{*}

\begin{document}

\printbibliography[check=online]
\printbibliography[check=hasurl]

\end{document}


This does not work, however, because it seems that in the bibcheck “routine” neither Url nor Urldate are set – even though they are printed correctly in the list of references. I tried outputting the value of the Url field using \thefield{url} and it only returns an empty string.

How can I filter based on Url and Urldate?

-

## 2 Answers

The problem with your example is that "URLDATE" is not a field. If you check the manual, all the "*DATE" fields are split into their components by the backend and so if you change "urldate" to to "urlyear" then it works.

An alternative is to use the sourcemapping feature with biber:

\DeclareSourcemap{
\maps[datatype=bibtex]{
\map{
\step[fieldsource=url]
\step[fieldsource=urldate]
\step[fieldset=keywords, fieldvalue={online}]
}
}
}


This will give everything with both URL and URLDATE the keyword "online" which you can then use for bib filtering. Since URLDATE is part of the backend datamodel, you can use it there.

-
Thanks for the hint. This works infact for the urldate field. But I still do not know how to test against the url field. – ilpssun Jun 21 '12 at 11:35
I think you're getting confused by the fact that your example has the field names in mixed case. "Url" won't work but "url" will. The URL field can be tested against but URLDATE can't as it doesn't exist as a .bbl field. – PLK Jun 21 '12 at 11:52
@PLK: urldate is defined via DeclareFieldFormat in biblatex.def – Herbert Jun 21 '12 at 12:09
Yes, as a format but not as a field. If you look in the .bbl for this example, you'll see that there is no urldate. It's been split into urlyear, urlmonth and urlday. See the section 4.2.4.3 of the manual. – PLK Jun 21 '12 at 12:15
@PLK: thats correct, but the problem is that biblatex uses only the fields defined in the bbl and not the ones defined by itself. – Herbert Jun 21 '12 at 12:56

The test on the field urldate, because biblatex uses only the fields defined in the .bblfile. However, why don't you define such entries not as an online type? Then you can test for \ifentrytype (I used biber in my example):

\documentclass{article}

\usepackage[style=verbose,backend=biber]{biblatex}

\defbibcheck{online}{\ifentrytype{online}{}{\skipentry}}
\defbibcheck{hasurl}{\iffieldundef{url}{\skipentry}{}}
\defbibcheck{hasurldate}{\iffieldundef{urlyear}{\skipentry}{}}

\usepackage{filecontents}

\begin{filecontents*}{\jobname.bib}
@online{A01,
author = {Author, A.},
year = {2001},
title = {Alpha},
urldate = {2012-06-21},
url = {http://www.google.com/},
}
@misc{B02,
author = {Buthor, B.},
year = {2002},
title = {Bravo},
url = {http://www.google.com/}
}
@misc{C03,
author = {Cuthor, C.},
year = {2001},
title = {Charlie},
urldate = {2012-06-21},
}
@misc{D04,
author = {Duthor, D.},
year = {2001},
title = {Delta},
}
\end{filecontents*}

\addbibresource{\jobname.bib}
\nocite{*}
\begin{document}

\printbibliography[check=online]
\printbibliography[check=hasurl]
\printbibliography[check=hasurldate]
\printbibliography

\end{document}


-
I would like to format some online sources as, e.g., technical reports setting the type to @techreport while still including a URL and a URL date. Also, my bibtex-file is rather comprehensive and it would be tedious to manually check all entries whether they should be @online. – ilpssun Jun 21 '12 at 11:37
@ilpssun: ok, the "field" urldate is internally divided into the separate fields urlday, urlmonth, and urlyear. If you run the test with urlyear instead of urldate then it should work. The problem is that biblatex defines the field urldate but uses for the check only the fields which are definied by biber – Herbert Jun 21 '12 at 12:51